QuantumCore

Lesson 45 · 95 min · advanced

Strongly Entangling Layers

Loading progress…

Strongly entangling layers (SEL) are the default trainable block of many quantum machine-learning libraries. Each layer applies a general single-qubit rotation Rot(ϕ,θ,ω)=RZ(ω)RY(θ)RZ(ϕ)\mathrm{Rot}(\phi,\theta,\omega)=R_Z(\omega)R_Y(\theta)R_Z(\phi) to every wire and then a cyclic block of CNOTs CNOT(i,(i+rℓ) mod n)\mathrm{CNOT}(i,(i+r_\ell)\bmod n) whose range rℓr_\ell changes from layer to layer. This lesson proves that Rot\mathrm{Rot} reaches all of SU(2)SU(2) (ZYZ decomposition), fixes the PennyLane conventions (weights of shape (L,n,3)(L,n,3), default range rℓ=(ℓ mod (n−1))+1r_\ell=(\ell\bmod(n-1))+1), shows that every entangling block is an invertible linear map over F2\mathbb F_2 on basis labels, counts 3nL3nL parameters and nLnL CNOTs, analyses the growth of light cones and direct couplings, and relates the template to the circuit-centric classifiers of Schuld, Bocharov, Svore and Wiebe.

Prerequisites: Hardware-Efficient Ansatz

Objectives and key results
  • Prove that every U∈U(2)U\in U(2) equals eiαRZ(β)RY(γ)RZ(δ)e^{i\alpha}R_Z(\beta)R_Y(\gamma)R_Z(\delta), write the explicit matrix of Rot(ϕ,θ,ω)\mathrm{Rot}(\phi,\theta,\omega) and translate the matrix order into the time order RZ(ϕ)R_Z(\phi), RY(θ)R_Y(\theta), RZ(ω)R_Z(\omega).

  • Implement PennyLane-convention strongly entangling layers with weights of shape (L,n,3)(L,n,3) and the default range rℓ=(ℓ mod (n−1))+1r_\ell=(\ell\bmod(n-1))+1, and explain why only r∈{1,…,n−1}r\in\{1,\dots,n-1\} is admissible.

  • Represent a product of CNOTs as an invertible matrix over F2\mathbb F_2, compute it for n=3n=3 with r=1r=1 and r=2r=2, and invert it.

  • Count parameters (3nL3nL) and CNOTs (nLnL), and bound the growth of light cones and of the set of directly coupled pairs with the number of layers.

  • Describe the circuit-centric classifier (amplitude encoding, layered model circuit, single-qubit readout, bias and threshold) and its parameter count O(Llog⁡N)O(L\log N).

theorem · ZYZ decomposition
∀ U∈U(2) ∃ α,β,γ,δ∈R:U=eiαRZ(β)RY(γ)RZ(δ),SU(2)={Rot(ϕ,θ,ω)}\forall\,U\in U(2)\ \exists\,\alpha,\beta,\gamma,\delta\in\mathbb R:\quad U=e^{i\alpha}R_Z(\beta)R_Y(\gamma)R_Z(\delta),\qquad SU(2)=\{\mathrm{Rot}(\phi,\theta,\omega)\}
definition · General rotation
Rot(ϕ,θ,ω)=RZ(ω)RY(θ)RZ(ϕ)=(e−i(ϕ+ω)/2cos⁡θ2−ei(ϕ−ω)/2sin⁡θ2e−i(ϕ−ω)/2sin⁡θ2ei(ϕ+ω)/2cos⁡θ2)\mathrm{Rot}(\phi,\theta,\omega)=R_Z(\omega)R_Y(\theta)R_Z(\phi)=\begin{pmatrix}e^{-i(\phi+\omega)/2}\cos\frac\theta2&-e^{i(\phi-\omega)/2}\sin\frac\theta2\\e^{-i(\phi-\omega)/2}\sin\frac\theta2&e^{i(\phi+\omega)/2}\cos\frac\theta2\end{pmatrix}
definition · Strongly entangling layer
Wℓ=∏i=n−10CNOT(i,(i+rℓ) mod n)⋅⨂i=0n−1Rot(wℓ,i,0,wℓ,i,1,wℓ,i,2),rℓ=(ℓ mod (n−1))+1W_\ell=\prod_{i=n-1}^{0}\mathrm{CNOT}\big(i,(i+r_\ell)\bmod n\big)\cdot\bigotimes_{i=0}^{n-1}\mathrm{Rot}(w_{\ell,i,0},w_{\ell,i,1},w_{\ell,i,2}),\qquad r_\ell=(\ell\bmod(n-1))+1
identity · The n = 3, r = 1 block over F₂
(x0,x1,x2)↦(x1⊕x2, x0⊕x1, x0⊕x1⊕x2),A=(011110111),A−1=(101111011)(x_0,x_1,x_2)\mapsto(x_1\oplus x_2,\ x_0\oplus x_1,\ x_0\oplus x_1\oplus x_2),\qquad A=\begin{pmatrix}0&1&1\\1&1&0\\1&1&1\end{pmatrix},\qquad A^{-1}=\begin{pmatrix}1&0&1\\1&1&1\\0&1&1\end{pmatrix}
formula · Resource counts
#w=3nL,#CNOT=nL (n>1),every pair of wires shares a CNOT after ⌊n2⌋ layers\#w=3nL,\qquad\#\mathrm{CNOT}=nL\ (n>1),\qquad\text{every pair of wires shares a CNOT after }\big\lfloor\tfrac n2\big\rfloor\text{ layers}

The general single-qubit rotation#

The hardware-efficient ansatz of the previous lesson used two rotations per qubit and layer and a CNOT ladder between neighbours. This leaves two gaps: RZ(b)RY(a)R_Z(b)R_Y(a) is a two-parameter family, while U(2)U(2) modulo global phase is three-dimensional; and the ladder couples only neighbouring qubits. Strongly entangling layers close both: each wire receives a general rotation with three angles, and the CNOTs close a cycle whose stride, the range, changes from layer to layer. The template goes back to the circuit-centric classifiers of Schuld, Bocharov, Svore and Wiebe and is implemented in PennyLane as StronglyEntanglingLayers. We begin with the rotation.

Definition

General rotation Rot

For real angles ϕ,θ,ω\phi,\theta,\omega the general rotation is Rot(ϕ,θ,ω)=RZ(ω) RY(θ) RZ(ϕ),RZ(α)=(e−iα/200eiα/2),RY(α)=(cos⁡α2−sin⁡α2sin⁡α2cos⁡α2).\mathrm{Rot}(\phi,\theta,\omega)=R_Z(\omega)\,R_Y(\theta)\,R_Z(\phi),\qquad R_Z(\alpha)=\begin{pmatrix}e^{-i\alpha/2}&0\\0&e^{i\alpha/2}\end{pmatrix},\quad R_Y(\alpha)=\begin{pmatrix}\cos\frac\alpha2&-\sin\frac\alpha2\\\sin\frac\alpha2&\cos\frac\alpha2\end{pmatrix}. In a matrix product the rightmost factor acts first, so in a circuit Rot(ϕ,θ,ω)\mathrm{Rot}(\phi,\theta,\omega) is the sequence RZ(ϕ)R_Z(\phi), then RY(θ)R_Y(\theta), then RZ(ω)R_Z(\omega). Since det⁡RZ=det⁡RY=1\det R_Z=\det R_Y=1, Rot(ϕ,θ,ω)∈SU(2)\mathrm{Rot}(\phi,\theta,\omega)\in SU(2).

Derivation

Explicit matrix of Rot

  1. Step 1:
    RY(θ)RZ(ϕ)=(c−ssc)(e−iϕ/200eiϕ/2)=(c e−iϕ/2−s eiϕ/2s e−iϕ/2c eiϕ/2),c=cos⁡θ2, s=sin⁡θ2R_Y(\theta)R_Z(\phi)=\begin{pmatrix}c&-s\\s&c\end{pmatrix}\begin{pmatrix}e^{-i\phi/2}&0\\0&e^{i\phi/2}\end{pmatrix}=\begin{pmatrix}c\,e^{-i\phi/2}&-s\,e^{i\phi/2}\\s\,e^{-i\phi/2}&c\,e^{i\phi/2}\end{pmatrix},\qquad c=\cos\tfrac\theta2,\ s=\sin\tfrac\theta2
    Right multiplication by a diagonal matrix scales the columns: column 00 by e−iϕ/2e^{-i\phi/2}, column 11 by eiϕ/2e^{i\phi/2}.
  2. Step 2:
    RZ(ω)(RY(θ)RZ(ϕ))=(e−iω/2c e−iϕ/2−e−iω/2s eiϕ/2eiω/2s e−iϕ/2eiω/2c eiϕ/2)R_Z(\omega)\big(R_Y(\theta)R_Z(\phi)\big)=\begin{pmatrix}e^{-i\omega/2}c\,e^{-i\phi/2}&-e^{-i\omega/2}s\,e^{i\phi/2}\\e^{i\omega/2}s\,e^{-i\phi/2}&e^{i\omega/2}c\,e^{i\phi/2}\end{pmatrix}
    Left multiplication by a diagonal matrix scales the rows: row 00 by e−iω/2e^{-i\omega/2}, row 11 by eiω/2e^{i\omega/2}.
  3. Step 3:
    Rot(ϕ,θ,ω)=(e−i(ϕ+ω)/2cos⁡θ2−ei(ϕ−ω)/2sin⁡θ2e−i(ϕ−ω)/2sin⁡θ2ei(ϕ+ω)/2cos⁡θ2)\mathrm{Rot}(\phi,\theta,\omega)=\begin{pmatrix}e^{-i(\phi+\omega)/2}\cos\frac\theta2&-e^{i(\phi-\omega)/2}\sin\frac\theta2\\e^{-i(\phi-\omega)/2}\sin\frac\theta2&e^{i(\phi+\omega)/2}\cos\frac\theta2\end{pmatrix}
    Collect the exponents: −ω2−ϕ2=−ϕ+ω2-\frac\omega2-\frac\phi2=-\frac{\phi+\omega}2, −ω2+ϕ2=ϕ−ω2-\frac\omega2+\frac\phi2=\frac{\phi-\omega}2, ω2−ϕ2=−ϕ−ω2\frac\omega2-\frac\phi2=-\frac{\phi-\omega}2, ω2+ϕ2=ϕ+ω2\frac\omega2+\frac\phi2=\frac{\phi+\omega}2.
  4. Step 4:
    Rot(ω,θ,ϕ)01=−ei(ω−ϕ)/2sin⁡θ2≠Rot(ϕ,θ,ω)01unless ei(ϕ−ω)=1 or sin⁡θ2=0\mathrm{Rot}(\omega,\theta,\phi)_{01}=-e^{i(\omega-\phi)/2}\sin\tfrac\theta2\ne\mathrm{Rot}(\phi,\theta,\omega)_{01}\quad\text{unless }e^{i(\phi-\omega)}=1\text{ or }\sin\tfrac\theta2=0
    Exchanging ϕ\phi and ω\omega conjugates the phase of the off-diagonal entries. The two orders agree when ϕ=ω\phi=\omega, which is why the lab has a check with ϕ=ω\phi=\omega that a learner with the wrong order still passes.
  5. Step 5:
    Rot(ϕ,0,ω)=diag(e−i(ϕ+ω)/2,ei(ϕ+ω)/2)=RZ(ϕ+ω)\mathrm{Rot}(\phi,0,\omega)=\mathrm{diag}\big(e^{-i(\phi+\omega)/2},e^{i(\phi+\omega)/2}\big)=R_Z(\phi+\omega)
    At θ=0\theta=0 the two ZZ rotations merge, because rotations about the same axis add their angles. Only the sum ϕ+ω\phi+\omega is then determined: the parametrisation is singular at θ=0\theta=0 (and at θ=π\theta=\pi, where only ϕ−ω\phi-\omega matters), the familiar gimbal lock of Euler angles.

