QuantumCore

Hands-on lab · 1 step

Build strongly entangling layers

Implement PennyLane-convention strongly entangling layers as a list of Circuit-IR operations: on every wire the general rotation Rot(ϕ,θ,ω)=RZ(ω)RY(θ)RZ(ϕ)\mathrm{Rot}(\phi,\theta,\omega)=R_Z(\omega)R_Y(\theta)R_Z(\phi), then the cyclic CNOT block CNOT(i,(i+rℓ) mod n)\mathrm{CNOT}(i,(i+r_\ell)\bmod n) with the layer-dependent range rℓ=(ℓ mod (n−1))+1r_\ell=(\ell\bmod(n-1))+1. The grader compares the unitary of your circuit with the reference unitary on 77 weight tensors of shapes (1,2,3)(1,2,3), (1,3,3)(1,3,3), (2,3,3)(2,3,3) and (3,4,3)(3,4,3), requiring process fidelity at least 1−10−91-10^{-9}.

0/1 step passedBest score 0/100

Step 1: Implement stronglyEntanglingLayers

Complete the TypeScript function

stronglyEntanglingLayers(weights: number[][][], n: number): Operation[]

that returns the operations of LL strongly entangling layers on nn qubits, in time order.

Shapes. weights has shape (L,n,3)(L,n,3): weights[l][i] = [phi, theta, omega] holds the three angles of wire ii in layer ℓ\ell. The circuit has 3nL3nL rotations and, for n>1n>1, nLnL CNOTs. Qubit 00 is the most significant bit and RP(α)=e−iαP/2R_P(\alpha)=e^{-i\alpha P/2}.

Layer ℓ\ell (ℓ=0,…,L−1\ell=0,\dots,L-1):

  1. on every wire i=0,…,n−1i=0,\dots,n-1 the rotation Rot(ϕ,θ,ω)=RZ(ω) RY(θ) RZ(ϕ),\mathrm{Rot}(\phi,\theta,\omega)=R_Z(\omega)\,R_Y(\theta)\,R_Z(\phi), written as the three operations { kind: 'gate', gate: 'RZ', targets: [i], params: [phi] }, then 'RY' with [theta], then 'RZ' with [omega];
  2. if n>1n>1, with the range rℓ=(ℓ mod (n−1))+1∈{1,…,n−1},r_\ell=(\ell\bmod(n-1))+1\in\{1,\dots,n-1\}, the CNOTs CNOT(i,(i+rℓ) mod n)\mathrm{CNOT}\big(i,(i+r_\ell)\bmod n\big) for i=0,1,…,n−1i=0,1,\dots,n-1 in this order, each written { kind: 'gate', gate: 'CNOT', targets: [control, target] }. For n=1n=1 there are no CNOTs.

Grading. For every test the grader builds the circuit { numQubits: n, ops } from your list, computes its 2n×2n2^n\times2^n unitary UU and compares it with the reference unitary TT through the process fidelity ∣Tr(T†U)∣/2n≥1−10−9\lvert\mathrm{Tr}(T^\dagger U)\rvert/2^n\ge1-10^{-9}, so a different but equivalent gate sequence also passes. The weights of the hidden tests are wℓ,i,k=2π uw_{\ell,i,k}=2\pi\,u with uu drawn from mulberry32(seed) in the order ℓ\ell, ii, kk. The tests are grouped into three checks:

  • rot-symmetric (hidden): one layer with ϕ=ω\phi=\omega on every wire, n=2n=2 (seed 1111) and n=3n=3 (seed 1212);
  • single-layer: the visible test zero-weights-L1-n2 and hidden random tests of shapes (1,2,3)(1,2,3) (seed 11) and (1,3,3)(1,3,3) (seed 44);
  • multi-layer (hidden): shapes (2,3,3)(2,3,3) (seed 22) and (3,4,3)(3,4,3) (seed 33).

Visible test. weights = [[[0, 0, 0], [0, 0, 0]]] and n = 2: all rotations are the identity and r0=1r_0=1, so the circuit is CNOT(0,1)\mathrm{CNOT}(0,1) followed by CNOT(1,0)\mathrm{CNOT}(1,0). On basis labels (x0,x1)↦(x0,x0⊕x1)↦(x1,x0⊕x1)(x_0,x_1)\mapsto(x_0,x_0\oplus x_1)\mapsto(x_1,x_0\oplus x_1), hence T=CNOT1→0 CNOT0→1=(1000001000010100),T=\mathrm{CNOT}_{1\to0}\,\mathrm{CNOT}_{0\to1}=\begin{pmatrix}1&0&0&0\\0&0&1&0\\0&0&0&1\\0&1&0&0\end{pmatrix}, with ∣00⟩↦∣00⟩\lvert00\rangle\mapsto\lvert00\rangle, ∣01⟩↦∣11⟩\lvert01\rangle\mapsto\lvert11\rangle, ∣10⟩↦∣01⟩\lvert10\rangle\mapsto\lvert01\rangle, ∣11⟩↦∣10⟩\lvert11\rangle\mapsto\lvert10\rangle.

TypeScript: export stronglyEntanglingLayers, stronglyEntanglingLayers, stronglyEntanglingLayers · 7 tests · imports: quantumcore, quantumcore/qml
Run the tests first; the results of your latest run are submitted.