Result

Rot(ϕ,θ,ω)=(e−i(ϕ+ω)/2cos⁡θ2−ei(ϕ−ω)/2sin⁡θ2e−i(ϕ−ω)/2sin⁡θ2ei(ϕ+ω)/2cos⁡θ2)\boxed{\mathrm{Rot}(\phi,\theta,\omega)=\begin{pmatrix}e^{-i(\phi+\omega)/2}\cos\frac\theta2&-e^{i(\phi-\omega)/2}\sin\frac\theta2\\e^{-i(\phi-\omega)/2}\sin\frac\theta2&e^{i(\phi+\omega)/2}\cos\frac\theta2\end{pmatrix}}
Lemma

The matrices of SU(2)

A complex 2×22\times2 matrix VV lies in SU(2)SU(2) (that is, V†V=IV^\dagger V=I and det⁡V=1\det V=1) if and only if V=(p−qˉqpˉ)with p,q∈C, ∣p∣2+∣q∣2=1.V=\begin{pmatrix}p&-\bar q\\q&\bar p\end{pmatrix}\qquad\text{with }p,q\in\mathbb C,\ \lvert p\rvert^2+\lvert q\rvert^2=1 .

Proof (6 steps)
  1. Step 1:
    V=(abcd),V†V=I  ⟺  ∣a∣2+∣c∣2=1,  ∣b∣2+∣d∣2=1,  aˉb+cˉd=0V=\begin{pmatrix}a&b\\c&d\end{pmatrix},\quad V^\dagger V=I\iff\lvert a\rvert^2+\lvert c\rvert^2=1,\ \ \lvert b\rvert^2+\lvert d\rvert^2=1,\ \ \bar ab+\bar cd=0
    The entries of V†VV^\dagger V are the inner products ⟨vj,vk⟩=∑m(vj)m‾(vk)m\langle v_j,v_k\rangle=\sum_m\overline{(v_j)_m}(v_k)_m of the columns v0=(a,c)v_0=(a,c), v1=(b,d)v_1=(b,d); unitarity says the columns are orthonormal.
  2. Step 2:
    ⟨(a,c),(−cˉ,aˉ)⟩=aˉ(−cˉ)+cˉ aˉ=0,∥(−cˉ,aˉ)∥2=∣c∣2+∣a∣2=1\big\langle(a,c),(-\bar c,\bar a)\big\rangle=\bar a(-\bar c)+\bar c\,\bar a=0,\qquad\lVert(-\bar c,\bar a)\rVert^2=\lvert c\rvert^2+\lvert a\rvert^2=1
    An explicit unit vector orthogonal to the first column.
  3. Step 3:
    dim⁡C{v∈C2:⟨v0,v⟩=0}=2−1=1 ⇒ (b,d)=t (−cˉ,aˉ),t∈C\dim_{\mathbb C}\{v\in\mathbb C^2:\langle v_0,v\rangle=0\}=2-1=1\ \Rightarrow\ (b,d)=t\,(-\bar c,\bar a),\quad t\in\mathbb C
    The orthogonal complement of the non-zero vector v0v_0 is the kernel of the non-zero linear functional v↦⟨v0,v⟩v\mapsto\langle v_0,v\rangle, hence one-dimensional and spanned by (−cˉ,aˉ)(-\bar c,\bar a).
  4. Step 4:
    det⁡V=ad−bc=a t aˉ−(−t cˉ) c=t(∣a∣2+∣c∣2)=t\det V=ad-bc=a\,t\,\bar a-(-t\,\bar c)\,c=t\big(\lvert a\rvert^2+\lvert c\rvert^2\big)=t
    Substitute b=−tcˉb=-t\bar c and d=taˉd=t\bar a and use the normalisation of the first column.
  5. Step 5:
    det⁡V=1 ⇒ t=1 ⇒ V=(a−cˉcaˉ)=:(p−qˉqpˉ)\det V=1\ \Rightarrow\ t=1\ \Rightarrow\ V=\begin{pmatrix}a&-\bar c\\c&\bar a\end{pmatrix}=:\begin{pmatrix}p&-\bar q\\q&\bar p\end{pmatrix}
    This proves the "only if" direction with p=ap=a, q=cq=c.
  6. Step 6:
    (pˉqˉ−qp)(p−qˉqpˉ)=(∣p∣2+∣q∣2−pˉqˉ+qˉpˉ−qp+pq∣q∣2+∣p∣2)=I,det⁡=∣p∣2+∣q∣2=1\begin{pmatrix}\bar p&\bar q\\-q&p\end{pmatrix}\begin{pmatrix}p&-\bar q\\q&\bar p\end{pmatrix}=\begin{pmatrix}\lvert p\rvert^2+\lvert q\rvert^2&-\bar p\bar q+\bar q\bar p\\-qp+pq&\lvert q\rvert^2+\lvert p\rvert^2\end{pmatrix}=I,\qquad\det=\lvert p\rvert^2+\lvert q\rvert^2=1
    The "if" direction: direct multiplication and the determinant ppˉ−(−qˉ)qp\bar p-(-\bar q)q.

∎

Theorem

ZYZ decomposition: Rot reaches all of SU(2)

For every U∈U(2)U\in U(2) there are real numbers α,β,γ,δ\alpha,\beta,\gamma,\delta, with γ∈[0,π]\gamma\in[0,\pi], such that U=eiα RZ(β) RY(γ) RZ(δ).U=e^{i\alpha}\,R_Z(\beta)\,R_Y(\gamma)\,R_Z(\delta). Consequently {Rot(ϕ,θ,ω):ϕ,θ,ω∈R}=SU(2)\{\mathrm{Rot}(\phi,\theta,\omega):\phi,\theta,\omega\in\mathbb R\}=SU(2), and every single-qubit unitary equals a Rot\mathrm{Rot} gate up to a global phase.

Proof (9 steps)
  1. Step 1:
    ∣det⁡U∣2=det⁡(U†)det⁡(U)=det⁡(U†U)=1 ⇒ det⁡U=e2iα for some α∈R\lvert\det U\rvert^2=\det(U^\dagger)\det(U)=\det(U^\dagger U)=1\ \Rightarrow\ \det U=e^{2i\alpha}\ \text{for some }\alpha\in\mathbb R
    Multiplicativity of the determinant and det⁡U†=det⁡U‾\det U^\dagger=\overline{\det U}.
  2. Step 2:
    V:=e−iαU:V†V=U†U=I,det⁡V=(e−iα)2det⁡U=e−2iαe2iα=1V:=e^{-i\alpha}U:\qquad V^\dagger V=U^\dagger U=I,\qquad\det V=\big(e^{-i\alpha}\big)^2\det U=e^{-2i\alpha}e^{2i\alpha}=1
    A scalar factor λ\lambda multiplies the determinant of a 2×22\times2 matrix by λ2\lambda^2 and leaves unitarity intact when ∣λ∣=1\lvert\lambda\rvert=1. Hence V∈SU(2)V\in SU(2).
  3. Step 3:
    V=(p−qˉqpˉ),∣p∣2+∣q∣2=1V=\begin{pmatrix}p&-\bar q\\q&\bar p\end{pmatrix},\qquad\lvert p\rvert^2+\lvert q\rvert^2=1
    The lemma on the matrices of SU(2)SU(2).
  4. Step 4:
    γ:=2arctan⁡ ⁣2(∣q∣,∣p∣)∈[0,π] ⇒ ∣p∣=cos⁡γ2, ∣q∣=sin⁡γ2;p=cos⁡γ2 eiλ,  q=sin⁡γ2 eiκ\gamma:=2\arctan\!2\big(\lvert q\rvert,\lvert p\rvert\big)\in[0,\pi]\ \Rightarrow\ \lvert p\rvert=\cos\tfrac\gamma2,\ \lvert q\rvert=\sin\tfrac\gamma2;\qquad p=\cos\tfrac\gamma2\,e^{i\lambda},\ \ q=\sin\tfrac\gamma2\,e^{i\kappa}
    The point (∣p∣,∣q∣)(\lvert p\rvert,\lvert q\rvert) lies on the quarter of the unit circle with non-negative coordinates, so it is (cos⁡γ2,sin⁡γ2)(\cos\frac\gamma2,\sin\frac\gamma2) for a unique γ2∈[0,π2]\frac\gamma2\in[0,\frac\pi2]. The phases λ=arg⁡p\lambda=\arg p and κ=arg⁡q\kappa=\arg q are arbitrary when the modulus vanishes.
  5. Step 5:
    RZ(β)RY(γ)RZ(δ)=(e−i(β+δ)/2cos⁡γ2−e−i(β−δ)/2sin⁡γ2ei(β−δ)/2sin⁡γ2ei(β+δ)/2cos⁡γ2)R_Z(\beta)R_Y(\gamma)R_Z(\delta)=\begin{pmatrix}e^{-i(\beta+\delta)/2}\cos\frac\gamma2&-e^{-i(\beta-\delta)/2}\sin\frac\gamma2\\e^{i(\beta-\delta)/2}\sin\frac\gamma2&e^{i(\beta+\delta)/2}\cos\frac\gamma2\end{pmatrix}
    The explicit matrix of Rot\mathrm{Rot} with ϕ=δ\phi=\delta, θ=γ\theta=\gamma, ω=β\omega=\beta.
  6. Step 6:
    β:=κ−λ,δ:=−κ−λ ⇒ −β+δ2=λ,β−δ2=κ\beta:=\kappa-\lambda,\quad\delta:=-\kappa-\lambda\ \Rightarrow\ -\tfrac{\beta+\delta}2=\lambda,\qquad\tfrac{\beta-\delta}2=\kappa
    Two linear equations for the two unknown angles: β+δ=−2λ\beta+\delta=-2\lambda and β−δ=2κ\beta-\delta=2\kappa.
  7. Step 7:
    RZ(β)RY(γ)RZ(δ)=(cos⁡γ2eiλ−sin⁡γ2e−iκsin⁡γ2eiκcos⁡γ2e−iλ)=(p−qˉqpˉ)=VR_Z(\beta)R_Y(\gamma)R_Z(\delta)=\begin{pmatrix}\cos\frac\gamma2e^{i\lambda}&-\sin\frac\gamma2e^{-i\kappa}\\\sin\frac\gamma2e^{i\kappa}&\cos\frac\gamma2e^{-i\lambda}\end{pmatrix}=\begin{pmatrix}p&-\bar q\\q&\bar p\end{pmatrix}=V
    Substitute the two phase relations entry by entry; eiκ‾=e−iκ\overline{e^{i\kappa}}=e^{-i\kappa} and eiλ‾=e−iλ\overline{e^{i\lambda}}=e^{-i\lambda}.
  8. Step 8:
    U=eiαV=eiαRZ(β)RY(γ)RZ(δ)=eiα Rot(δ,γ,β)U=e^{i\alpha}V=e^{i\alpha}R_Z(\beta)R_Y(\gamma)R_Z(\delta)=e^{i\alpha}\,\mathrm{Rot}(\delta,\gamma,\beta)
    Undo the phase. For U∈SU(2)U\in SU(2) we have e2iα=1e^{2i\alpha}=1, so eiα=±1e^{i\alpha}=\pm1; the sign −1-1 is absorbed by RY(γ+2π)=−RY(γ)R_Y(\gamma+2\pi)=-R_Y(\gamma), giving U=Rot(δ,γ+2π,β)U=\mathrm{Rot}(\delta,\gamma+2\pi,\beta). Together with Rot∈SU(2)\mathrm{Rot}\in SU(2) this proves {Rot}=SU(2)\{\mathrm{Rot}\}=SU(2).
  9. Step 9:
    (eiαV)i⊗Irest=eiα (Vi⊗Irest)\big(e^{i\alpha}V\big)_i\otimes I_{\text{rest}}=e^{i\alpha}\,\big(V_i\otimes I_{\text{rest}}\big)
    On a register, a phase on one tensor factor is a global phase of the whole state, which no measurement detects. A column of Rot\mathrm{Rot} gates therefore realises every product of single-qubit unitaries U0⊗⋯⊗Un−1U_0\otimes\cdots\otimes U_{n-1} up to an unobservable phase.

∎

Quick check

Which gate is Rot(ϕ,0,ω)\mathrm{Rot}(\phi,0,\omega)?

Select one answer

Layers, ranges and resources#

Definition

Strongly entangling layers (PennyLane convention)

Let n≥1n\ge1 be the number of wires, L≥1L\ge1 the number of layers and w∈RL×n×3w\in\mathbb R^{L\times n\times3} the weights; wℓ,i=(wℓ,i,0,wℓ,i,1,wℓ,i,2)=(ϕ,θ,ω)w_{\ell,i}=(w_{\ell,i,0},w_{\ell,i,1},w_{\ell,i,2})=(\phi,\theta,\omega) belongs to wire ii in layer ℓ\ell. For n≥2n\ge2 a range sequence r0,…,rL−1∈{1,…,n−1}r_0,\dots,r_{L-1}\in\{1,\dots,n-1\} is chosen, by default rℓ=(ℓ mod (n−1))+1.r_\ell=(\ell\bmod(n-1))+1 . Layer ℓ\ell is the circuit Wℓ=Brℓ⋅⨂i=0n−1Rot(wℓ,i,0,wℓ,i,1,wℓ,i,2),Br=CNOT(n−1,(n−1+r) mod n)⋯CNOT(1,(1+r) mod n) CNOT(0,r),W_\ell=B_{r_\ell}\cdot\bigotimes_{i=0}^{n-1}\mathrm{Rot}(w_{\ell,i,0},w_{\ell,i,1},w_{\ell,i,2}),\qquad B_r=\mathrm{CNOT}\big(n-1,(n-1+r)\bmod n\big)\cdots\mathrm{CNOT}\big(1,(1+r)\bmod n\big)\,\mathrm{CNOT}\big(0,r\big), i.e. in time order the rotations on all wires, then CNOT(i,(i+rℓ) mod n)\mathrm{CNOT}(i,(i+r_\ell)\bmod n) for i=0,1,…,n−1i=0,1,\dots,n-1 (control ii, target (i+rℓ) mod n(i+r_\ell)\bmod n). For n=1n=1 there is no entangling block: Wℓ=Rot(wℓ,0)W_\ell=\mathrm{Rot}(w_{\ell,0}). The template is W(w)=WL−1⋯W1W0W(w)=W_{L-1}\cdots W_1W_0.

Proposition

Admissible ranges and the cycle structure of a block

Let n≥2n\ge2. (a) CNOT(i,(i+r) mod n)\mathrm{CNOT}(i,(i+r)\bmod n) is a valid two-qubit gate for every ii if and only if r≢0(modn)r\not\equiv0\pmod n; the ranges rr and r+nr+n give the same block, so r∈{1,…,n−1}r\in\{1,\dots,n-1\} lists every admissible block exactly once, and r=nr=n is excluded. (b) The default sequence rℓ=(ℓ mod (n−1))+1r_\ell=(\ell\bmod(n-1))+1 takes the values 1,2,…,n−1,1,2,…1,2,\dots,n-1,1,2,\dots in this cyclic order. (c) Regard each CNOT of BrB_r as the edge {i,i+r}\{i,i+r\} on the wires. The edges form g=gcd⁡(n,r)g=\gcd(n,r) disjoint cycles {c,c+r,c+2r,… }\{c,c+r,c+2r,\dots\}, c=0,…,g−1c=0,\dots,g-1, each of length n/gn/g; for r=1r=1 the block is one cycle through all wires, for n=3n=3 it is the triangle on {0,1,2}\{0,1,2\} for both r=1r=1 and r=2r=2.

Proof (6 steps)
  1. Step 1:
    (i+r) mod n=i  ⟺  r≡0(modn)(i+r)\bmod n=i\iff r\equiv0\pmod n
    A CNOT needs two distinct wires. If rr is a multiple of nn, every "gate" CNOT(i,i)\mathrm{CNOT}(i,i) has control equal to target and is undefined; otherwise no wire is paired with itself.
  2. Step 2:
    (i+r+n) mod n=(i+r) mod n(i+r+n)\bmod n=(i+r)\bmod n
    Only r mod nr\bmod n enters the block, and the non-zero residues are exactly 1,…,n−11,\dots,n-1. In particular r=nr=n is the excluded residue 00.
  3. Step 3:
    ℓ=0,1,…,n−2: rℓ=ℓ+1;ℓ=n−1: rℓ=0+1=1;rℓ+(n−1)=rℓ\ell=0,1,\dots,n-2:\ r_\ell=\ell+1;\qquad\ell=n-1:\ r_\ell=0+1=1;\qquad r_{\ell+(n-1)}=r_\ell
    ℓ mod (n−1)\ell\bmod(n-1) runs through 0,…,n−20,\dots,n-2 periodically with period n−1n-1, so the range runs through 1,…,n−11,\dots,n-1 and starts again. For n=2n=2 every layer has rℓ=1r_\ell=1.
  4. Step 4:
    i↦(i+r) mod n is a bijection of Zn ⇒ every wire has degree 2 in the multigraph of Bri\mapsto(i+r)\bmod n\ \text{is a bijection of }\mathbb Z_n\ \Rightarrow\ \text{every wire has degree }2\text{ in the multigraph of }B_r
    Wire ii is the control of edge {i,i+r}\{i,i+r\} and the target of edge {i−r,i}\{i-r,i\}. A finite multigraph in which every vertex has degree 22 is a disjoint union of cycles.
  5. Step 5:
    orbit of c: {c+kr mod n:k∈Z}=c+gZn,∣c+gZn∣=ng\text{orbit of }c:\ \{c+kr\bmod n:k\in\mathbb Z\}=c+g\mathbb Z_n,\qquad\lvert c+g\mathbb Z_n\rvert=\frac ng
    The subgroup of Zn\mathbb Z_n generated by rr is generated by g=gcd⁡(n,r)g=\gcd(n,r) (Bézout: g=ar+bng=ar+bn), so the orbits are the gg cosets of gZng\mathbb Z_n, each with n/gn/g elements. For gcd⁡(n,r)=1\gcd(n,r)=1 there is a single cycle through all nn wires.
  6. Step 6:
    n=3: r=1: {0,1},{1,2},{2,0};r=2: {0,2},{1,0},{2,1}n=3:\ r=1:\ \{0,1\},\{1,2\},\{2,0\};\qquad r=2:\ \{0,2\},\{1,0\},\{2,1\}
    For n=3n=3 both blocks consist of the three edges of the triangle; they differ in the direction of the CNOTs and in the order in which the edges are applied, which the F2\mathbb F_2 analysis below makes precise. If n/g=2n/g=2 (i.e. r=n/2r=n/2), each cycle is a pair {i,i+n/2}\{i,i+n/2\} carrying the two CNOTs CNOT(i,i+n2)\mathrm{CNOT}(i,i+\frac n2) and CNOT(i+n2,i)\mathrm{CNOT}(i+\frac n2,i).

∎

Circuit · 3 qubits

Quantum circuit on 3 qubitsRZ(0.30) on q0; RY(1.20) on q0; RZ(-0.40) on q0; RZ(0.80) on q1; RY(-0.50) on q1; RZ(1.10) on q1; RZ(-1.00) on q2; RY(0.70) on q2; RZ(0.20) on q2; X on q1 controlled by q0; X on q2 controlled by q1; X on q0 controlled by q2; RZ(0.50) on q0; RY(-1.30) on q0; RZ(0.90) on q0; RZ(-0.20) on q1; RY(0.40) on q1; RZ(-0.70) on q1; RZ(1.40) on q2; RY(0.60) on q2; RZ(-1.10) on q2; X on q2 controlled by q0; X on q0 controlled by q1; X on q1 controlled by q2q0q1q2RZ(0.30)RY(1.20)RZ(-0.40)RZ(0.80)RY(-0.50)RZ(1.10)RZ(-1.00)RY(0.70)RZ(0.20)RZ(0.50)RY(-1.30)RZ(0.90)RZ(-0.20)RY(0.40)RZ(-0.70)RZ(1.40)RY(0.60)RZ(-1.10)

Two strongly entangling layers on n=3n=3 qubits with the numeric weights w0=((0.3,1.2,−0.4),(0.8,−0.5,1.1),(−1.0,0.7,0.2))w_{0}=\big((0.3,1.2,-0.4),(0.8,-0.5,1.1),(-1.0,0.7,0.2)\big) and w1=((0.5,−1.3,0.9),(−0.2,0.4,−0.7),(1.4,0.6,−1.1))w_{1}=\big((0.5,-1.3,0.9),(-0.2,0.4,-0.7),(1.4,0.6,-1.1)\big). Each wire receives RZ(ϕ)R_Z(\phi), RY(θ)R_Y(\theta), RZ(ω)R_Z(\omega); layer 00 has range r0=1r_0=1 (CNOTs (0,1),(1,2),(2,0)(0,1),(1,2),(2,0)), layer 11 has range r1=2r_1=2 (CNOTs (0,2),(1,0),(2,1)(0,2),(1,0),(2,1)).

∣ψ⟩=(0.2829−0.4858i)∣000⟩+(0.1337+0.0154i)∣001⟩+(−0.1854+0.1183i)∣010⟩+(0.0238−0.0441i)∣011⟩+(0.0759+0.3303i)∣100⟩+(−0.2724−0.3995i)∣101⟩+(−0.1327−0.0755i)∣110⟩+(−0.4597−0.1781i)∣111⟩\lvert\psi\rangle = \left(0.2829 - 0.4858i\right)\lvert 000\rangle + \left(0.1337 + 0.0154i\right)\lvert 001\rangle + \left(-0.1854 + 0.1183i\right)\lvert 010\rangle + \left(0.0238 - 0.0441i\right)\lvert 011\rangle + \left(0.0759 + 0.3303i\right)\lvert 100\rangle + \left(-0.2724 - 0.3995i\right)\lvert 101\rangle + \left(-0.1327 - 0.0755i\right)\lvert 110\rangle + \left(-0.4597 - 0.1781i\right)\lvert 111\rangle
Proposition

Parameter and gate counts

LL strongly entangling layers on nn wires have (a) 3nL3nL trainable parameters and 3nL3nL single-qubit rotations; (b) nLnL CNOTs if n≥2n\ge2 and none if n=1n=1; (c) for n=3n=3, depth exactly 66 per layer, so depth 6L6L for the whole circuit. For n=2n=2 the block is B1=CNOT(1,0) CNOT(0,1)B_1=\mathrm{CNOT}(1,0)\,\mathrm{CNOT}(0,1), which maps ∣x0x1⟩↦∣x1, x0⊕x1⟩\lvert x_0x_1\rangle\mapsto\lvert x_1,\,x_0\oplus x_1\rangle.

Proof (5 steps)
  1. Step 1:
    #w=∑ℓ=0L−1∑i=0n−13=3nL,#rotations=3⋅#Rot=3nL\#w=\sum_{\ell=0}^{L-1}\sum_{i=0}^{n-1}3=3nL,\qquad\#\text{rotations}=3\cdot\#\mathrm{Rot}=3nL
    One Rot\mathrm{Rot} gate with three independent angles per wire and layer; it is emitted as three rotations.
  2. Step 2:
    #CNOT=∑ℓ=0L−1#{i:0≤i≤n−1}=nL(n≥2)\#\mathrm{CNOT}=\sum_{\ell=0}^{L-1}\#\{i:0\le i\le n-1\}=nL\quad(n\ge2)
    Every block has one CNOT per wire ii, including the wrap-around gate CNOT(n−1,(n−1+r) mod n)\mathrm{CNOT}(n-1,(n-1+r)\bmod n); the HEA ladder has only n−1n-1 CNOTs because it does not close the cycle.
  3. Step 3:
    n=3: any two edges of the triangle share a wire ⇒ depth(Br)=3n=3:\ \text{any two edges of the triangle share a wire}\ \Rightarrow\ \mathrm{depth}(B_r)=3
    Gates sharing a wire cannot be in the same moment, so the three CNOTs of a block occupy three consecutive moments.
  4. Step 4:
    depth(Wℓ)=3+3=6,depth(W)=6L\mathrm{depth}(W_\ell)=3+3=6,\qquad\mathrm{depth}(W)=6L
    Three moments for RZ,RY,RZR_Z,R_Y,R_Z on all wires, three for the block. Layers do not overlap: if a block ends at moment TT, the two wires of its last CNOT are busy until TT, and any pair of the three wires contains one of them. The first CNOT of the next block therefore waits for three rotations after TT and runs at T+4T+4, and its two successors follow at T+5T+5 and T+6T+6, because the edges of the triangle pairwise share a wire.
  5. Step 5:
    (x0,x1)→CNOT(0,1)(x0, x0⊕x1)→CNOT(1,0)(x0⊕(x0⊕x1), x0⊕x1)=(x1, x0⊕x1)(x_0,x_1)\xrightarrow{\mathrm{CNOT}(0,1)}(x_0,\,x_0\oplus x_1)\xrightarrow{\mathrm{CNOT}(1,0)}\big(x_0\oplus(x_0\oplus x_1),\,x_0\oplus x_1\big)=(x_1,\,x_0\oplus x_1)
    For n=2n=2 the range is r=1r=1 and the block is CNOT(0,1)\mathrm{CNOT}(0,1) followed by CNOT(1,0)\mathrm{CNOT}(1,0); x0⊕x0=0x_0\oplus x_0=0. This is the visible test of the lab: two of the three CNOTs of a SWAP.

∎

The gallery draws the 33-qubit, 22-layer template (1818 parameters, 66 CNOTs) and compares its fidelity histogram with the Haar density 7(1−F)67(1-F)^6 for d=8d=8, as in the previous lesson.

Quick check

How many trainable parameters do L=4L=4 strongly entangling layers on n=6n=6 wires have?

tolerance ±0.5

Quick check

With n=5n=5 wires and the default ranges, what is the range r5r_5 of layer ℓ=5\ell=5?

tolerance ±0.5

The entangling block as a linear map over F₂#

A block of CNOTs never creates superpositions on its own: it permutes the computational basis. The permutation is not arbitrary. Writing a basis label as a column vector x=(x0,…,xn−1)⊤x=(x_0,\dots,x_{n-1})^\top over the two-element field F2={0,1}\mathbb F_2=\{0,1\}, with addition ⊕\oplus (XOR) and multiplication AND, every CNOT block is a linear map x↦Axx\mapsto Ax with an invertible matrix AA. This turns questions about entangling blocks into linear algebra, exactly as the prefix-parity lemma did for the ladder of the hardware-efficient ansatz.

Lemma

A CNOT is an elementary row operation over F₂

For distinct wires c≠tc\ne t let Etc=I+etec⊤∈F2n×nE_{tc}=I+e_te_c^\top\in\mathbb F_2^{n\times n}, the identity with an additional 11 in row tt, column cc. Then CNOT(c,t)∣x⟩=∣Etcx⟩\mathrm{CNOT}(c,t)\lvert x\rangle=\lvert E_{tc}x\rangle for every x∈F2nx\in\mathbb F_2^n, and Etc2=IE_{tc}^2=I. If a block B=gm−1⋯g1g0B=g_{m-1}\cdots g_1g_0 consists of CNOTs gk=CNOT(ck,tk)g_k=\mathrm{CNOT}(c_k,t_k), applied in the order g0,g1,…g_0,g_1,\dots, then B∣x⟩=∣Ax⟩,A=Etm−1cm−1⋯Et1c1Et0c0,A−1=Et0c0Et1c1⋯Etm−1cm−1.B\lvert x\rangle=\lvert Ax\rangle,\qquad A=E_{t_{m-1}c_{m-1}}\cdots E_{t_1c_1}E_{t_0c_0},\qquad A^{-1}=E_{t_0c_0}E_{t_1c_1}\cdots E_{t_{m-1}c_{m-1}} .

Proof (5 steps)
  1. Step 1:
    CNOT(c,t)∣x⟩=∣x′⟩,xt′=xt⊕xc,xk′=xk (k≠t)\mathrm{CNOT}(c,t)\lvert x\rangle=\lvert x'\rangle,\qquad x'_t=x_t\oplus x_c,\quad x'_k=x_k\ (k\ne t)
    CNOT(c,t)=∣0⟩⟨0∣c⊗It+∣1⟩⟨1∣c⊗Xt\mathrm{CNOT}(c,t)=\lvert0\rangle\langle0\rvert_c\otimes I_t+\lvert1\rangle\langle1\rvert_c\otimes X_t flips the target bit exactly when the control bit is 11, i.e. adds xcx_c to xtx_t modulo 22.
  2. Step 2:
    (Etcx)t=xt+xc,(Etcx)k=xk (k≠t) ⇒ x′=Etcx(E_{tc}x)_t=x_t+x_c,\qquad(E_{tc}x)_k=x_k\ (k\ne t)\ \Rightarrow\ x'=E_{tc}x
    Row tt of EtcE_{tc} has ones in columns tt and cc, every other row is a row of the identity. Multiplying by EtcE_{tc} adds row cc of a matrix to row tt: the elementary row operation rowt←rowt+rowc\mathrm{row}_t\leftarrow\mathrm{row}_t+\mathrm{row}_c.
  3. Step 3:
    Etc2=I+2 etec⊤+et(ec⊤et)ec⊤=I+0+0=IE_{tc}^2=I+2\,e_te_c^\top+e_t\big(e_c^\top e_t\big)e_c^\top=I+0+0=I
    In F2\mathbb F_2, 2=02=0, and ec⊤et=0e_c^\top e_t=0 because c≠tc\ne t. Hence every CNOT is its own inverse, as a matrix over F2\mathbb F_2 and as a unitary.
  4. Step 4:
    B∣x⟩=gm−1⋯g1∣Et0c0x⟩=⋯=∣Etm−1cm−1⋯Et0c0x⟩=∣Ax⟩B\lvert x\rangle=g_{m-1}\cdots g_1\lvert E_{t_0c_0}x\rangle=\cdots=\lvert E_{t_{m-1}c_{m-1}}\cdots E_{t_0c_0}x\rangle=\lvert Ax\rangle
    Induction over the gates: each gate maps a basis state to a basis state and multiplies the current label from the left by its elementary matrix; later gates stand further to the left.
  5. Step 5:
    A⋅Et0c0⋯Etm−1cm−1=Etm−1cm−1⋯Et0c0Et0c0⋯Etm−1cm−1=IA\cdot E_{t_0c_0}\cdots E_{t_{m-1}c_{m-1}}=E_{t_{m-1}c_{m-1}}\cdots E_{t_0c_0}E_{t_0c_0}\cdots E_{t_{m-1}c_{m-1}}=I
    The innermost pair Et0c0Et0c0=IE_{t_0c_0}E_{t_0c_0}=I cancels, then the next pair, and so on. Thus AA is invertible, x↦Axx\mapsto Ax is a bijection of F2n\mathbb F_2^n, and BB is a permutation matrix.

∎

Derivation

The n = 3, r = 1 block step by step

  1. Step 1:
    B1=CNOT(2,0) CNOT(1,2) CNOT(0,1)B_1=\mathrm{CNOT}(2,0)\,\mathrm{CNOT}(1,2)\,\mathrm{CNOT}(0,1)
    r=1r=1: the gates CNOT(i,(i+1) mod 3)\mathrm{CNOT}(i,(i+1)\bmod3) for i=0,1,2i=0,1,2, applied in this order (rightmost first).
  2. Step 2:
    (x0,x1,x2)→CNOT(0,1)(x0, x0⊕x1, x2)(x_0,x_1,x_2)\xrightarrow{\mathrm{CNOT}(0,1)}(x_0,\ x_0\oplus x_1,\ x_2)
    Control x0x_0, target wire 11: x1←x1⊕x0x_1\leftarrow x_1\oplus x_0.
  3. Step 3:
    →CNOT(1,2)(x0, x0⊕x1, x0⊕x1⊕x2)\xrightarrow{\mathrm{CNOT}(1,2)}(x_0,\ x_0\oplus x_1,\ x_0\oplus x_1\oplus x_2)
    The control is the current bit on wire 11, which is already x0⊕x1x_0\oplus x_1; the target wire 22 becomes x2⊕x0⊕x1x_2\oplus x_0\oplus x_1.
  4. Step 4:
    →CNOT(2,0)(x0⊕x0⊕x1⊕x2, x0⊕x1, x0⊕x1⊕x2)=(x1⊕x2, x0⊕x1, x0⊕x1⊕x2)\xrightarrow{\mathrm{CNOT}(2,0)}\big(x_0\oplus x_0\oplus x_1\oplus x_2,\ x_0\oplus x_1,\ x_0\oplus x_1\oplus x_2\big)=\big(x_1\oplus x_2,\ x_0\oplus x_1,\ x_0\oplus x_1\oplus x_2\big)
    The wrap-around gate adds the current bit of wire 22 to wire 00; x0⊕x0=0x_0\oplus x_0=0.
  5. Step 5:
    A=(011110111)=E02E21E10=(101010001)(100010011)(100110001)A=\begin{pmatrix}0&1&1\\1&1&0\\1&1&1\end{pmatrix}=E_{02}E_{21}E_{10}=\begin{pmatrix}1&0&1\\0&1&0\\0&0&1\end{pmatrix}\begin{pmatrix}1&0&0\\0&1&0\\0&1&1\end{pmatrix}\begin{pmatrix}1&0&0\\1&1&0\\0&0&1\end{pmatrix}
    Row kk of AA lists which inputs enter output bit kk. The product of the elementary matrices (mod 22) gives the same rows, as the lemma predicts.
  6. Step 6:
    det⁡A=0⋅(1−0)−1⋅(1−0)+1⋅(1−1)=−1≡1(mod2)\det A=0\cdot(1-0)-1\cdot(1-0)+1\cdot(1-1)=-1\equiv1\pmod2
    Cofactor expansion along the first row. A non-zero determinant over F2\mathbb F_2 confirms invertibility independently of the lemma.
  7. Step 7:
    y=Ax:  x0=y0⊕y2,x1=y1⊕x0=y0⊕y1⊕y2,x2=y2⊕x0⊕x1=y1⊕y2y=Ax:\ \ x_0=y_0\oplus y_2,\quad x_1=y_1\oplus x_0=y_0\oplus y_1\oplus y_2,\quad x_2=y_2\oplus x_0\oplus x_1=y_1\oplus y_2
    Solve for the inputs: y0⊕y2=(x1⊕x2)⊕(x0⊕x1⊕x2)=x0y_0\oplus y_2=(x_1\oplus x_2)\oplus(x_0\oplus x_1\oplus x_2)=x_0; then x1=y1⊕x0x_1=y_1\oplus x_0 from y1=x0⊕x1y_1=x_0\oplus x_1; finally x0⊕x1=y1x_0\oplus x_1=y_1 in y2y_2.
  8. Step 8:
    A−1=(101111011),AA−1=(0+1+00+1+10+1+11+1+00+1+01+1+01+1+00+1+11+1+1)=(100010001)A^{-1}=\begin{pmatrix}1&0&1\\1&1&1\\0&1&1\end{pmatrix},\qquad AA^{-1}=\begin{pmatrix}0+1+0&0+1+1&0+1+1\\1+1+0&0+1+0&1+1+0\\1+1+0&0+1+1&1+1+1\end{pmatrix}=\begin{pmatrix}1&0&0\\0&1&0\\0&0&1\end{pmatrix}
    The inverse read off from the previous line, checked by multiplication modulo 22. It equals E10E21E02E_{10}E_{21}E_{02}, the gates in reverse order.
  9. Step 9:
    (i,j)∈{(0,1),(0,2),(1,2)}:A01=1,A02=1,A21=1(i,j)\in\{(0,1),(0,2),(1,2)\}:\quad A_{01}=1,\quad A_{02}=1,\quad A_{21}=1
    For every pair of distinct wires, the input of one of them enters the output of the other: x1x_1 and x2x_2 both reach output 00, and x1x_1 reaches output 22. Already a single layer couples every wire to every other; output 22 is the parity of all three inputs.

Result

B1∣x0x1x2⟩=∣x1⊕x2, x0⊕x1, x0⊕x1⊕x2⟩,A=(011110111),A−1=(101111011)\boxed{B_1\lvert x_0x_1x_2\rangle=\lvert x_1\oplus x_2,\ x_0\oplus x_1,\ x_0\oplus x_1\oplus x_2\rangle,\qquad A=\begin{pmatrix}0&1&1\\1&1&0\\1&1&1\end{pmatrix},\qquad A^{-1}=\begin{pmatrix}1&0&1\\1&1&1\\0&1&1\end{pmatrix}}
B1=(1000000000000001000100000000100000000010010000000000010000100000),000↦000, 001↦101, 010↦111, 011↦010,100↦011, 101↦110, 110↦100, 111↦001B_1=\begin{pmatrix}1&0&0&0&0&0&0&0\\0&0&0&0&0&0&0&1\\0&0&0&1&0&0&0&0\\0&0&0&0&1&0&0&0\\0&0&0&0&0&0&1&0\\0&1&0&0&0&0&0&0\\0&0&0&0&0&1&0&0\\0&0&1&0&0&0&0&0\end{pmatrix},\qquad\begin{aligned}&000\mapsto000,\ 001\mapsto101,\ 010\mapsto111,\ 011\mapsto010,\\&100\mapsto011,\ 101\mapsto110,\ 110\mapsto100,\ 111\mapsto001\end{aligned}
B₁ = CNOT(2,0) CNOT(1,2) CNOT(0,1) on three qubits8×8

Unitary verified: U†U=IU^\dagger U = I (max deviation 0.0e+0)

Derivation

The n = 3, r = 2 block of the second layer

  1. Step 1:
    B2=CNOT(2,1) CNOT(1,0) CNOT(0,2)B_2=\mathrm{CNOT}(2,1)\,\mathrm{CNOT}(1,0)\,\mathrm{CNOT}(0,2)
    r=2r=2: targets (i+2) mod 3=2,0,1(i+2)\bmod3=2,0,1 for i=0,1,2i=0,1,2.
  2. Step 2:
    (x0,x1,x2)→CNOT(0,2)(x0, x1, x0⊕x2)→CNOT(1,0)(x0⊕x1, x1, x0⊕x2)(x_0,x_1,x_2)\xrightarrow{\mathrm{CNOT}(0,2)}(x_0,\ x_1,\ x_0\oplus x_2)\xrightarrow{\mathrm{CNOT}(1,0)}(x_0\oplus x_1,\ x_1,\ x_0\oplus x_2)
    First wire 22 receives x0x_0, then wire 00 receives the current bit x1x_1 of wire 11.
  3. Step 3:
    →CNOT(2,1)(x0⊕x1, x0⊕x1⊕x2, x0⊕x2)\xrightarrow{\mathrm{CNOT}(2,1)}\big(x_0\oplus x_1,\ x_0\oplus x_1\oplus x_2,\ x_0\oplus x_2\big)
    Wire 11 receives the current bit x0⊕x2x_0\oplus x_2 of wire 22.
  4. Step 4:
    A′=(110111101),det⁡A′=1⋅(1−0)−1⋅(1−1)+0=1A'=\begin{pmatrix}1&1&0\\1&1&1\\1&0&1\end{pmatrix},\qquad\det A'=1\cdot(1-0)-1\cdot(1-1)+0=1
    The rows list the inputs of each output; the determinant over F2\mathbb F_2 is 11.
  5. Step 5:
    x2=y0⊕y1,x0=y2⊕x2=y0⊕y1⊕y2,x1=y0⊕x0=y1⊕y2x_2=y_0\oplus y_1,\quad x_0=y_2\oplus x_2=y_0\oplus y_1\oplus y_2,\quad x_1=y_0\oplus x_0=y_1\oplus y_2
    Solve: y0⊕y1=x2y_0\oplus y_1=x_2, then y2=x0⊕x2y_2=x_0\oplus x_2 gives x0x_0, then y0=x0⊕x1y_0=x_0\oplus x_1 gives x1x_1.
  6. Step 6:
    A′−1=(111011110),A′A′−1=(1+0+01+1+01+1+01+0+11+1+11+1+01+0+11+0+11+0+0)=IA'^{-1}=\begin{pmatrix}1&1&1\\0&1&1\\1&1&0\end{pmatrix},\qquad A'A'^{-1}=\begin{pmatrix}1+0+0&1+1+0&1+1+0\\1+0+1&1+1+1&1+1+0\\1+0+1&1+0+1&1+0+0\end{pmatrix}=I
    Multiplication modulo 22 confirms the inverse.
  7. Step 7:
    A′A=(110111101)(011110111)=(101010100)A'A=\begin{pmatrix}1&1&0\\1&1&1\\1&0&1\end{pmatrix}\begin{pmatrix}0&1&1\\1&1&0\\1&1&1\end{pmatrix}=\begin{pmatrix}1&0&1\\0&1&0\\1&0&0\end{pmatrix}
    Without rotations the blocks of two layers with ranges 1,21,2 compose to A′AA'A (the second block acts after the first). In this composite, output 11 is x1x_1 and output 22 is x0x_0: the second block partly undoes the mixing of the first. The rotations between the blocks destroy this cancellation in the full circuit, which is why the lab compares unitaries rather than permutations.

Result

B2∣x0x1x2⟩=∣x0⊕x1, x0⊕x1⊕x2, x0⊕x2⟩,A′−1=(111011110)\boxed{B_2\lvert x_0x_1x_2\rangle=\lvert x_0\oplus x_1,\ x_0\oplus x_1\oplus x_2,\ x_0\oplus x_2\rangle,\qquad A'^{-1}=\begin{pmatrix}1&1&1\\0&1&1\\1&1&0\end{pmatrix}}
Proposition

A range-1 block couples every pair of wires

For n≥2n\ge2 the block B1=CNOT(n−1,0) CNOT(n−2,n−1)⋯CNOT(0,1)B_1=\mathrm{CNOT}(n-1,0)\,\mathrm{CNOT}(n-2,n-1)\cdots\mathrm{CNOT}(0,1) maps ∣x⟩\lvert x\rangle to ∣y⟩\lvert y\rangle with y0=x1⊕x2⊕⋯⊕xn−1,yk=x0⊕x1⊕⋯⊕xk(1≤k≤n−1).y_0=x_1\oplus x_2\oplus\cdots\oplus x_{n-1},\qquad y_k=x_0\oplus x_1\oplus\cdots\oplus x_k\quad(1\le k\le n-1). Hence for all wires i<ji<j the input xix_i enters the output yjy_j: a single layer couples every wire to every other, and the output on wire n−1n-1 is the parity of all inputs.

Proof (3 steps)
  1. Step 1:
    CNOT(n−2,n−1)⋯CNOT(0,1)∣x⟩=∣x0, x0⊕x1, …, x0⊕⋯⊕xn−1⟩\mathrm{CNOT}(n-2,n-1)\cdots\mathrm{CNOT}(0,1)\lvert x\rangle=\lvert x_0,\ x_0\oplus x_1,\ \dots,\ x_0\oplus\cdots\oplus x_{n-1}\rangle
    The first n−1n-1 gates are exactly the CNOT ladder EE of the hardware-efficient ansatz, which computes prefix parities (lemma of the previous lesson).
  2. Step 2:
    CNOT(n−1,0): y0=x0⊕(x0⊕x1⊕⋯⊕xn−1)=x1⊕⋯⊕xn−1\mathrm{CNOT}(n-1,0):\ y_0=x_0\oplus\big(x_0\oplus x_1\oplus\cdots\oplus x_{n-1}\big)=x_1\oplus\cdots\oplus x_{n-1}
    The wrap-around gate adds the current bit of wire n−1n-1, the total parity, to wire 00; x0⊕x0=0x_0\oplus x_0=0. The other bits are unchanged.
  3. Step 3:
    i<j ⇒ j≥1, i≤j ⇒ Aji=1i<j\ \Rightarrow\ j\ge1,\ i\le j\ \Rightarrow\ A_{ji}=1
    Row j≥1j\ge1 of AA is the prefix (1,…,1,0,…,0)(1,\dots,1,0,\dots,0) with j+1j+1 ones, so it contains column ii. For n=3n=3 this reproduces A=(011110111)A=\begin{pmatrix}0&1&1\\1&1&0\\1&1&1\end{pmatrix}.

∎

Quick check

The n=3n=3, r=1r=1 block acts on the basis state ∣100⟩\lvert100\rangle. Give the output label y0y1y2y_0y_1y_2 as a decimal number (qubit 00 is the most significant bit).

tolerance ±0.5

Light cones and direct couplings#

Definition

Light cone of a wire

Let a circuit be a sequence of gates, each acting on a set of wires (its support). The forward light cone of wire ww is computed by starting from S={w}S=\{w\} and processing the gates in time order: whenever the support of a gate meets SS, the whole support is added to SS. The backward light cone of ww is obtained in the same way with the gates processed in reverse time order. Single-qubit gates never enlarge SS. An input on a wire outside the backward light cone of ww cannot influence any measurement on ww at the end of the circuit, because the reduced state of the cone's wires evolves under the gates inside it only; the cone is therefore an upper bound on the set of inputs that a local observable can depend on.

Theorem

Growth of the light cone through one block

Let SS be the light cone (in either direction) before the entangling block BrB_r and S′S' the light cone after it. Write S±r={(s±r) mod n:s∈S}S\pm r=\{(s\pm r)\bmod n:s\in S\} and let Cr(S)C_r(S) be the union of the cycles of BrB_r that meet SS. Then S∪(S+r)∪(S−r) ⊆ S′ ⊆ Cr(S).S\cup(S+r)\cup(S-r)\ \subseteq\ S'\ \subseteq\ C_r(S). Consequently, with the default ranges and L≤n−1L\le n-1 layers, the light cone of every wire contains {w+k mod n:∣k∣≤L(L+1)2}\{w+k\bmod n:\lvert k\rvert\le\tfrac{L(L+1)}2\}, and it is the whole register as soon as L(L+1)+1≥nL(L+1)+1\ge n.

Proof (8 steps)
  1. Step 1:
    S⊆S0⊆S1⊆⋯⊆Sn=S′S\subseteq S_0\subseteq S_1\subseteq\cdots\subseteq S_n=S'
    SkS_k is the set after processing kk of the nn gates of the block, in whichever order the direction prescribes. The update only adds wires.
  2. Step 2:
    s∈S, gate {s,(s+r) mod n} processed at step k ⇒ s∈Sk−1 ⇒ (s+r) mod n∈Sk⊆S′s\in S,\ \text{gate }\{s,(s+r)\bmod n\}\ \text{processed at step }k\ \Rightarrow\ s\in S_{k-1}\ \Rightarrow\ (s+r)\bmod n\in S_k\subseteq S'
    Every wire ss is the control of the gate CNOT(s,s+r)\mathrm{CNOT}(s,s+r); when that gate is processed, ss is already in the set by monotonicity, so its partner is added. Hence S+r⊆S′S+r\subseteq S'.
  3. Step 3:
    s∈S, gate {(s−r) mod n,s} ⇒ (s−r) mod n∈S′s\in S,\ \text{gate }\{(s-r)\bmod n,s\}\ \Rightarrow\ (s-r)\bmod n\in S'
    Every wire is also the target of exactly one gate, CNOT(s−r,s)\mathrm{CNOT}(s-r,s), by the same argument. Hence S−r⊆S′S-r\subseteq S'.
  4. Step 4:
    v∈Sk∖Sk−1 ⇒ v adjacent in the cycle graph of Br to some u∈Sk−1v\in S_k\setminus S_{k-1}\ \Rightarrow\ v\ \text{adjacent in the cycle graph of }B_r\text{ to some }u\in S_{k-1}
    A wire enters only together with a partner that already belongs to the set. By induction, every wire of S′S' is connected within the cycle graph to a wire of SS, so S′⊆Cr(S)S'\subseteq C_r(S).
  5. Step 5:
    S(L)⊇w+{∑ℓ=0L−1εℓrℓ:εℓ∈{−1,0,1}}S^{(L)}\supseteq w+\Big\{\sum_{\ell=0}^{L-1}\varepsilon_\ell r_\ell:\varepsilon_\ell\in\{-1,0,1\}\Big\}
    Apply the lower bound layer by layer (rotations do not change the set). The backward cone processes the layers in reverse order, which produces the same set of signed sums.
  6. Step 6:
    rℓ=ℓ+1 (ℓ<L≤n−1):{∑ℓ∈T(ℓ+1):T⊆{0,…,L−1}}={0,1,…,L(L+1)2}r_\ell=\ell+1\ (\ell<L\le n-1):\quad\Big\{\sum_{\ell\in T}(\ell+1):T\subseteq\{0,\dots,L-1\}\Big\}=\Big\{0,1,\dots,\tfrac{L(L+1)}2\Big\}
    Induction on LL: the subset sums of {1,…,L−1}\{1,\dots,L-1\} fill [0,(L−1)L2][0,\frac{(L-1)L}2]; adding LL to them fills [L,L(L+1)2][L,\frac{L(L+1)}2]; the two intervals overlap because L≤(L−1)L2+1L\le\frac{(L-1)L}2+1 for every L≥1L\ge1. With signs εℓ=−1\varepsilon_\ell=-1 the negative values follow by symmetry.
  7. Step 7:
    2⋅L(L+1)2+1=L(L+1)+1≥n ⇒ {w+k:∣k∣≤L(L+1)2} mod n=Zn2\cdot\tfrac{L(L+1)}2+1=L(L+1)+1\ge n\ \Rightarrow\ \{w+k:\lvert k\rvert\le\tfrac{L(L+1)}2\}\bmod n=\mathbb Z_n
    At least nn consecutive integers meet every residue class modulo nn. For n=8n=8: L=3L=3 gives 13≥813\ge8. The smallest such LL satisfies L≤n−1L\le n-1, because L=n−1L=n-1 gives (n−1)n+1≥n(n-1)n+1\ge n.
  8. Step 8:
    S⊆T ⇒ cone(S)⊆cone(T),coneL+1(w)⊇coneL(w)S\subseteq T\ \Rightarrow\ \mathrm{cone}(S)\subseteq\mathrm{cone}(T),\qquad\mathrm{cone}_{L+1}(w)\supseteq\mathrm{cone}_L(w)
    Propagation is monotone in the initial set. Forward: the first LL layers already give coneL(w)\mathrm{cone}_L(w), and the extra layer only adds wires. Backward: processing layer LL first yields a set containing ww, from which layers L−1,…,0L-1,\dots,0 produce a superset of coneL(w)\mathrm{cone}_L(w). Hence a full cone stays full for every larger LL.

∎

The viewer above shows one layer on n=3n=3 wires with the forward cone of wire 00: after CNOT(0,1)\mathrm{CNOT}(0,1) the set is {0,1}\{0,1\}, after CNOT(1,2)\mathrm{CNOT}(1,2) it is {0,1,2}\{0,1,2\}. The sequential order of the block lets a cone travel along a chain of gates in one layer, so the lower bound is often not tight. The parity map is the matrix AA derived above. Note the difference between the two notions: the light cone of output 11 contains wire 22, although y1=x0⊕x1y_1=x_0\oplus x_1 does not depend on x2x_2 for basis inputs. For superposition inputs a CNOT also acts from target to control (in the ∣±⟩\lvert\pm\rangle basis the roles of control and target are exchanged), so with the rotations of the next layer in between, the gate-support cone is the right causal bound.

The following table gives the exact number of layers after which every light cone, forward and backward, of every wire is the full register, computed by gate-support propagation, together with the sufficient bound of the theorem.

nn22334455667788
default ranges rℓ=(ℓ mod (n−1))+1r_\ell=(\ell\bmod(n-1))+111112222222233
rℓ=1r_\ell=1 in every layer11112222222222
bound min⁡{L:L(L+1)+1≥n}\min\{L:L(L+1)+1\ge n\}11112222222233

The bound is attained for n≤8n\le8. A fixed range r=1r=1 saturates the light cones at least as fast, for n=8n=8 even one layer earlier: the chain effect of the sequential block already spreads every cone over the register after two layers. Light cones alone therefore do not explain why the range should change. What changes is which pairs of wires interact directly.

Proposition

With the default ranges every pair shares a CNOT after ⌊n/2⌋ layers

Let n≥2n\ge2 and use the default ranges. The pair of wires {i,j}\{i,j\} is the support of some CNOT among the first LL layers (with L≤n−1L\le n-1) if and only if min⁡((j−i) mod n, (i−j) mod n)≤L\min\big((j-i)\bmod n,\ (i-j)\bmod n\big)\le L. In particular every one of the (n2)\binom n2 pairs shares a CNOT after exactly ⌊n/2⌋\lfloor n/2\rfloor layers, and not earlier. With r=1r=1 in every layer, only the nn cyclically neighbouring pairs ever share a CNOT.

Proof (5 steps)
  1. Step 1:
    {i,j}={s,(s+r) mod n}  ⟺  (j−i) mod n=r or (i−j) mod n=r\{i,j\}=\{s,(s+r)\bmod n\}\iff(j-i)\bmod n=r\ \text{or}\ (i-j)\bmod n=r
    The block BrB_r contains exactly the pairs at cyclic offset rr in one of the two directions.
  2. Step 2:
    {r0,…,rL−1}={1,…,L}(L≤n−1)\{r_0,\dots,r_{L-1}\}=\{1,\dots,L\}\quad(L\le n-1)
    The default ranges are rℓ=ℓ+1r_\ell=\ell+1 for ℓ≤n−2\ell\le n-2.
  3. Step 3:
    d:=(j−i) mod n∈{1,…,n−1},(i−j) mod n=n−d:{i,j} covered  ⟺  d≤L or n−d≤Ld:=(j-i)\bmod n\in\{1,\dots,n-1\},\quad(i-j)\bmod n=n-d:\qquad\{i,j\}\ \text{covered}\iff d\le L\ \text{or}\ n-d\le L
    Combine the two previous lines. The cyclic distance of the pair is min⁡(d,n−d)≤⌊n/2⌋\min(d,n-d)\le\lfloor n/2\rfloor.
  4. Step 4:
    all pairs covered  ⟺  max⁡1≤d≤n−1min⁡(d,n−d)≤L  ⟺  ⌊n2⌋≤L\text{all pairs covered}\iff\max_{1\le d\le n-1}\min(d,n-d)\le L\iff\big\lfloor\tfrac n2\big\rfloor\le L
    The largest cyclic distance is ⌊n/2⌋\lfloor n/2\rfloor, attained at d=⌊n/2⌋d=\lfloor n/2\rfloor. Also ⌊n/2⌋≤n−1\lfloor n/2\rfloor\le n-1, so the assumption L≤n−1L\le n-1 is satisfied at L=⌊n/2⌋L=\lfloor n/2\rfloor.
  5. Step 5:
    rℓ≡1: {s,s+1} only ⇒ {i,j} with min⁡(d,n−d)≥2 never coveredr_\ell\equiv1:\ \{s,s+1\}\ \text{only}\ \Rightarrow\ \{i,j\}\ \text{with}\ \min(d,n-d)\ge2\ \text{never covered}
    With a fixed range the same nn edges repeat in every layer. Distant wires then interact only indirectly, through chains of gates that are interleaved with rotations.

∎

The first viewer uses the defaults: n=4n=4 wires, L=3L=3 layers with ranges 1,2,31,2,3 and the backward cone of wire 00, the inputs that can influence a measurement of Z0Z_0. The second shows n=8n=8 wires and three layers with ranges 1,2,31,2,3, the smallest depth at which the bound of the theorem guarantees a full cone, for wire 33. The CNOT pattern drawn by the viewer shows which pairs are joined directly: the ranges 1,2,31,2,3 couple all pairs at cyclic distance at most 33, whereas r=(1,1,1)r=(1,1,1) would repeat the same eight neighbouring pairs in every layer.

Quick check

With n=8n=8 wires and the default ranges, after how many layers has every pair of wires shared at least one CNOT?

tolerance ±0.5

Circuit-centric classifiers#

Schuld, Bocharov, Svore and Wiebe (2020) proposed a variational classifier whose design principles are visible in the strongly entangling template. Its structure, in the notation of this course, is as follows.

  1. Encoding. An input x∈RNx\in\mathbb R^N is padded and normalised and loaded by amplitude encoding, ∣φ(x)⟩=∑kxk∥x∥∣k⟩\lvert\varphi(x)\rangle=\sum_{k}\frac{x_k}{\lVert x\rVert}\lvert k\rangle, on n=⌈log⁡2N⌉n=\lceil\log_2N\rceil qubits; nonlinear feature maps can be applied before the encoding.
  2. Model circuit. Uθ=BL⋯B1U_\theta=B_L\cdots B_1 is a product of code blocks. Each code block applies a general single-qubit gate with three angles to every qubit and then a cycle of controlled single-qubit gates in which qubit jj is coupled to qubit (j+r) mod n(j+r)\bmod n, with a range rr chosen per block.
  3. Readout. The first qubit is measured: π(x;θ)=Pr⁡(q0=1)=⟨φ(x)∣Uθ†(∣1⟩⟨1∣⊗I)Uθ∣φ(x)⟩\pi(x;\theta)=\Pr(q_0=1)=\langle\varphi(x)\rvert U_\theta^\dagger\big(\lvert1\rangle\langle1\rvert\otimes I\big)U_\theta\lvert\varphi(x)\rangle.
  4. Decision. A trainable bias bb gives f(x;θ,b)=π(x;θ)+bf(x;\theta,b)=\pi(x;\theta)+b, and the predicted class is 11 if f>12f>\tfrac12 and 00 otherwise.

PennyLane's StronglyEntanglingLayers keeps the general rotations and the cyclic layout with a per-layer range, and replaces the trainable controlled gates by fixed CNOTs, so that all parameters sit in the Rot\mathrm{Rot} gates and the circuit uses only one kind of two-qubit gate.

Derivation

Readout probability, decision rule and parameter count

  1. Step 1:
    ∣1⟩⟨1∣=12(1001)−12(100−1)=12(I−Z)\lvert1\rangle\langle1\rvert=\tfrac12\begin{pmatrix}1&0\\0&1\end{pmatrix}-\tfrac12\begin{pmatrix}1&0\\0&-1\end{pmatrix}=\tfrac12(I-Z)
    The projector onto ∣1⟩\lvert1\rangle written in the Pauli basis.
  2. Step 2:
    π(x;θ)=12(1−⟨Z0⟩x,θ),⟨Z0⟩x,θ=⟨φ(x)∣Uθ†Z0Uθ∣φ(x)⟩\pi(x;\theta)=\tfrac12\big(1-\langle Z_0\rangle_{x,\theta}\big),\qquad\langle Z_0\rangle_{x,\theta}=\langle\varphi(x)\rvert U_\theta^\dagger Z_0U_\theta\lvert\varphi(x)\rangle
    Linearity of the expectation and ⟨ψ∣I∣ψ⟩=1\langle\psi\vert I\vert\psi\rangle=1 for a normalised state. The classifier is a variational model with observable H=Z0H=Z_0 in the sense of the lesson on variational circuit architecture.
  3. Step 3:
    f>12  ⟺  π+b>12  ⟺  ⟨Z0⟩x,θ<2bf>\tfrac12\iff\pi+b>\tfrac12\iff\langle Z_0\rangle_{x,\theta}<2b
    Substitute π\pi and rearrange. The bias moves the decision threshold of the expectation value away from 00.
  4. Step 4:
    #θ=L⋅n⋅(3+3)=6nL=6L⌈log⁡2N⌉\#\theta=L\cdot n\cdot(3+3)=6nL=6L\lceil\log_2N\rceil
    Count for code blocks with nn general single-qubit gates and nn controlled single-qubit gates, when every one of these 2n2n gates is parametrised by three angles.
  5. Step 5:
    #wSEL=3nL=3L⌈log⁡2N⌉\#w_{\mathrm{SEL}}=3nL=3L\lceil\log_2N\rceil
    With fixed CNOTs only the Rot\mathrm{Rot} angles remain. Either way the number of parameters grows logarithmically with the input dimension NN, which is the central resource argument of the circuit-centric design; the price is the amplitude-encoding state preparation, whose gate count is studied in Stage 3.

The TypeScript cell builds the circuit of this lesson by hand, compares it with the platform's builder stronglyEntanglingLayersOps, prints its resources and output distribution, and checks the F2\mathbb F_2 matrices of the r=1r=1 and r=2r=2 blocks against simulated basis states.

TypeScriptrunnable
import { circuitUnitary, matrix, runStatevector } from '@/lib/quantum-simulator';
import { stronglyEntanglingLayersOps } from '@/lib/qml';

type Op = { kind: 'gate'; gate: 'X' | 'RZ' | 'RY' | 'CNOT'; targets: number[]; params?: number[] };
const circ = (n: number, ops: Op[]) => ({ version: 1 as const, numQubits: n, numClbits: 0, ops });

// Strongly entangling layers: Rot = RZ(phi), RY(theta), RZ(omega) on every wire, then CNOT(i, (i + r_l) mod n).
function sel(weights: number[][][], n: number): Op[] {
  const ops: Op[] = [];
  weights.forEach((layer, l) => {
    layer.forEach(([phi, theta, omega], i) => {
      ops.push({ kind: 'gate', gate: 'RZ', targets: [i], params: [phi] });
      ops.push({ kind: 'gate', gate: 'RY', targets: [i], params: [theta] });
      ops.push({ kind: 'gate', gate: 'RZ', targets: [i], params: [omega] });
    });
    if (n > 1) {
      const r = (l % (n - 1)) + 1;
      for (let i = 0; i < n; i++) ops.push({ kind: 'gate', gate: 'CNOT', targets: [i, (i + r) % n] });
    }
  });
  return ops;
}

// (1) The 3-qubit, 2-layer circuit of the lesson against the engine builder.
const W = [
  [[0.3, 1.2, -0.4], [0.8, -0.5, 1.1], [-1.0, 0.7, 0.2]],
  [[0.5, -1.3, 0.9], [-0.2, 0.4, -0.7], [1.4, 0.6, -1.1]],
];
const ops = sel(W, 3);
const U = circuitUnitary(circ(3, ops));
const V = circuitUnitary(circ(3, stronglyEntanglingLayersOps(W, 3) as Op[]));
const cnots = ops.filter((o) => o.gate === 'CNOT');
console.log('rotations = ' + (ops.length - cnots.length) + ' (3nL = 18), CNOTs = ' + cnots.length + ' (nL = 6)');
console.log('CNOT pairs: ' + cnots.map((o) => '(' + o.targets.join(',') + ')').join(' '));
console.log('max |U - U_engine| = ' + matrix.maxAbsDiff(U, V));
const p = runStatevector(circ(3, ops)).probabilities();
console.log('P(x) = ' + Array.from(p, (v) => v.toFixed(4)).join(' '));

// (2) One CNOT block on basis labels: the F2 matrix A (y = A x mod 2) against simulated basis states.
function f2Block(n: number, r: number): number[][] {
  let A = Array.from({ length: n }, (_, i) => Array.from({ length: n }, (_, j) => (i === j ? 1 : 0)));
  for (let i = 0; i < n; i++) {
    const t = (i + r) % n;
    A = A.map((row, k) => (k === t ? row.map((v, j) => v ^ A[i][j]) : row)); // CNOT(i, t): row t += row i
  }
  return A;
}
for (const r of [1, 2]) {
  const A = f2Block(3, r);
  const image: number[] = [];
  let agree = true;
  for (let x = 0; x < 8; x++) {
    const bits = [0, 1, 2].map((q) => (x >> (2 - q)) & 1);
    const prep: Op[] = [];
    bits.forEach((b, q) => { if (b) prep.push({ kind: 'gate', gate: 'X', targets: [q] }); });
    const block: Op[] = [0, 1, 2].map((i) => ({ kind: 'gate', gate: 'CNOT', targets: [i, (i + r) % 3] }));
    const probs = runStatevector(circ(3, [...prep, ...block])).probabilities();
    const y = A.map((row) => row.reduce((s, a, j) => s ^ (a & bits[j]), 0));
    const label = y.reduce((s, b) => 2 * s + b, 0);
    image.push(label);
    agree = agree && Math.abs(probs[label] - 1) < 1e-12;
  }
  console.log('n = 3, r = ' + r + ': A = ' + JSON.stringify(A) + ', x -> Ax: [' + image.join(', ') + '], simulation agrees: ' + agree);
}

Expected output

rotations = 18 (3nL = 18), CNOTs = 6 (nL = 6)
CNOT pairs: (0,1) (1,2) (2,0) (0,2) (1,0) (2,1)
max |U - U_engine| = 0
P(x) = 0.3160 0.0181 0.0483 0.0025 0.1148 0.2338 0.0233 0.2431
n = 3, r = 1: A = [[0,1,1],[1,1,0],[1,1,1]], x -> Ax: [0, 5, 7, 2, 3, 6, 4, 1], simulation agrees: true
n = 3, r = 2: A = [[1,1,0],[1,1,1],[1,0,1]], x -> Ax: [0, 3, 6, 5, 7, 4, 1, 2], simulation agrees: true

The NumPy cell checks the ZYZ theorem on 10001000 Haar-random unitaries, the explicit matrix of Rot\mathrm{Rot}, the two 33-qubit F2\mathbb F_2 matrices and their inverses (Gauss–Jordan elimination over F2\mathbb F_2), the range-11 formula for n≤8n\le8 and the pair-coverage depth ⌊n/2⌋\lfloor n/2\rfloor.

Pythonrunnable
import numpy as np

def rz(a):
    return np.diag([np.exp(-0.5j * a), np.exp(0.5j * a)])

def ry(a):
    c, s = np.cos(a / 2), np.sin(a / 2)
    return np.array([[c, -s], [s, c]], dtype=complex)

def rot(phi, theta, omega):  # Rot(phi, theta, omega) = R_Z(omega) R_Y(theta) R_Z(phi)
    return rz(omega) @ ry(theta) @ rz(phi)

# (1) ZYZ: U = e^{i alpha} R_Z(beta) R_Y(gamma) R_Z(delta) for Haar-random U in U(2).
def zyz(U):
    alpha = np.angle(np.linalg.det(U)) / 2
    V = np.exp(-1j * alpha) * U                       # det V = 1
    p, q = V[0, 0], V[1, 0]
    gamma = 2 * np.arctan2(abs(q), abs(p))
    lam, kap = np.angle(p), np.angle(q)
    return alpha, kap - lam, gamma, -kap - lam

rng = np.random.default_rng(45)
worst, form = 0.0, 0.0
for _ in range(1000):
    Q, R = np.linalg.qr(rng.standard_normal((2, 2)) + 1j * rng.standard_normal((2, 2)))
    U = Q @ np.diag(np.diag(R) / abs(np.diag(R)))
    a, b, g, d = zyz(U)
    worst = max(worst, abs(np.exp(1j * a) * rz(b) @ ry(g) @ rz(d) - U).max())
    phi, theta, omega = rng.uniform(-np.pi, np.pi, 3)
    c, s = np.cos(theta / 2), np.sin(theta / 2)
    M = np.array([[np.exp(-0.5j * (phi + omega)) * c, -np.exp(0.5j * (phi - omega)) * s],
                  [np.exp(-0.5j * (phi - omega)) * s, np.exp(0.5j * (phi + omega)) * c]])
    form = max(form, abs(M - rot(phi, theta, omega)).max())
print("ZYZ reconstruction of 1000 Haar-random U(2), max error < 1e-12:", worst < 1e-12)
print("explicit Rot matrix = R_Z(omega) R_Y(theta) R_Z(phi), max error < 1e-14:", form < 1e-14)

# (2) One CNOT block as an F2-linear map: CNOT(c, t) is the row operation row_t += row_c (mod 2).
def block(n, r):
    A = np.eye(n, dtype=int)
    for i in range(n):
        E = np.eye(n, dtype=int)
        E[(i + r) % n, i] = 1
        A = E @ A % 2
    return A

def inverse_f2(A):
    n = len(A)
    M = np.concatenate([A % 2, np.eye(n, dtype=int)], axis=1)
    for col in range(n):
        piv = next(k for k in range(col, n) if M[k, col])
        M[[col, piv]] = M[[piv, col]]
        for k in range(n):
            if k != col and M[k, col]:
                M[k] = (M[k] + M[col]) % 2
    return M[:, n:]

for n, r in [(3, 1), (3, 2)]:
    A = block(n, r)
    Ai = inverse_f2(A)
    print(f"n={n} r={r}: A={A.tolist()} A^-1={Ai.tolist()} A A^-1 = I: {np.array_equal(A @ Ai % 2, np.eye(n, dtype=int))}")

# (3) r = 1: y_0 = x_1 + ... + x_{n-1}, y_k = x_0 + ... + x_k (k >= 1), so every pair of wires is coupled.
for n in range(2, 9):
    A = block(n, 1)
    pred = np.array([[int(j >= 1) for j in range(n)]] + [[int(j <= k) for j in range(n)] for k in range(1, n)])
    coupled = all(A[i, j] or A[j, i] for i in range(n) for j in range(n) if i != j)
    print(f"n={n}: prefix/suffix formula {np.array_equal(A, pred)}, all pairs coupled {coupled}")

# (4) Pairs {i, j} that share a CNOT after L layers with the default ranges r_l = (l mod (n-1)) + 1.
for n in range(2, 9):
    full = next(L for L in range(1, n + 1)
                if len({frozenset((i, (i + (l % (n - 1)) + 1) % n)) for l in range(L) for i in range(n)}) == n * (n - 1) // 2)
    print(f"n={n}: every pair shares a CNOT after {full} layer(s) (floor(n/2) = {n // 2})")

Expected output

ZYZ reconstruction of 1000 Haar-random U(2), max error < 1e-12: True
explicit Rot matrix = R_Z(omega) R_Y(theta) R_Z(phi), max error < 1e-14: True
n=3 r=1: A=[[0, 1, 1], [1, 1, 0], [1, 1, 1]] A^-1=[[1, 0, 1], [1, 1, 1], [0, 1, 1]] A A^-1 = I: True
n=3 r=2: A=[[1, 1, 0], [1, 1, 1], [1, 0, 1]] A^-1=[[1, 1, 1], [0, 1, 1], [1, 1, 0]] A A^-1 = I: True
n=2: prefix/suffix formula True, all pairs coupled True
n=3: prefix/suffix formula True, all pairs coupled True
n=4: prefix/suffix formula True, all pairs coupled True
n=5: prefix/suffix formula True, all pairs coupled True
n=6: prefix/suffix formula True, all pairs coupled True
n=7: prefix/suffix formula True, all pairs coupled True
n=8: prefix/suffix formula True, all pairs coupled True
n=2: every pair shares a CNOT after 1 layer(s) (floor(n/2) = 1)
n=3: every pair shares a CNOT after 1 layer(s) (floor(n/2) = 1)
n=4: every pair shares a CNOT after 2 layer(s) (floor(n/2) = 2)
n=5: every pair shares a CNOT after 2 layer(s) (floor(n/2) = 2)
n=6: every pair shares a CNOT after 3 layer(s) (floor(n/2) = 3)
n=7: every pair shares a CNOT after 3 layer(s) (floor(n/2) = 3)
n=8: every pair shares a CNOT after 4 layer(s) (floor(n/2) = 4)

References

  1. M. Schuld, A. Bocharov, K. M. Svore and N. Wiebe, Circuit-centric quantum classifiers, Physical Review A 101, 032308 (2020).doi:10.1103/PhysRevA.101.032308
  2. PennyLane documentation, qml.StronglyEntanglingLayers (template reference, ranges and imprimitive gates).docs.pennylane.ai
  3. M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th anniversary edition, Cambridge University Press (2010), Theorem 4.1 (Z–Y decomposition for a single qubit).doi:10.1017/CBO9780511976667
  4. V. Bergholm et al., PennyLane: Automatic differentiation of hybrid quantum-classical computations, arXiv:1811.04968 (2018).arxiv.org
  5. S. Sim, P. D. Johnson and A. Aspuru-Guzik, Expressibility and entangling capability of parameterized quantum circuits for hybrid quantum-classical algorithms, Advanced Quantum Technologies 2, 1900070 (2019).doi:10.1002/qute.201900070

Hands-on labs

  • Build strongly entangling layers

    1 step · auto-graded

    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}.

    Open lab