QuantumCore

Lesson 37 · 80 min · core

Angle & Phase Encoding

Loading progress…

Angle encoding writes each real feature xjx_j into the rotation angle of one qubit, ∣ϕ(x)⟩=⨂jRY(xj)∣0⟩\lvert\phi(x)\rangle=\bigotimes_jR_Y(x_j)\lvert0\rangle, so that ⟨Zj⟩=cos⁡xj\langle Z_j\rangle=\cos x_j and ⟨Xj⟩=sin⁡xj\langle X_j\rangle=\sin x_j. This lesson derives these expectation values by explicit matrix algebra for RYR_Y and RXR_X encodings, the Bloch vector of dense angle encoding (two features per qubit) and of phase encoding (HH then P(xj)P(x_j)), and the product kernel k(x,x′)=∏jcos⁡2xj−xj′2k(x,x')=\prod_j\cos^2\frac{x_j-x'_j}2. It then proves the Fourier-series view of Schuld, Sweke and Meyer: a model whose data enters through Pauli rotations re-uploaded LL times is a real trigonometric polynomial with frequencies {−L,…,L}\{-L,\dots,L\}, which explains why data re-uploading is the route to richer models.

Prerequisites: Basis Encoding, Rotation Gates & ZYZ Euler Decomposition

Objectives and key results
  • Encode x∈Rnx\in\mathbb R^n with one RYR_Y (or RXR_X) per qubit and derive ⟨Zj⟩=cos⁡xj\langle Z_j\rangle=\cos x_j, ⟨Xj⟩=sin⁡xj\langle X_j\rangle=\sin x_j, ⟨Yj⟩=0\langle Y_j\rangle=0 (and ⟨Z⟩=cos⁡x\langle Z\rangle=\cos x, ⟨Y⟩=−sin⁡x\langle Y\rangle=-\sin x, ⟨X⟩=0\langle X\rangle=0 for RXR_X) by explicit matrix algebra.

  • Encode two features per qubit with RZ(x2j+1)RY(x2j)R_Z(x_{2j+1})R_Y(x_{2j}) and derive the Bloch vector (sin⁡x2jcos⁡x2j+1, sin⁡x2jsin⁡x2j+1, cos⁡x2j)(\sin x_{2j}\cos x_{2j+1},\ \sin x_{2j}\sin x_{2j+1},\ \cos x_{2j}).

  • Derive the state, Bloch vector and expectation values of phase encoding P(xj)H∣0⟩P(x_j)H\lvert0\rangle.

  • Prove that product RXR_X, RYR_Y and phase encodings induce the kernel k(x,x′)=∏jcos⁡2xj−xj′2k(x,x')=\prod_j\cos^2\frac{x_j-x'_j}2, and explain its periodicity and its data-scaling bandwidth.

  • Prove that a model with LL re-uploaded Pauli encodings is a real Fourier series f(x)=∑ω=−LLcωeiωxf(x)=\sum_{\omega=-L}^{L}c_\omega e^{i\omega x} with c−ω=cω‾c_{-\omega}=\overline{c_\omega}, and use it to explain data re-uploading.

definition · Angle encoding
∣ϕ(x)⟩=⨂j=0n−1RY(xj)∣0⟩=⨂j=0n−1(cos⁡xj2∣0⟩+sin⁡xj2∣1⟩),⟨Zj⟩=cos⁡xj,  ⟨Xj⟩=sin⁡xj,  ⟨Yj⟩=0\lvert\phi(x)\rangle=\bigotimes_{j=0}^{n-1}R_Y(x_j)\lvert0\rangle=\bigotimes_{j=0}^{n-1}\Big(\cos\tfrac{x_j}2\lvert0\rangle+\sin\tfrac{x_j}2\lvert1\rangle\Big),\qquad\langle Z_j\rangle=\cos x_j,\ \ \langle X_j\rangle=\sin x_j,\ \ \langle Y_j\rangle=0
formula · Dense angle encoding
RZ(b)RY(a)∣0⟩=e−ib/2(cos⁡a2∣0⟩+eibsin⁡a2∣1⟩),r⃗=(sin⁡acos⁡b, sin⁡asin⁡b, cos⁡a)R_Z(b)R_Y(a)\lvert0\rangle=e^{-ib/2}\Big(\cos\tfrac a2\lvert0\rangle+e^{ib}\sin\tfrac a2\lvert1\rangle\Big),\qquad\vec r=(\sin a\cos b,\ \sin a\sin b,\ \cos a)
formula · Phase encoding
P(x)H∣0⟩=12(∣0⟩+eix∣1⟩),r⃗=(cos⁡x, sin⁡x, 0)P(x)H\lvert0\rangle=\tfrac1{\sqrt2}\big(\lvert0\rangle+e^{ix}\lvert1\rangle\big),\qquad\vec r=(\cos x,\ \sin x,\ 0)
theorem · Product angle kernel
k(x,x′)=∣⟨ϕ(x′)∣ϕ(x)⟩∣2=∏j=0n−1cos⁡2xj−xj′2,k=1  ⟺  xj≡xj′ (mod 2π) ∀jk(x,x')=\lvert\langle\phi(x')\vert\phi(x)\rangle\rvert^2=\prod_{j=0}^{n-1}\cos^2\frac{x_j-x'_j}{2},\qquad k=1\iff x_j\equiv x'_j\ (\mathrm{mod}\ 2\pi)\ \forall j
theorem · Fourier spectrum of re-uploading models
f(x)=∑ω∈Ωcωeiωx,Ω={Λk−Λj},G=σ2, L uploads⇒Ω={−L,…,L},c−ω=cω‾f(x)=\sum_{\omega\in\Omega}c_\omega e^{i\omega x},\quad\Omega=\{\Lambda_{\mathbf k}-\Lambda_{\mathbf j}\},\quad G=\tfrac\sigma2,\ L\ \text{uploads}\Rightarrow\Omega=\{-L,\dots,L\},\quad c_{-\omega}=\overline{c_\omega}

Angle encoding with single-qubit rotations#

Basis encoding (previous lesson) turns a bit string into a computational basis state, and its kernel δxx′\delta_{xx'} cannot relate two different inputs. Real-valued features call for an encoding that depends continuously on the data. The simplest one uses the feature itself as a rotation angle: feature xjx_j rotates qubit jj, so nn features occupy nn qubits, the circuit has nn single-qubit gates and depth 11, and nearby inputs give nearby states. This angle encoding (also called qubit encoding or rotation encoding) is the first layer of most variational classifiers and quantum-kernel models.

Definition

Angle encoding

Let x=(x0,…,xn−1)∈Rnx=(x_0,\dots,x_{n-1})\in\mathbb R^n. The RYR_Y angle encoding of xx is the nn-qubit product state ∣ϕ(x)⟩:=⨂j=0n−1RY(xj)∣0⟩=RY(x0)∣0⟩⊗⋯⊗RY(xn−1)∣0⟩,\lvert\phi(x)\rangle:=\bigotimes_{j=0}^{n-1}R_Y(x_j)\lvert0\rangle=R_Y(x_0)\lvert0\rangle\otimes\cdots\otimes R_Y(x_{n-1})\lvert0\rangle, prepared from ∣0n⟩\lvert0^n\rangle by the depth-one circuit U(x)=⨂jRY(xj)U(x)=\bigotimes_jR_Y(x_j). Replacing RYR_Y by RXR_X gives the RXR_X angle encoding. Both use nn qubits and nn single-qubit gates, and no entangling gate.

Lemma

Pauli expectation values of a qubit from its amplitudes

Let ∣ψ⟩=α∣0⟩+β∣1⟩\lvert\psi\rangle=\alpha\lvert0\rangle+\beta\lvert1\rangle with ∣α∣2+∣β∣2=1\lvert\alpha\rvert^2+\lvert\beta\rvert^2=1. Then ⟨X⟩=2 Re(αˉβ)\langle X\rangle=2\,\mathrm{Re}(\bar\alpha\beta), ⟨Y⟩=2 Im(αˉβ)\langle Y\rangle=2\,\mathrm{Im}(\bar\alpha\beta) and ⟨Z⟩=∣α∣2−∣β∣2\langle Z\rangle=\lvert\alpha\rvert^2-\lvert\beta\rvert^2, and the Bloch vector r⃗=(⟨X⟩,⟨Y⟩,⟨Z⟩)\vec r=(\langle X\rangle,\langle Y\rangle,\langle Z\rangle) has length 11.

Proof (6 steps)
  1. Step 1:
    X∣ψ⟩=(0110)(αβ)=(βα),⟨ψ∣X∣ψ⟩=αˉβ+βˉα=αˉβ+αˉβ‾=2 Re(αˉβ)X\lvert\psi\rangle=\begin{pmatrix}0&1\\1&0\end{pmatrix}\begin{pmatrix}\alpha\\\beta\end{pmatrix}=\begin{pmatrix}\beta\\\alpha\end{pmatrix},\qquad\langle\psi\vert X\vert\psi\rangle=\bar\alpha\beta+\bar\beta\alpha=\bar\alpha\beta+\overline{\bar\alpha\beta}=2\,\mathrm{Re}(\bar\alpha\beta)
    XX swaps the two amplitudes; the inner product with ⟨ψ∣=(αˉ,βˉ)\langle\psi\rvert=(\bar\alpha,\bar\beta) is a number plus its complex conjugate.
  2. Step 2:
    Y∣ψ⟩=(0−ii0)(αβ)=(−iβiα),⟨ψ∣Y∣ψ⟩=−iαˉβ+iβˉα=−i(αˉβ−αˉβ‾)Y\lvert\psi\rangle=\begin{pmatrix}0&-i\\i&0\end{pmatrix}\begin{pmatrix}\alpha\\\beta\end{pmatrix}=\begin{pmatrix}-i\beta\\i\alpha\end{pmatrix},\qquad\langle\psi\vert Y\vert\psi\rangle=-i\bar\alpha\beta+i\bar\beta\alpha=-i\big(\bar\alpha\beta-\overline{\bar\alpha\beta}\big)
    Matrix–vector product with YY, then the inner product with (αˉ,βˉ)(\bar\alpha,\bar\beta).
  3. Step 3:
    w−wˉ=2i Im w ⇒ ⟨Y⟩=−i⋅2i Im(αˉβ)=2 Im(αˉβ)w-\bar w=2i\,\mathrm{Im}\,w\ \Rightarrow\ \langle Y\rangle=-i\cdot2i\,\mathrm{Im}(\bar\alpha\beta)=2\,\mathrm{Im}(\bar\alpha\beta)
    For any complex ww, w−wˉ=2i Im ww-\bar w=2i\,\mathrm{Im}\,w; apply it to w=αˉβw=\bar\alpha\beta and use −i⋅2i=2-i\cdot 2i=2.
  4. Step 4:
    Z∣ψ⟩=(100−1)(αβ)=(α−β),⟨ψ∣Z∣ψ⟩=αˉα−βˉβ=∣α∣2−∣β∣2Z\lvert\psi\rangle=\begin{pmatrix}1&0\\0&-1\end{pmatrix}\begin{pmatrix}\alpha\\\beta\end{pmatrix}=\begin{pmatrix}\alpha\\-\beta\end{pmatrix},\qquad\langle\psi\vert Z\vert\psi\rangle=\bar\alpha\alpha-\bar\beta\beta=\lvert\alpha\rvert^2-\lvert\beta\rvert^2
    ZZ flips the sign of the ∣1⟩\lvert1\rangle amplitude.
  5. Step 5:
    ⟨X⟩2+⟨Y⟩2=4∣αˉβ∣2=4∣α∣2∣β∣2\langle X\rangle^2+\langle Y\rangle^2=4\lvert\bar\alpha\beta\rvert^2=4\lvert\alpha\rvert^2\lvert\beta\rvert^2
    (2 Re w)2+(2 Im w)2=4∣w∣2(2\,\mathrm{Re}\,w)^2+(2\,\mathrm{Im}\,w)^2=4\lvert w\rvert^2.
  6. Step 6:
    ∥r⃗∥2=4∣α∣2∣β∣2+(∣α∣2−∣β∣2)2=(∣α∣2+∣β∣2)2=1\lVert\vec r\rVert^2=4\lvert\alpha\rvert^2\lvert\beta\rvert^2+\big(\lvert\alpha\rvert^2-\lvert\beta\rvert^2\big)^2=\big(\lvert\alpha\rvert^2+\lvert\beta\rvert^2\big)^2=1
    The identity 4ab+(a−b)2=(a+b)24ab+(a-b)^2=(a+b)^2 with a=∣α∣2a=\lvert\alpha\rvert^2, b=∣β∣2b=\lvert\beta\rvert^2, and normalisation.

∎

Lemma

Local observables on product states

If ∣Ψ⟩=∣φ0⟩⊗⋯⊗∣φn−1⟩\lvert\Psi\rangle=\lvert\varphi_0\rangle\otimes\cdots\otimes\lvert\varphi_{n-1}\rangle with normalised factors and PjP_j is a single-qubit operator PP on qubit jj (identity elsewhere), then ⟨Ψ∣Pj∣Ψ⟩=⟨φj∣P∣φj⟩\langle\Psi\vert P_j\vert\Psi\rangle=\langle\varphi_j\vert P\vert\varphi_j\rangle.

Proof (3 steps)
  1. Step 1:
    Pj=I⊗j⊗P⊗I⊗(n−1−j) ⇒ Pj∣Ψ⟩=∣φ0⟩⊗⋯⊗P∣φj⟩⊗⋯⊗∣φn−1⟩P_j=I^{\otimes j}\otimes P\otimes I^{\otimes(n-1-j)}\ \Rightarrow\ P_j\lvert\Psi\rangle=\lvert\varphi_0\rangle\otimes\cdots\otimes P\lvert\varphi_j\rangle\otimes\cdots\otimes\lvert\varphi_{n-1}\rangle
    Mixed-product rule (A⊗B)(u⊗v)=Au⊗Bv(A\otimes B)(u\otimes v)=Au\otimes Bv, factor by factor.
  2. Step 2:
    ⟨Ψ∣Pj∣Ψ⟩=∏k≠j⟨φk∣φk⟩⋅⟨φj∣P∣φj⟩\langle\Psi\vert P_j\vert\Psi\rangle=\prod_{k\ne j}\langle\varphi_k\vert\varphi_k\rangle\cdot\langle\varphi_j\vert P\vert\varphi_j\rangle
    The inner product of two product vectors is the product of the factor inner products.
  3. Step 3:
    ⟨φk∣φk⟩=1 ⇒ ⟨Ψ∣Pj∣Ψ⟩=⟨φj∣P∣φj⟩\langle\varphi_k\vert\varphi_k\rangle=1\ \Rightarrow\ \langle\Psi\vert P_j\vert\Psi\rangle=\langle\varphi_j\vert P\vert\varphi_j\rangle
    Every factor is normalised, so only the factor of qubit jj remains.

∎

Theorem

State and expectation values of R_Y angle encoding

For every x∈Rnx\in\mathbb R^n, ∣ϕ(x)⟩=⨂j=0n−1(cos⁡xj2∣0⟩+sin⁡xj2∣1⟩),\lvert\phi(x)\rangle=\bigotimes_{j=0}^{n-1}\Big(\cos\tfrac{x_j}2\lvert0\rangle+\sin\tfrac{x_j}2\lvert1\rangle\Big), and for every qubit jj: ⟨Zj⟩=cos⁡xj\langle Z_j\rangle=\cos x_j, ⟨Xj⟩=sin⁡xj\langle X_j\rangle=\sin x_j, ⟨Yj⟩=0\langle Y_j\rangle=0. The Bloch vector of qubit jj is (sin⁡xj,0,cos⁡xj)(\sin x_j,0,\cos x_j): it lies in the xzxz-plane at polar angle xjx_j.

Proof (6 steps)
  1. Step 1:
    RY(xj)∣0⟩=(cos⁡xj2−sin⁡xj2sin⁡xj2cos⁡xj2)(10)=(cos⁡xj2sin⁡xj2)=cos⁡xj2∣0⟩+sin⁡xj2∣1⟩R_Y(x_j)\lvert0\rangle=\begin{pmatrix}\cos\frac{x_j}2&-\sin\frac{x_j}2\\\sin\frac{x_j}2&\cos\frac{x_j}2\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix}=\begin{pmatrix}\cos\frac{x_j}2\\\sin\frac{x_j}2\end{pmatrix}=\cos\tfrac{x_j}2\lvert0\rangle+\sin\tfrac{x_j}2\lvert1\rangle
    A matrix applied to ∣0⟩=(1,0)T\lvert0\rangle=(1,0)^{\mathsf T} returns its first column.
  2. Step 2:
    (⨂jRY(xj))∣0⟩⊗n=⨂jRY(xj)∣0⟩\Big(\bigotimes_jR_Y(x_j)\Big)\lvert0\rangle^{\otimes n}=\bigotimes_jR_Y(x_j)\lvert0\rangle
    Mixed-product rule; this proves the product form of ∣ϕ(x)⟩\lvert\phi(x)\rangle.
  3. Step 3:
    ⟨Zj⟩=(cjsj)(100−1)(cjsj)=cj2−sj2=cos⁡xj,cj=cos⁡xj2, sj=sin⁡xj2\langle Z_j\rangle=\begin{pmatrix}c_j&s_j\end{pmatrix}\begin{pmatrix}1&0\\0&-1\end{pmatrix}\begin{pmatrix}c_j\\s_j\end{pmatrix}=c_j^2-s_j^2=\cos x_j,\qquad c_j=\cos\tfrac{x_j}2,\ s_j=\sin\tfrac{x_j}2
    By the product-state lemma only qubit jj matters; the amplitudes are real, and cos⁡2u−sin⁡2u=cos⁡2u\cos^2u-\sin^2u=\cos2u.
  4. Step 4:
    ⟨Xj⟩=(cjsj)(0110)(cjsj)=(cjsj)(sjcj)=2cjsj=sin⁡xj\langle X_j\rangle=\begin{pmatrix}c_j&s_j\end{pmatrix}\begin{pmatrix}0&1\\1&0\end{pmatrix}\begin{pmatrix}c_j\\s_j\end{pmatrix}=\begin{pmatrix}c_j&s_j\end{pmatrix}\begin{pmatrix}s_j\\c_j\end{pmatrix}=2c_js_j=\sin x_j
    Double-angle formula 2sin⁡ucos⁡u=sin⁡2u2\sin u\cos u=\sin2u.
  5. Step 5:
    ⟨Yj⟩=(cjsj)(0−ii0)(cjsj)=(cjsj)(−isjicj)=−icjsj+icjsj=0\langle Y_j\rangle=\begin{pmatrix}c_j&s_j\end{pmatrix}\begin{pmatrix}0&-i\\i&0\end{pmatrix}\begin{pmatrix}c_j\\s_j\end{pmatrix}=\begin{pmatrix}c_j&s_j\end{pmatrix}\begin{pmatrix}-is_j\\ic_j\end{pmatrix}=-ic_js_j+ic_js_j=0
    With real amplitudes αˉβ=cjsj\bar\alpha\beta=c_js_j is real, so ⟨Y⟩=2 Im(αˉβ)=0\langle Y\rangle=2\,\mathrm{Im}(\bar\alpha\beta)=0, in agreement with the lemma.
  6. Step 6:
    r⃗j=(sin⁡xj, 0, cos⁡xj)=(sin⁡θ, 0, cos⁡θ)∣θ=xj\vec r_j=(\sin x_j,\ 0,\ \cos x_j)=(\sin\theta,\ 0,\ \cos\theta)\big|_{\theta=x_j}
    Collect the three components; this is the point of the Bloch sphere with polar angle θ=xj\theta=x_j and azimuth 00 (for xj∈[0,π]x_j\in[0,\pi]).

∎

Proposition

Expectation values of R_X angle encoding

RX(x)∣0⟩=cos⁡x2∣0⟩−isin⁡x2∣1⟩R_X(x)\lvert0\rangle=\cos\tfrac x2\lvert0\rangle-i\sin\tfrac x2\lvert1\rangle, and in this state ⟨Z⟩=cos⁡x\langle Z\rangle=\cos x, ⟨Y⟩=−sin⁡x\langle Y\rangle=-\sin x, ⟨X⟩=0\langle X\rangle=0. The Bloch vector (0,−sin⁡x,cos⁡x)(0,-\sin x,\cos x) rotates in the yzyz-plane.

Proof (6 steps)
  1. Step 1:
    RX(x)∣0⟩=(cos⁡x2−isin⁡x2−isin⁡x2cos⁡x2)(10)=(c−is),c=cos⁡x2, s=sin⁡x2R_X(x)\lvert0\rangle=\begin{pmatrix}\cos\frac x2&-i\sin\frac x2\\-i\sin\frac x2&\cos\frac x2\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix}=\begin{pmatrix}c\\-is\end{pmatrix},\qquad c=\cos\tfrac x2,\ s=\sin\tfrac x2
    First column of RX(x)R_X(x).
  2. Step 2:
    ⟨ψ∣=(cˉ−is‾)=(cis)\langle\psi\rvert=\begin{pmatrix}\bar c&\overline{-is}\end{pmatrix}=\begin{pmatrix}c&is\end{pmatrix}
    Conjugate transpose; c,sc,s are real.
  3. Step 3:
    ⟨Z⟩=(cis)(cis)=c2+i2s2=c2−s2=cos⁡x\langle Z\rangle=\begin{pmatrix}c&is\end{pmatrix}\begin{pmatrix}c\\is\end{pmatrix}=c^2+i^2s^2=c^2-s^2=\cos x
    Z(c,−is)T=(c,is)TZ(c,-is)^{\mathsf T}=(c,is)^{\mathsf T}.
  4. Step 4:
    ⟨X⟩=(cis)(−isc)=−ics+ics=0\langle X\rangle=\begin{pmatrix}c&is\end{pmatrix}\begin{pmatrix}-is\\c\end{pmatrix}=-ics+ics=0
    XX swaps the amplitudes: X(c,−is)T=(−is,c)TX(c,-is)^{\mathsf T}=(-is,c)^{\mathsf T}.
  5. Step 5:
    ⟨Y⟩=(cis)(−i(−is)ic)=(cis)(−sic)=−cs+i2cs=−2cs=−sin⁡x\langle Y\rangle=\begin{pmatrix}c&is\end{pmatrix}\begin{pmatrix}-i(-is)\\ic\end{pmatrix}=\begin{pmatrix}c&is\end{pmatrix}\begin{pmatrix}-s\\ic\end{pmatrix}=-cs+i^2cs=-2cs=-\sin x
    Y(α,β)T=(−iβ,iα)TY(\alpha,\beta)^{\mathsf T}=(-i\beta,i\alpha)^{\mathsf T} with α=c\alpha=c, β=−is\beta=-is, then the double-angle formula.
  6. Step 6:
    r⃗=(0, −sin⁡x, cos⁡x)\vec r=(0,\ -\sin x,\ \cos x)
    For RXR_X the data moves the Bloch vector in the yzyz-plane, so the XX-component carries no information about xx; for RYR_Y it is the YY-component that vanishes.

∎

Derivation

Worked example: x = (0.3, 1.2)

  1. Step 1:
    c0=cos⁡0.15=0.988771,s0=sin⁡0.15=0.149438,c1=cos⁡0.6=0.825336,s1=sin⁡0.6=0.564642c_0=\cos0.15=0.988771,\quad s_0=\sin0.15=0.149438,\quad c_1=\cos0.6=0.825336,\quad s_1=\sin0.6=0.564642
    Half-angles of the two features, to six decimals.
  2. Step 2:
    ∣ϕ(x)⟩=(c0∣0⟩+s0∣1⟩)⊗(c1∣0⟩+s1∣1⟩)=c0c1∣00⟩+c0s1∣01⟩+s0c1∣10⟩+s0s1∣11⟩\lvert\phi(x)\rangle=(c_0\lvert0\rangle+s_0\lvert1\rangle)\otimes(c_1\lvert0\rangle+s_1\lvert1\rangle)=c_0c_1\lvert00\rangle+c_0s_1\lvert01\rangle+s_0c_1\lvert10\rangle+s_0s_1\lvert11\rangle
    Expand the tensor product; qubit 00 is the left symbol of each ket.
  3. Step 3:
    ∣ϕ(x)⟩=(0.816068, 0.558302, 0.123337, 0.084379)T\lvert\phi(x)\rangle=(0.816068,\ 0.558302,\ 0.123337,\ 0.084379)^{\mathsf T}
    The four real amplitudes in the order ∣00⟩,∣01⟩,∣10⟩,∣11⟩\lvert00\rangle,\lvert01\rangle,\lvert10\rangle,\lvert11\rangle; their squares sum to 11.
  4. Step 4:
    ⟨Z0⟩=cos⁡0.3=0.955336,⟨X0⟩=sin⁡0.3=0.295520,⟨Z1⟩=cos⁡1.2=0.362358,⟨X1⟩=sin⁡1.2=0.932039\langle Z_0\rangle=\cos0.3=0.955336,\quad\langle X_0\rangle=\sin0.3=0.295520,\quad\langle Z_1\rangle=\cos1.2=0.362358,\quad\langle X_1\rangle=\sin1.2=0.932039
    The theorem applied qubit by qubit; these are exactly the values the lab grader expects at its first datum.

Result

⟨Z0⟩=0.955336,  ⟨X0⟩=0.295520,  ⟨Y0⟩=0\boxed{\langle Z_0\rangle=0.955336,\ \ \langle X_0\rangle=0.295520,\ \ \langle Y_0\rangle=0}

Circuit · 2 qubits

Quantum circuit on 2 qubitsRY(0.30) on q0; RY(1.20) on q1q0q1RY(0.30)RY(1.20)

Angle encoding of x=(0.3,1.2)x=(0.3,1.2): RY(0.3)R_Y(0.3) on qubit 00 and RY(1.2)R_Y(1.2) on qubit 11, one layer, no entangling gate. The statevector shows the four real amplitudes (0.816068,0.558302,0.123337,0.084379)(0.816068,0.558302,0.123337,0.084379) derived above.

∣ψ⟩=0.8161∣00⟩+0.5583∣01⟩+0.1233∣10⟩+0.0844∣11⟩\lvert\psi\rangle = 0.8161\lvert 00\rangle + 0.5583\lvert 01\rangle + 0.1233\lvert 10\rangle + 0.0844\lvert 11\rangle

Quick check

A single feature x=π/6x=\pi/6 is encoded as RX(x)∣0⟩R_X(x)\lvert0\rangle. What is ⟨Y⟩\langle Y\rangle?

tolerance ±0.000001

Dense angle encoding: two features per qubit#

A pure qubit state has two real degrees of freedom, the polar and azimuthal angles of its Bloch vector, but angle encoding uses only one of them. Dense angle encoding (LaRose and Coyle 2020) uses both: one feature sets the polar angle with RYR_Y, the next one the azimuth with RZR_Z. This halves the number of qubits at the price of one more gate per qubit.

Definition

Dense angle encoding

For x∈R2mx\in\mathbb R^{2m} the dense angle encoding is the mm-qubit product state ∣ϕdense(x)⟩:=⨂j=0m−1RZ(x2j+1) RY(x2j)∣0⟩,\lvert\phi_{\mathrm{dense}}(x)\rangle:=\bigotimes_{j=0}^{m-1}R_Z(x_{2j+1})\,R_Y(x_{2j})\lvert0\rangle, i.e. qubit jj is first rotated by RY(x2j)R_Y(x_{2j}) and then by RZ(x2j+1)R_Z(x_{2j+1}). A vector with an odd number NN of features is padded with one zero, so ⌈N/2⌉\lceil N/2\rceil qubits and at most 2⌈N/2⌉2\lceil N/2\rceil single-qubit gates suffice.

Theorem

Bloch vector of dense angle encoding

Write a=x2ja=x_{2j} and b=x2j+1b=x_{2j+1}. Qubit jj of ∣ϕdense(x)⟩\lvert\phi_{\mathrm{dense}}(x)\rangle is RZ(b)RY(a)∣0⟩=e−ib/2(cos⁡a2∣0⟩+eibsin⁡a2∣1⟩),R_Z(b)R_Y(a)\lvert0\rangle=e^{-ib/2}\Big(\cos\tfrac a2\lvert0\rangle+e^{ib}\sin\tfrac a2\lvert1\rangle\Big), with Bloch vector r⃗j=(sin⁡acos⁡b, sin⁡asin⁡b, cos⁡a)\vec r_j=(\sin a\cos b,\ \sin a\sin b,\ \cos a): polar angle aa, azimuth bb.

Proof (7 steps)
  1. Step 1:
    RY(a)∣0⟩=cos⁡a2∣0⟩+sin⁡a2∣1⟩R_Y(a)\lvert0\rangle=\cos\tfrac a2\lvert0\rangle+\sin\tfrac a2\lvert1\rangle
    First column of RY(a)R_Y(a), as in the angle-encoding theorem.
  2. Step 2:
    RZ(b)(cos⁡a2∣0⟩+sin⁡a2∣1⟩)=(e−ib/200eib/2)(cos⁡a2sin⁡a2)=(e−ib/2cos⁡a2eib/2sin⁡a2)R_Z(b)\Big(\cos\tfrac a2\lvert0\rangle+\sin\tfrac a2\lvert1\rangle\Big)=\begin{pmatrix}e^{-ib/2}&0\\0&e^{ib/2}\end{pmatrix}\begin{pmatrix}\cos\frac a2\\\sin\frac a2\end{pmatrix}=\begin{pmatrix}e^{-ib/2}\cos\frac a2\\e^{ib/2}\sin\frac a2\end{pmatrix}
    RZ(b)R_Z(b) is diagonal and multiplies each amplitude by its phase.
  3. Step 3:
    =e−ib/2(cos⁡a2∣0⟩+eibsin⁡a2∣1⟩)=e^{-ib/2}\Big(\cos\tfrac a2\lvert0\rangle+e^{ib}\sin\tfrac a2\lvert1\rangle\Big)
    Factor out e−ib/2e^{-ib/2}; this global phase has no physical effect.
  4. Step 4:
    αˉβ=eib/2cos⁡a2⋅eib/2sin⁡a2=eibcos⁡a2sin⁡a2=12eibsin⁡a\bar\alpha\beta=e^{ib/2}\cos\tfrac a2\cdot e^{ib/2}\sin\tfrac a2=e^{ib}\cos\tfrac a2\sin\tfrac a2=\tfrac12e^{ib}\sin a
    With α=e−ib/2cos⁡a2\alpha=e^{-ib/2}\cos\frac a2 and β=eib/2sin⁡a2\beta=e^{ib/2}\sin\frac a2; αˉ=eib/2cos⁡a2\bar\alpha=e^{ib/2}\cos\frac a2 and 2sin⁡ucos⁡u=sin⁡2u2\sin u\cos u=\sin2u.
  5. Step 5:
    ⟨X⟩=2 Re(αˉβ)=sin⁡acos⁡b,⟨Y⟩=2 Im(αˉβ)=sin⁡asin⁡b\langle X\rangle=2\,\mathrm{Re}(\bar\alpha\beta)=\sin a\cos b,\qquad\langle Y\rangle=2\,\mathrm{Im}(\bar\alpha\beta)=\sin a\sin b
    Pauli-expectation lemma with eib=cos⁡b+isin⁡be^{ib}=\cos b+i\sin b.
  6. Step 6:
    ⟨Z⟩=∣α∣2−∣β∣2=cos⁡2a2−sin⁡2a2=cos⁡a\langle Z\rangle=\lvert\alpha\rvert^2-\lvert\beta\rvert^2=\cos^2\tfrac a2-\sin^2\tfrac a2=\cos a
    The phases have modulus 11, so ∣α∣=cos⁡a2\lvert\alpha\rvert=\cos\frac a2, ∣β∣=∣sin⁡a2∣\lvert\beta\rvert=\lvert\sin\frac a2\rvert.
  7. Step 7:
    r⃗j=(sin⁡acos⁡b, sin⁡asin⁡b, cos⁡a)\vec r_j=(\sin a\cos b,\ \sin a\sin b,\ \cos a)
    These are the spherical coordinates of the unit vector with polar angle aa and azimuth bb; by the product-state lemma the other qubits do not affect r⃗j\vec r_j.

∎

Proposition

Kernel of dense angle encoding

For single-qubit pure states with Bloch vectors r⃗,r⃗′\vec r,\vec r', ∣⟨ψ′∣ψ⟩∣2=12(1+r⃗⋅r⃗′)\lvert\langle\psi'\vert\psi\rangle\rvert^2=\tfrac12(1+\vec r\cdot\vec r'). Hence dense angle encoding has the kernel k(x,x′)=∏j=0m−11+r⃗j⋅r⃗j′2,r⃗j⋅r⃗j′=sin⁡ajsin⁡aj′cos⁡(bj−bj′)+cos⁡ajcos⁡aj′.k(x,x')=\prod_{j=0}^{m-1}\frac{1+\vec r_j\cdot\vec r'_j}{2},\qquad\vec r_j\cdot\vec r'_j=\sin a_j\sin a'_j\cos(b_j-b'_j)+\cos a_j\cos a'_j.

Proof (6 steps)
  1. Step 1:
    ρ=∣ψ⟩⟨ψ∣=12(I+r⃗⋅σ⃗),r⃗⋅σ⃗=rxX+ryY+rzZ\rho=\lvert\psi\rangle\langle\psi\rvert=\tfrac12\big(I+\vec r\cdot\vec\sigma\big),\qquad\vec r\cdot\vec\sigma=r_xX+r_yY+r_zZ
    Bloch representation of a pure qubit state, with rμ=Tr(ρσμ)=⟨σμ⟩r_\mu=\mathrm{Tr}(\rho\sigma_\mu)=\langle\sigma_\mu\rangle (lemma above).
  2. Step 2:
    ∣⟨ψ′∣ψ⟩∣2=⟨ψ′∣ψ⟩⟨ψ∣ψ′⟩=Tr(ρρ′)\lvert\langle\psi'\vert\psi\rangle\rvert^2=\langle\psi'\vert\psi\rangle\langle\psi\vert\psi'\rangle=\mathrm{Tr}(\rho\rho')
    Write the squared modulus as a trace of the two projectors.
  3. Step 3:
    Tr(ρρ′)=14(Tr I+∑μrμTr σμ+∑νrν′Tr σν+∑μ,νrμrν′ Tr(σμσν))\mathrm{Tr}(\rho\rho')=\tfrac14\Big(\mathrm{Tr}\,I+\sum_\mu r_\mu\mathrm{Tr}\,\sigma_\mu+\sum_\nu r'_\nu\mathrm{Tr}\,\sigma_\nu+\sum_{\mu,\nu}r_\mu r'_\nu\,\mathrm{Tr}(\sigma_\mu\sigma_\nu)\Big)
    Expand the product and use linearity of the trace.
  4. Step 4:
    Tr I=2,Tr σμ=0,Tr(σμσν)=2δμν ⇒ Tr(ρρ′)=14(2+2 r⃗⋅r⃗′)=12(1+r⃗⋅r⃗′)\mathrm{Tr}\,I=2,\quad\mathrm{Tr}\,\sigma_\mu=0,\quad\mathrm{Tr}(\sigma_\mu\sigma_\nu)=2\delta_{\mu\nu}\ \Rightarrow\ \mathrm{Tr}(\rho\rho')=\tfrac14(2+2\,\vec r\cdot\vec r')=\tfrac12(1+\vec r\cdot\vec r')
    Pauli matrices are traceless and σμσν=δμνI+i∑κϵμνκσκ\sigma_\mu\sigma_\nu=\delta_{\mu\nu}I+i\sum_\kappa\epsilon_{\mu\nu\kappa}\sigma_\kappa.
  5. Step 5:
    r⃗j⋅r⃗j′=sin⁡ajsin⁡aj′(cos⁡bjcos⁡bj′+sin⁡bjsin⁡bj′)+cos⁡ajcos⁡aj′=sin⁡ajsin⁡aj′cos⁡(bj−bj′)+cos⁡ajcos⁡aj′\vec r_j\cdot\vec r'_j=\sin a_j\sin a'_j(\cos b_j\cos b'_j+\sin b_j\sin b'_j)+\cos a_j\cos a'_j=\sin a_j\sin a'_j\cos(b_j-b'_j)+\cos a_j\cos a'_j
    Dot product of the two Bloch vectors from the theorem and cos⁡(b−b′)=cos⁡bcos⁡b′+sin⁡bsin⁡b′\cos(b-b')=\cos b\cos b'+\sin b\sin b'.
  6. Step 6:
    k(x,x′)=∏j∣⟨ϕj(x′)∣ϕj(x)⟩∣2=∏j1+r⃗j⋅r⃗j′2k(x,x')=\prod_j\lvert\langle\phi_j(x')\vert\phi_j(x)\rangle\rvert^2=\prod_j\frac{1+\vec r_j\cdot\vec r'_j}{2}
    The overlap of product states factorises over qubits; the global phases e−ibj/2e^{-ib_j/2} drop out of the modulus.

∎

Quick check

A data set has N=10N=10 real features. How many qubits does dense angle encoding need, compared with plain angle encoding?

Select one answer

Phase encoding#

A diagonal gate applied to ∣0⟩\lvert0\rangle only multiplies it by a phase, so encoding into the relative phase requires a superposition first. Phase encoding applies a Hadamard and then the phase gate P(xj)P(x_j), which places the datum in the azimuth of a Bloch vector on the equator.

Definition

Phase encoding

For x∈Rnx\in\mathbb R^n the phase encoding is ∣ϕP(x)⟩:=⨂j=0n−1P(xj)H∣0⟩,P(λ)=(100eiλ),H=12(111−1).\lvert\phi_P(x)\rangle:=\bigotimes_{j=0}^{n-1}P(x_j)H\lvert0\rangle,\qquad P(\lambda)=\begin{pmatrix}1&0\\0&e^{i\lambda}\end{pmatrix},\quad H=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}. It uses nn qubits and 2n2n single-qubit gates in depth 22.

Theorem

State, Bloch vector and expectation values of phase encoding

P(x)H∣0⟩=12(∣0⟩+eix∣1⟩)P(x)H\lvert0\rangle=\tfrac1{\sqrt2}\big(\lvert0\rangle+e^{ix}\lvert1\rangle\big), its Bloch vector is (cos⁡x,sin⁡x,0)(\cos x,\sin x,0), so ⟨X⟩=cos⁡x\langle X\rangle=\cos x, ⟨Y⟩=sin⁡x\langle Y\rangle=\sin x, ⟨Z⟩=0\langle Z\rangle=0. Moreover P(x)=eix/2RZ(x)P(x)=e^{ix/2}R_Z(x), so RZ(x)H∣0⟩R_Z(x)H\lvert0\rangle is the same physical state.

Proof (6 steps)
  1. Step 1:
    H∣0⟩=12(111−1)(10)=12(11)=∣+⟩H\lvert0\rangle=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix}=\tfrac1{\sqrt2}\begin{pmatrix}1\\1\end{pmatrix}=\lvert+\rangle
    First column of HH.
  2. Step 2:
    P(x)∣+⟩=(100eix)12(11)=12(1eix)=12(∣0⟩+eix∣1⟩)P(x)\lvert+\rangle=\begin{pmatrix}1&0\\0&e^{ix}\end{pmatrix}\tfrac1{\sqrt2}\begin{pmatrix}1\\1\end{pmatrix}=\tfrac1{\sqrt2}\begin{pmatrix}1\\e^{ix}\end{pmatrix}=\tfrac1{\sqrt2}\big(\lvert0\rangle+e^{ix}\lvert1\rangle\big)
    The phase gate multiplies the ∣1⟩\lvert1\rangle amplitude by eixe^{ix}.
  3. Step 3:
    α=12, β=eix2 ⇒ αˉβ=12eix=12(cos⁡x+isin⁡x)\alpha=\tfrac1{\sqrt2},\ \beta=\tfrac{e^{ix}}{\sqrt2}\ \Rightarrow\ \bar\alpha\beta=\tfrac12e^{ix}=\tfrac12(\cos x+i\sin x)
    Euler's formula.
  4. Step 4:
    ⟨X⟩=2 Re(αˉβ)=cos⁡x,⟨Y⟩=2 Im(αˉβ)=sin⁡x,⟨Z⟩=12−12=0\langle X\rangle=2\,\mathrm{Re}(\bar\alpha\beta)=\cos x,\quad\langle Y\rangle=2\,\mathrm{Im}(\bar\alpha\beta)=\sin x,\quad\langle Z\rangle=\tfrac12-\tfrac12=0
    Pauli-expectation lemma; both amplitudes have modulus 1/21/\sqrt2.
  5. Step 5:
    eix/2RZ(x)=eix/2(e−ix/200eix/2)=(100eix)=P(x)e^{ix/2}R_Z(x)=e^{ix/2}\begin{pmatrix}e^{-ix/2}&0\\0&e^{ix/2}\end{pmatrix}=\begin{pmatrix}1&0\\0&e^{ix}\end{pmatrix}=P(x)
    Multiply the diagonal entries of RZ(x)R_Z(x) by eix/2e^{ix/2}.
  6. Step 6:
    P(x)H∣0⟩=eix/2 RZ(x)H∣0⟩P(x)H\lvert0\rangle=e^{ix/2}\,R_Z(x)H\lvert0\rangle
    The two preparations differ by the global phase eix/2e^{ix/2}, which no measurement can detect; the platform's QML engine implements phase encoding as RZ(x)HR_Z(x)H.

∎

Circuit · 2 qubits

Quantum circuit on 2 qubitsH on q0; H on q1; P(0.30) on q0; P(1.20) on q1q0q1HHP(0.30)P(1.20)

Phase encoding of x=(0.3,1.2)x=(0.3,1.2): Hadamards create ∣++⟩\lvert{+}{+}\rangle, then P(0.3)P(0.3) and P(1.2)P(1.2) write the features into the relative phases. All four amplitudes have modulus 12\tfrac12; only their phases 0, 1.2, 0.3, 1.50,\,1.2,\,0.3,\,1.5 depend on the datum.

∣ψ⟩=12∣00⟩+(0.1812+0.466i)∣01⟩+(0.4777+0.1478i)∣10⟩+(0.0354+0.4987i)∣11⟩\lvert\psi\rangle = \tfrac{1}{2}\lvert 00\rangle + \left(0.1812 + 0.466i\right)\lvert 01\rangle + \left(0.4777 + 0.1478i\right)\lvert 10\rangle + \left(0.0354 + 0.4987i\right)\lvert 11\rangle

The kernel of a product angle encoding#

The fidelity kernel k(x,x′)=∣⟨ϕ(x′)∣ϕ(x)⟩∣2k(x,x')=\lvert\langle\phi(x')\vert\phi(x)\rangle\rvert^2 of a feature map measures how similar two encoded inputs are (it is studied in depth in the quantum-kernel module). For product encodings it can be computed in closed form, one qubit at a time.

Theorem

Product angle kernel

Let ∣ϕ(x)⟩=⨂jRP(xj)∣0⟩\lvert\phi(x)\rangle=\bigotimes_jR_P(x_j)\lvert0\rangle with P=YP=Y for every qubit, or P=XP=X for every qubit. Then for all x,x′∈Rnx,x'\in\mathbb R^n k(x,x′)=∏j=0n−1cos⁡2xj−xj′2.k(x,x')=\prod_{j=0}^{n-1}\cos^2\frac{x_j-x'_j}{2}. Each factor is 2π2\pi-periodic in δj=xj−xj′\delta_j=x_j-x'_j, 0≤k≤10\le k\le1, and k(x,x′)=1k(x,x')=1 if and only if xj≡xj′(mod2π)x_j\equiv x'_j\pmod{2\pi} for every jj. Phase encoding ⨂jP(xj)H∣0⟩\bigotimes_jP(x_j)H\lvert0\rangle has the same kernel.

Proof (8 steps)
  1. Step 1:
    ⟨ϕ(x′)∣ϕ(x)⟩=∏j=0n−1⟨0∣RP(xj′)†RP(xj)∣0⟩\langle\phi(x')\vert\phi(x)\rangle=\prod_{j=0}^{n-1}\langle0\vert R_P(x'_j)^\dagger R_P(x_j)\vert0\rangle
    The inner product of product states is the product of the single-qubit inner products, with ⟨ϕj(x′)∣=⟨0∣RP(xj′)†\langle\phi_j(x')\rvert=\langle0\rvert R_P(x'_j)^\dagger.
  2. Step 2:
    RP(a)†=(e−iaP/2)†=eiaP/2=RP(−a)R_P(a)^\dagger=\big(e^{-iaP/2}\big)^\dagger=e^{iaP/2}=R_P(-a)
    PP is Hermitian, so (e−iaP/2)†=eiaP†/2=eiaP/2(e^{-iaP/2})^\dagger=e^{i a P^\dagger/2}=e^{iaP/2}.
  3. Step 3:
    RP(a)†RP(b)=eiaP/2e−ibP/2=e−i(b−a)P/2=RP(b−a)R_P(a)^\dagger R_P(b)=e^{iaP/2}e^{-ibP/2}=e^{-i(b-a)P/2}=R_P(b-a)
    Exponentials of multiples of the same operator commute and add their exponents.
  4. Step 4:
    ⟨0∣RY(δ)∣0⟩=(10)(cos⁡δ2−sin⁡δ2sin⁡δ2cos⁡δ2)(10)=cos⁡δ2=⟨0∣RX(δ)∣0⟩\langle0\vert R_Y(\delta)\vert0\rangle=\begin{pmatrix}1&0\end{pmatrix}\begin{pmatrix}\cos\frac\delta2&-\sin\frac\delta2\\\sin\frac\delta2&\cos\frac\delta2\end{pmatrix}\begin{pmatrix}1\\0\end{pmatrix}=\cos\tfrac\delta2=\langle0\vert R_X(\delta)\vert0\rangle
    ⟨0∣M∣0⟩\langle0\rvert M\lvert0\rangle is the top-left entry, which is cos⁡δ2\cos\frac\delta2 for both RY(δ)R_Y(\delta) and RX(δ)R_X(\delta).
  5. Step 5:
    ⟨ϕ(x′)∣ϕ(x)⟩=∏jcos⁡xj−xj′2 ⇒ k(x,x′)=∏jcos⁡2xj−xj′2\langle\phi(x')\vert\phi(x)\rangle=\prod_j\cos\frac{x_j-x'_j}2\ \Rightarrow\ k(x,x')=\prod_j\cos^2\frac{x_j-x'_j}2
    Combine the previous steps with δj=xj−xj′\delta_j=x_j-x'_j and take the squared modulus of a real number.
  6. Step 6:
    cos⁡2δ2=1+cos⁡δ2 ⇒ cos⁡2δ+2π2=cos⁡2δ2\cos^2\frac{\delta}{2}=\frac{1+\cos\delta}{2}\ \Rightarrow\ \cos^2\frac{\delta+2\pi}{2}=\cos^2\frac\delta2
    Half-angle identity: each factor is a 2π2\pi-periodic function of δj\delta_j with values in [0,1][0,1], hence 0≤k≤10\le k\le1.
  7. Step 7:
    k=1  ⟺  cos⁡2δj2=1 ∀j  ⟺  cos⁡δj=1 ∀j  ⟺  δj∈2πZ ∀jk=1\iff\cos^2\tfrac{\delta_j}2=1\ \forall j\iff\cos\delta_j=1\ \forall j\iff\delta_j\in2\pi\mathbb Z\ \forall j
    A product of numbers in [0,1][0,1] equals 11 only if every factor equals 11.
  8. Step 8:
    ⟨+∣P(−xj′)P(xj)∣+⟩=12(1+eiδj),∣12(1+eiδj)∣2=2+2cos⁡δj4=cos⁡2δj2\langle+\vert P(-x'_j)P(x_j)\vert+\rangle=\tfrac12\big(1+e^{i\delta_j}\big),\qquad\Big\lvert\tfrac12\big(1+e^{i\delta_j}\big)\Big\rvert^2=\frac{2+2\cos\delta_j}{4}=\cos^2\frac{\delta_j}2
    Phase encoding: P(x′)†=P(−x′)P(x')^\dagger=P(-x') and P(−x′)P(x)=diag(1,eiδ)P(-x')P(x)=\mathrm{diag}(1,e^{i\delta}), so the per-qubit overlap is 12(1+eiδ)\frac12(1+e^{i\delta}); then ∣1+eiδ∣2=2+2cos⁡δ\lvert1+e^{i\delta}\rvert^2=2+2\cos\delta.

∎

Derivation

Data scaling sets the kernel bandwidth

  1. Step 1:
    x↦s x ⇒ ks(x,x′)=∏jcos⁡2s δj2,δ=x−x′x\mapsto s\,x\ \Rightarrow\ k_s(x,x')=\prod_j\cos^2\frac{s\,\delta_j}{2},\qquad\delta=x-x'
    Encoding the rescaled features sxjsx_j with s>0s>0 (this is the scale option of the angle feature map) multiplies every angle difference by ss.
  2. Step 2:
    ln⁡cos⁡u=−u22−u412+O(u6)\ln\cos u=-\frac{u^2}2-\frac{u^4}{12}+O(u^6)
    From cos⁡u=1−u22+u424+O(u6)\cos u=1-\frac{u^2}2+\frac{u^4}{24}+O(u^6) and ln⁡(1+y)=y−y22+O(y3)\ln(1+y)=y-\frac{y^2}2+O(y^3) with y=−u22+u424y=-\frac{u^2}2+\frac{u^4}{24}: −u22+u424−u48=−u22−u412-\frac{u^2}2+\frac{u^4}{24}-\frac{u^4}8=-\frac{u^2}2-\frac{u^4}{12}.
  3. Step 3:
    ln⁡ks=2∑jln⁡cos⁡sδj2=−s24∥δ∥2−s496∑jδj4+O(s6∥δ∥6)\ln k_s=2\sum_j\ln\cos\frac{s\delta_j}2=-\frac{s^2}{4}\lVert\delta\rVert^2-\frac{s^4}{96}\sum_j\delta_j^4+O(s^6\lVert\delta\rVert^6)
    Insert u=sδj/2u=s\delta_j/2: 2⋅u22=s2δj242\cdot\frac{u^2}{2}=\frac{s^2\delta_j^2}{4} and 2⋅u412=s4δj4962\cdot\frac{u^4}{12}=\frac{s^4\delta_j^4}{96}; sum over jj.
  4. Step 4:
    ks(x,x′)≈exp⁡(−s24∥x−x′∥2)(s∥x−x′∥≪1)k_s(x,x')\approx\exp\Big(-\frac{s^2}{4}\lVert x-x'\rVert^2\Big)\qquad(s\lVert x-x'\rVert\ll1)
    Locally the angle kernel is a Gaussian (RBF) kernel with γ=s2/4\gamma=s^2/4.
  5. Step 5:
    s→0: K→11T (every input looks the same),s large: cos⁡2sδj2=12(1+cos⁡sδj) averages to 12 ⇒ Kab∼2−n (a≠b)s\to0:\ K\to\mathbf 1\mathbf 1^{\mathsf T}\ \text{(every input looks the same)},\qquad s\ \text{large}:\ \cos^2\tfrac{s\delta_j}{2}=\tfrac12\big(1+\cos s\delta_j\big)\ \text{averages to}\ \tfrac12\ \Rightarrow\ K_{ab}\sim2^{-n}\ (a\ne b)
    For s→0s\to0 every factor tends to cos⁡20=1\cos^20=1, so the kernel flattens to 11. For large ss the first zero ∣δj∣=π/s\lvert\delta_j\rvert=\pi/s of each factor moves toward 00 and the factor oscillates many times across the range of the data, so it no longer decreases with distance; over differences spread across many periods its mean is 12\frac12, and off-diagonal entries are typically of order 2−n2^{-n}. With many qubits distinct training points are then nearly orthogonal, K≈IK\approx I (memorisation, as in basis encoding), and the kernel has lost its notion of locality. Because each factor is 2π/s2\pi/s-periodic in δj\delta_j, KK has no limit as s→∞s\to\infty; the effect is this loss of locality, not convergence. The scale is a hyperparameter, exactly like the width of an RBF kernel.

Quick check

Compute the RYR_Y angle-encoding kernel k(x,x′)k(x,x') for x=(0.3,1.2)x=(0.3,1.2) and x′=(1.0,0.4)x'=(1.0,0.4) (four decimals).

tolerance ±0.0001
TypeScriptrunnable
import { Statevector, expectationPauli } from '@/lib/quantum-simulator';

// Angle encoding |phi(x)> = RY(x0)|0> (x) RY(x1)|0>; qubit 0 is the most significant bit,
// so the Pauli word 'ZI' is Z on qubit 0 and 'IX' is X on qubit 1.
const encode = (gate, x) => {
  const sv = Statevector.zero(x.length);
  x.forEach((xj, j) => sv.applyGate(gate, [j], [xj]));
  return sv;
};
const fmt = (v) => (Math.abs(v) < 1e-12 ? 0 : v).toFixed(6);
const ev = (sv, ops) => fmt(expectationPauli(sv, { coeff: 1, ops }));

const x = [0.3, 1.2];
const phi = encode('RY', x);
for (const ops of ['ZI', 'XI', 'YI', 'IZ', 'IX']) console.log('<' + ops + '> = ' + ev(phi, ops));
const viaRx = encode('RX', x);
console.log('RX: <ZI> = ' + ev(viaRx, 'ZI') + ', <YI> = ' + ev(viaRx, 'YI') + ', <XI> = ' + ev(viaRx, 'XI'));

// Fidelity kernel k(x, x') = |<phi(x')|phi(x)>|^2 against the product formula.
const xp = [1.0, 0.4];
const k = phi.fidelity(encode('RY', xp));
const product = x.reduce((p, xj, j) => p * Math.cos((xj - xp[j]) / 2) ** 2, 1);
console.log('k(x, xp) = ' + k.toFixed(10) + ', product formula = ' + product.toFixed(10));

Expected output

<ZI> = 0.955336
<XI> = 0.295520
<YI> = 0.000000
<IZ> = 0.362358
<IX> = 0.932039
RX: <ZI> = 0.955336, <YI> = -0.295520, <XI> = 0.000000
k(x, xp) = 0.7486048950, product formula = 0.7486048950

The same computation in NumPy builds the three encoded states of the data set {(0.3,1.2),(1.0,0.4),(2.5,−0.7)}\{(0.3,1.2),(1.0,0.4),(2.5,-0.7)\} with Kronecker products, forms the Gram matrix Kab=∣⟨ϕ(xa)∣ϕ(xb)⟩∣2K_{ab}=\lvert\langle\phi(x_a)\vert\phi(x_b)\rangle\rvert^2, checks it against the product formula, and confirms that it is positive definite.

Pythonrunnable
import numpy as np

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

def encode(x):
    psi = np.array([1.0])
    for xj in x:
        psi = np.kron(psi, ry(xj) @ np.array([1.0, 0.0]))
    return psi

Z = np.array([[1.0, 0.0], [0.0, -1.0]])
X = np.array([[0.0, 1.0], [1.0, 0.0]])
I2 = np.eye(2)
data = np.array([[0.3, 1.2], [1.0, 0.4], [2.5, -0.7]])
psi = encode(data[0])
print(f"<Z0> = {psi @ np.kron(Z, I2) @ psi:.6f}  cos(x0) = {np.cos(data[0, 0]):.6f}")
print(f"<X1> = {psi @ np.kron(I2, X) @ psi:.6f}  sin(x1) = {np.sin(data[0, 1]):.6f}")
states = np.array([encode(x) for x in data])
K = np.abs(states @ states.T) ** 2
delta = data[:, None, :] - data[None, :, :]
K_formula = np.prod(np.cos(delta / 2) ** 2, axis=2)
print(np.round(K, 6))
print(bool(np.allclose(K, K_formula)))
print(f"min eigenvalue of K: {np.linalg.eigvalsh(K).min():.6f}")

Expected output

<Z0> = 0.955336  cos(x0) = 0.955336
<X1> = 0.932039  sin(x1) = 0.932039
[[1.       0.748605 0.069616]
 [0.748605 1.       0.389105]
 [0.069616 0.389105 1.      ]]
True
min eigenvalue of K: 0.183300

The Fourier view of angle-encoded models#

A variational model does not stop at the encoding: trainable unitaries act before and after it, and a measurement turns the state into a number. Schuld, Sweke and Meyer (2021) showed that the functions such a model can represent are determined by the eigenvalues of the encoding generator: the model is always a Fourier series, and its frequencies are differences of those eigenvalues. We prove this in full for one input feature.

Definition

Quantum model with data re-uploading

Fix a Hermitian encoding generator GG on Cd\mathbb C^d and the encoding gate S(x)=e−ixGS(x)=e^{-ixG} for x∈Rx\in\mathbb R. For trainable unitaries W0,…,WLW_0,\dots,W_L and a Hermitian observable MM, the quantum model with LL uploads is U(x)=WL S(x) WL−1⋯W1 S(x) W0,f(x)=⟨0∣U(x)†MU(x)∣0⟩.U(x)=W_L\,S(x)\,W_{L-1}\cdots W_1\,S(x)\,W_0,\qquad f(x)=\langle0\vert U(x)^\dagger MU(x)\vert0\rangle. Angle encoding is the case S(x)=RX(x)=e−ixX/2S(x)=R_X(x)=e^{-ixX/2} (or RYR_Y), i.e. G=σ/2G=\sigma/2 for a Pauli matrix σ\sigma. The FourierSpectrum widget below simulates the one-qubit instance Wℓ=RZ(γℓ)RY(θℓ)RZ(φℓ)W_\ell=R_Z(\gamma_\ell)R_Y(\theta_\ell)R_Z(\varphi_\ell), S=RXS=R_X or RYR_Y, M=ZM=Z.

Lemma

The encoding gate is diagonal in the eigenbasis of its generator

If G=∑k=1dλk∣k⟩⟨k∣G=\sum_{k=1}^{d}\lambda_k\lvert k\rangle\langle k\rvert is a spectral decomposition (orthonormal eigenbasis {∣k⟩}\{\lvert k\rangle\}, real eigenvalues λk\lambda_k), then S(x)=e−ixG=∑k=1de−ixλk∣k⟩⟨k∣S(x)=e^{-ixG}=\sum_{k=1}^{d}e^{-ix\lambda_k}\lvert k\rangle\langle k\rvert.

Proof (4 steps)
  1. Step 1:
    G=∑kλk∣k⟩⟨k∣,λk∈R, ⟨k∣l⟩=δklG=\sum_k\lambda_k\lvert k\rangle\langle k\rvert,\qquad\lambda_k\in\mathbb R,\ \langle k\vert l\rangle=\delta_{kl}
    Spectral theorem for the Hermitian matrix GG.
  2. Step 2:
    Gm=∑kλkm∣k⟩⟨k∣(m≥0)G^m=\sum_k\lambda_k^m\lvert k\rangle\langle k\rvert\quad(m\ge0)
    Induction on mm: Gm+1=∑k,lλkmλl∣k⟩⟨k∣l⟩⟨l∣=∑kλkm+1∣k⟩⟨k∣G^{m+1}=\sum_{k,l}\lambda_k^m\lambda_l\lvert k\rangle\langle k\vert l\rangle\langle l\rvert=\sum_k\lambda_k^{m+1}\lvert k\rangle\langle k\rvert by orthonormality; G0=I=∑k∣k⟩⟨k∣G^0=I=\sum_k\lvert k\rangle\langle k\rvert by completeness.
  3. Step 3:
    e−ixG=∑m=0∞(−ix)mm!Gm=∑k(∑m=0∞(−ixλk)mm!)∣k⟩⟨k∣e^{-ixG}=\sum_{m=0}^{\infty}\frac{(-ix)^m}{m!}G^m=\sum_k\Big(\sum_{m=0}^\infty\frac{(-ix\lambda_k)^m}{m!}\Big)\lvert k\rangle\langle k\rvert
    Definition of the matrix exponential by its absolutely convergent power series, then exchange of the finite sum over kk with the series.
  4. Step 4:
    =∑ke−ixλk∣k⟩⟨k∣=\sum_k e^{-ix\lambda_k}\lvert k\rangle\langle k\rvert
    The inner series is the scalar exponential.

∎

Theorem

One upload: the model is a Fourier series

For L=1L=1, f(x)=∑ω∈Ωcωeiωxf(x)=\sum_{\omega\in\Omega}c_\omega e^{i\omega x} with frequency spectrum Ω={λl−λk: k,l=1,…,d}\Omega=\{\lambda_l-\lambda_k:\ k,l=1,\dots,d\} and coefficients cω=∑(l,k): λl−λk=ω⟨vl∣M∣vk⟩c_\omega=\sum_{(l,k):\,\lambda_l-\lambda_k=\omega}\langle v_l\vert M\vert v_k\rangle, where ∣vk⟩=W1∣k⟩⟨k∣W0∣0⟩\lvert v_k\rangle=W_1\lvert k\rangle\langle k\vert W_0\vert0\rangle. For a Pauli encoding G=σ/2G=\sigma/2 the spectrum is Ω={−1,0,1}\Omega=\{-1,0,1\}, so f(x)=c0+c1eix+c−1e−ixf(x)=c_0+c_1e^{ix}+c_{-1}e^{-ix}.

Proof (6 steps)
  1. Step 1:
    ∣ψ(x)⟩=W1S(x)W0∣0⟩=∑ke−ixλk W1∣k⟩⟨k∣W0∣0⟩=∑ke−ixλk∣vk⟩\lvert\psi(x)\rangle=W_1S(x)W_0\lvert0\rangle=\sum_ke^{-ix\lambda_k}\,W_1\lvert k\rangle\langle k\vert W_0\vert0\rangle=\sum_ke^{-ix\lambda_k}\lvert v_k\rangle
    Insert the eigen-expansion of S(x)S(x) from the lemma; the scalar phases move to the front.
  2. Step 2:
    ⟨ψ(x)∣=∑leixλl⟨vl∣\langle\psi(x)\rvert=\sum_le^{ix\lambda_l}\langle v_l\rvert
    Conjugate transpose: e−ixλl‾=eixλl\overline{e^{-ix\lambda_l}}=e^{ix\lambda_l} because xx and λl\lambda_l are real.
  3. Step 3:
    f(x)=⟨ψ(x)∣M∣ψ(x)⟩=∑l,keix(λl−λk)⟨vl∣M∣vk⟩f(x)=\langle\psi(x)\vert M\vert\psi(x)\rangle=\sum_{l,k}e^{ix(\lambda_l-\lambda_k)}\langle v_l\vert M\vert v_k\rangle
    Bilinearity of the inner product.
  4. Step 4:
    f(x)=∑ω∈Ω(∑(l,k): λl−λk=ω⟨vl∣M∣vk⟩)eiωx=∑ω∈Ωcωeiωxf(x)=\sum_{\omega\in\Omega}\Big(\sum_{(l,k):\,\lambda_l-\lambda_k=\omega}\langle v_l\vert M\vert v_k\rangle\Big)e^{i\omega x}=\sum_{\omega\in\Omega}c_\omega e^{i\omega x}
    Group the d2d^2 terms by the value of the exponent ω=λl−λk\omega=\lambda_l-\lambda_k.
  5. Step 5:
    σ2=I, Tr σ=0 ⇒ spec(σ)={1,−1} ⇒ spec(σ/2)={12,−12}\sigma^2=I,\ \mathrm{Tr}\,\sigma=0\ \Rightarrow\ \mathrm{spec}(\sigma)=\{1,-1\}\ \Rightarrow\ \mathrm{spec}(\sigma/2)=\{\tfrac12,-\tfrac12\}
    An eigenvalue μ\mu of σ\sigma satisfies μ2=1\mu^2=1; tracelessness forces one eigenvalue of each sign.
  6. Step 6:
    Ω={12−12, 12+12, −12−12}={0,1,−1}\Omega=\{\tfrac12-\tfrac12,\ \tfrac12+\tfrac12,\ -\tfrac12-\tfrac12\}=\{0,1,-1\}
    All differences of the two eigenvalues; hence f(x)=c0+c1eix+c−1e−ixf(x)=c_0+c_1e^{ix}+c_{-1}e^{-ix}.

∎

Theorem

L uploads: spectrum {-L, ..., L}

For LL uploads, with multi-indices j=(j1,…,jL)∈{1,…,d}L\mathbf j=(j_1,\dots,j_L)\in\{1,\dots,d\}^L and Λj=λj1+⋯+λjL\Lambda_{\mathbf j}=\lambda_{j_1}+\cdots+\lambda_{j_L}, f(x)=∑ω∈ΩLcωeiωx,ΩL={Λk−Λj},cω=∑Λk−Λj=ω⟨vk∣M∣vj⟩,f(x)=\sum_{\omega\in\Omega_L}c_\omega e^{i\omega x},\qquad\Omega_L=\{\Lambda_{\mathbf k}-\Lambda_{\mathbf j}\},\qquad c_\omega=\sum_{\Lambda_{\mathbf k}-\Lambda_{\mathbf j}=\omega}\langle v_{\mathbf k}\vert M\vert v_{\mathbf j}\rangle, with ∣vj⟩=WL∣jL⟩⟨jL∣WL−1⋯W1∣j1⟩⟨j1∣W0∣0⟩\lvert v_{\mathbf j}\rangle=W_L\lvert j_L\rangle\langle j_L\rvert W_{L-1}\cdots W_1\lvert j_1\rangle\langle j_1\rvert W_0\lvert0\rangle. For a Pauli encoding G=σ/2G=\sigma/2, ΩL={−L,−L+1,…,L}\Omega_L=\{-L,-L+1,\dots,L\}, which has 2L+12L+1 elements: ff is a trigonometric polynomial of degree at most LL.

Proof (7 steps)
  1. Step 1:
    U(x)=WL(∑jLe−ixλjL∣jL⟩⟨jL∣)WL−1⋯W1(∑j1e−ixλj1∣j1⟩⟨j1∣)W0U(x)=W_L\Big(\sum_{j_L}e^{-ix\lambda_{j_L}}\lvert j_L\rangle\langle j_L\rvert\Big)W_{L-1}\cdots W_1\Big(\sum_{j_1}e^{-ix\lambda_{j_1}}\lvert j_1\rangle\langle j_1\rvert\Big)W_0
    Replace each of the LL encoding gates by its eigen-expansion (lemma).
  2. Step 2:
    U(x)=∑j1,…,jLe−ix(λj1+⋯+λjL) WL∣jL⟩⟨jL∣WL−1⋯W1∣j1⟩⟨j1∣W0U(x)=\sum_{j_1,\dots,j_L}e^{-ix(\lambda_{j_1}+\cdots+\lambda_{j_L})}\,W_L\lvert j_L\rangle\langle j_L\rvert W_{L-1}\cdots W_1\lvert j_1\rangle\langle j_1\rvert W_0
    Multiply out the LL sums (distributivity of the matrix product) and collect the scalar phases.
  3. Step 3:
    ∣ψ(x)⟩=U(x)∣0⟩=∑je−ixΛj∣vj⟩\lvert\psi(x)\rangle=U(x)\lvert0\rangle=\sum_{\mathbf j}e^{-ix\Lambda_{\mathbf j}}\lvert v_{\mathbf j}\rangle
    Apply to ∣0⟩\lvert0\rangle and use the definitions of Λj\Lambda_{\mathbf j} and ∣vj⟩\lvert v_{\mathbf j}\rangle.
  4. Step 4:
    f(x)=∑k,jeix(Λk−Λj)⟨vk∣M∣vj⟩=∑ω∈ΩLcωeiωxf(x)=\sum_{\mathbf k,\mathbf j}e^{ix(\Lambda_{\mathbf k}-\Lambda_{\mathbf j})}\langle v_{\mathbf k}\vert M\vert v_{\mathbf j}\rangle=\sum_{\omega\in\Omega_L}c_\omega e^{i\omega x}
    Same computation as for one upload, with the bra ⟨ψ(x)∣=∑keixΛk⟨vk∣\langle\psi(x)\rvert=\sum_{\mathbf k}e^{ix\Lambda_{\mathbf k}}\langle v_{\mathbf k}\rvert; group the terms by ω=Λk−Λj\omega=\Lambda_{\mathbf k}-\Lambda_{\mathbf j}.
  5. Step 5:
    λji∈{±12} ⇒ Λj=12p(j)−12(L−p(j))=p(j)−L2,p(j)=#{i:λji=+12}∈{0,…,L}\lambda_{j_i}\in\{\pm\tfrac12\}\ \Rightarrow\ \Lambda_{\mathbf j}=\tfrac12p(\mathbf j)-\tfrac12\big(L-p(\mathbf j)\big)=p(\mathbf j)-\tfrac L2,\qquad p(\mathbf j)=\#\{i:\lambda_{j_i}=+\tfrac12\}\in\{0,\dots,L\}
    Pauli case: each of the LL eigenvalues is ±12\pm\frac12; let pp count the positive ones.
  6. Step 6:
    Λk−Λj=p(k)−p(j)∈{−L,…,L} ⇒ ΩL⊆{−L,…,L}\Lambda_{\mathbf k}-\Lambda_{\mathbf j}=p(\mathbf k)-p(\mathbf j)\in\{-L,\dots,L\}\ \Rightarrow\ \Omega_L\subseteq\{-L,\dots,L\}
    The constant −L/2-L/2 cancels; a difference of two integers in [0,L][0,L] lies in [−L,L][-L,L].
  7. Step 7:
    ω∈{0,…,L}: p(k)=L, p(j)=L−ω;ω<0: swap the roles of k,j ⇒ ΩL={−L,…,L}\omega\in\{0,\dots,L\}:\ p(\mathbf k)=L,\ p(\mathbf j)=L-\omega;\qquad\omega<0:\ \text{swap the roles of }\mathbf k,\mathbf j\ \Rightarrow\ \Omega_L=\{-L,\dots,L\}
    Every value is attained: choose k\mathbf k with all eigenvalues +12+\frac12 and j\mathbf j with exactly ω\omega of them equal to −12-\frac12. Hence ∣ΩL∣=2L+1\lvert\Omega_L\rvert=2L+1.

∎

Proposition

Hermitian symmetry of the coefficients

The coefficients satisfy c−ω=cω‾c_{-\omega}=\overline{c_\omega} for every ω∈ΩL\omega\in\Omega_L, in particular c0∈Rc_0\in\mathbb R. Consequently f(x)=c0+2∑ω∈ΩL, ω>0(Re cωcos⁡ωx−Im cωsin⁡ωx)f(x)=c_0+2\sum_{\omega\in\Omega_L,\ \omega>0}\big(\mathrm{Re}\,c_\omega\cos\omega x-\mathrm{Im}\,c_\omega\sin\omega x\big) is real for every real xx.

Proof (5 steps)
  1. Step 1:
    ⟨vk∣M∣vj⟩‾=⟨vj∣M†∣vk⟩=⟨vj∣M∣vk⟩\overline{\langle v_{\mathbf k}\vert M\vert v_{\mathbf j}\rangle}=\langle v_{\mathbf j}\vert M^\dagger\vert v_{\mathbf k}\rangle=\langle v_{\mathbf j}\vert M\vert v_{\mathbf k}\rangle
    ⟨a∣M∣b⟩‾=⟨b∣M†∣a⟩\overline{\langle a\vert M\vert b\rangle}=\langle b\vert M^\dagger\vert a\rangle and M=M†M=M^\dagger.
  2. Step 2:
    cω‾=∑Λk−Λj=ω⟨vj∣M∣vk⟩=∑Λk′−Λj′=−ω⟨vk′∣M∣vj′⟩=c−ω\overline{c_\omega}=\sum_{\Lambda_{\mathbf k}-\Lambda_{\mathbf j}=\omega}\langle v_{\mathbf j}\vert M\vert v_{\mathbf k}\rangle=\sum_{\Lambda_{\mathbf k'}-\Lambda_{\mathbf j'}=-\omega}\langle v_{\mathbf k'}\vert M\vert v_{\mathbf j'}\rangle=c_{-\omega}
    Conjugate term by term and relabel (k′,j′)=(j,k)(\mathbf k',\mathbf j')=(\mathbf j,\mathbf k); the condition Λk−Λj=ω\Lambda_{\mathbf k}-\Lambda_{\mathbf j}=\omega becomes Λk′−Λj′=−ω\Lambda_{\mathbf k'}-\Lambda_{\mathbf j'}=-\omega. Note that ΩL=−ΩL\Omega_L=-\Omega_L.
  3. Step 3:
    ω=0: c0‾=c0 ⇒ c0∈R\omega=0:\ \overline{c_0}=c_0\ \Rightarrow\ c_0\in\mathbb R
    Special case of the symmetry.
  4. Step 4:
    f(x)=c0+∑ω>0(cωeiωx+c−ωe−iωx)=c0+∑ω>0(cωeiωx+cωeiωx‾)=c0+2∑ω>0Re(cωeiωx)f(x)=c_0+\sum_{\omega>0}\Big(c_\omega e^{i\omega x}+c_{-\omega}e^{-i\omega x}\Big)=c_0+\sum_{\omega>0}\Big(c_\omega e^{i\omega x}+\overline{c_\omega e^{i\omega x}}\Big)=c_0+2\sum_{\omega>0}\mathrm{Re}\big(c_\omega e^{i\omega x}\big)
    Pair each positive frequency with its negative; c−ωe−iωx=cω‾ eiωx‾c_{-\omega}e^{-i\omega x}=\overline{c_\omega}\,\overline{e^{i\omega x}}.
  5. Step 5:
    Re(cωeiωx)=Re cωcos⁡ωx−Im cωsin⁡ωx\mathrm{Re}\big(c_\omega e^{i\omega x}\big)=\mathrm{Re}\,c_\omega\cos\omega x-\mathrm{Im}\,c_\omega\sin\omega x
    Multiply cω=Re cω+i Im cωc_\omega=\mathrm{Re}\,c_\omega+i\,\mathrm{Im}\,c_\omega by eiωx=cos⁡ωx+isin⁡ωxe^{i\omega x}=\cos\omega x+i\sin\omega x and keep the real part.

∎

Derivation

Worked example: L = 1, W = I, R_X encoding, M = Z

  1. Step 1:
    S(x)=RX(x)=e−ixX/2,G=X2,X∣±⟩=±∣±⟩,λ±=±12,∣±⟩=12(∣0⟩±∣1⟩)S(x)=R_X(x)=e^{-ixX/2},\quad G=\tfrac X2,\quad X\lvert\pm\rangle=\pm\lvert\pm\rangle,\quad\lambda_\pm=\pm\tfrac12,\quad\lvert\pm\rangle=\tfrac1{\sqrt2}(\lvert0\rangle\pm\lvert1\rangle)
    Eigenbasis of the generator: X∣+⟩=∣+⟩X\lvert+\rangle=\lvert+\rangle and X∣−⟩=−∣−⟩X\lvert-\rangle=-\lvert-\rangle.
  2. Step 2:
    W0=W1=I:∣v±⟩=∣±⟩⟨±∣0⟩=12∣±⟩W_0=W_1=I:\quad\lvert v_\pm\rangle=\lvert\pm\rangle\langle\pm\vert0\rangle=\tfrac1{\sqrt2}\lvert\pm\rangle
    ⟨±∣0⟩=12\langle\pm\vert0\rangle=\frac1{\sqrt2}.
  3. Step 3:
    Z∣+⟩=∣−⟩, Z∣−⟩=∣+⟩ ⇒ ⟨+∣Z∣+⟩=⟨−∣Z∣−⟩=0,⟨+∣Z∣−⟩=⟨−∣Z∣+⟩=1Z\lvert+\rangle=\lvert-\rangle,\ Z\lvert-\rangle=\lvert+\rangle\ \Rightarrow\ \langle+\vert Z\vert+\rangle=\langle-\vert Z\vert-\rangle=0,\quad\langle+\vert Z\vert-\rangle=\langle-\vert Z\vert+\rangle=1
    ZZ maps 12(∣0⟩±∣1⟩)\frac1{\sqrt2}(\lvert0\rangle\pm\lvert1\rangle) to 12(∣0⟩∓∣1⟩)\frac1{\sqrt2}(\lvert0\rangle\mp\lvert1\rangle).
  4. Step 4:
    c1=⟨v+∣Z∣v−⟩=12,c−1=⟨v−∣Z∣v+⟩=12,c0=⟨v+∣Z∣v+⟩+⟨v−∣Z∣v−⟩=0c_1=\langle v_+\vert Z\vert v_-\rangle=\tfrac12,\qquad c_{-1}=\langle v_-\vert Z\vert v_+\rangle=\tfrac12,\qquad c_0=\langle v_+\vert Z\vert v_+\rangle+\langle v_-\vert Z\vert v_-\rangle=0
    ω=λl−λk=1\omega=\lambda_l-\lambda_k=1 only for (l,k)=(+,−)(l,k)=(+,-), ω=−1\omega=-1 only for (−,+)(-,+), and ω=0\omega=0 for (+,+)(+,+) and (−,−)(-,-).
  5. Step 5:
    f(x)=12eix+12e−ix=cos⁡xf(x)=\tfrac12e^{ix}+\tfrac12e^{-ix}=\cos x
    Euler's formula. This is exactly ⟨Z⟩=cos⁡x\langle Z\rangle=\cos x for RXR_X encoding derived in the first section, and c−1=c1‾c_{-1}=\overline{c_1} as required by the symmetry.

Result

f(x)=cos⁡x,c±1=12,c0=0\boxed{f(x)=\cos x,\qquad c_{\pm1}=\tfrac12,\quad c_0=0}

With L=1L=1 and every trainable block frozen at the identity, the widget shows f(x)=cos⁡xf(x)=\cos x and the two bars ∣c±1∣=12\lvert c_{\pm1}\rvert=\tfrac12 of the example. The next widget re-uploads xx three times with randomly drawn blocks W0,…,W3W_0,\dots,W_3: the bars now occupy ω∈{−3,…,3}\omega\in\{-3,\dots,3\} and never appear beyond ∣ω∣=3\lvert\omega\rvert=3, whatever the seed.

Corollary

The spectrum is an upper bound; the trainable blocks set the coefficients

(i) With W0=⋯=WL=IW_0=\cdots=W_L=I, S=RXS=R_X and M=ZM=Z, the LL-upload model is f(x)=cos⁡(Lx)f(x)=\cos(Lx): only c±L=12c_{\pm L}=\tfrac12 are nonzero. (ii) Encoding xx once on each of LL qubits in parallel, S(x)=RX(x)⊗LS(x)=R_X(x)^{\otimes L}, gives the same spectrum {−L,…,L}\{-L,\dots,L\} as LL sequential uploads on one qubit.

Proof (5 steps)
  1. Step 1:
    U(x)=RX(x)L=e−iLxX/2=RX(Lx)U(x)=R_X(x)^L=e^{-iLxX/2}=R_X(Lx)
    Identity blocks leave LL consecutive rotations about the same axis, whose angles add.
  2. Step 2:
    f(x)=⟨0∣RX(Lx)†ZRX(Lx)∣0⟩=cos⁡(Lx)=12eiLx+12e−iLxf(x)=\langle0\vert R_X(Lx)^\dagger ZR_X(Lx)\vert0\rangle=\cos(Lx)=\tfrac12e^{iLx}+\tfrac12e^{-iLx}
    The RXR_X proposition with angle LxLx: of the 2L+12L+1 available frequencies only ±L\pm L carry weight. The spectrum says which frequencies can appear; the blocks WℓW_\ell decide their coefficients.
  3. Step 3:
    RX(x)⊗L=⨂i=1Le−ixXi/2=e−ix∑iXi/2R_X(x)^{\otimes L}=\bigotimes_{i=1}^{L}e^{-ixX_i/2}=e^{-ix\sum_iX_i/2}
    The operators XiX_i act on different qubits and commute, so the product of exponentials is the exponential of the sum: the generator is G=12∑iXiG=\frac12\sum_iX_i.
  4. Step 4:
    spec(12∑iXi)={12∑iμi: μi=±1}={p−L2: p=0,…,L}\mathrm{spec}\Big(\tfrac12\sum_iX_i\Big)=\Big\{\tfrac12\sum_i\mu_i:\ \mu_i=\pm1\Big\}=\Big\{p-\tfrac L2:\ p=0,\dots,L\Big\}
    The product basis of XiX_i-eigenvectors diagonalises the sum; with pp positive signs the eigenvalue is p2−L−p2\frac p2-\frac{L-p}2.
  5. Step 5:
    Ω={p−p′: p,p′∈{0,…,L}}={−L,…,L}\Omega=\{p-p':\ p,p'\in\{0,\dots,L\}\}=\{-L,\dots,L\}
    The same eigenvalue set as Λj\Lambda_{\mathbf j} in the sequential case, so the one-upload theorem with this GG gives the same spectrum: width (qubits) can be traded for depth (uploads).

∎

Quick check

A one-qubit model re-uploads xx four times through RY(x)R_Y(x), with trainable blocks between the uploads. How many frequencies does its spectrum Ω\Omega contain?

tolerance ±1e-9

Quick check

Take L=3L=3 uploads of RX(x)R_X(x) on one qubit with every trainable block equal to II, and measure ZZ. Which Fourier coefficients of ff are nonzero?

Select one answer

Data re-uploading and expressivity#

Proposition

A single upload cannot represent cos 2x

Every one-upload Pauli model is of the form f(x)=a0+a1cos⁡x+b1sin⁡xf(x)=a_0+a_1\cos x+b_1\sin x with real a0,a1,b1a_0,a_1,b_1. In particular no choice of W0,W1,MW_0,W_1,M gives f(x)=cos⁡2xf(x)=\cos2x; more generally a model with LL uploads cannot represent a function with a nonzero Fourier coefficient at a frequency ∣ω∣>L\lvert\omega\rvert>L.

Proof (5 steps)
  1. Step 1:
    f(x)=c0+2 Re c1cos⁡x−2 Im c1sin⁡x=:a0+a1cos⁡x+b1sin⁡xf(x)=c_0+2\,\mathrm{Re}\,c_1\cos x-2\,\mathrm{Im}\,c_1\sin x=:a_0+a_1\cos x+b_1\sin x
    The one-upload theorem gives Ω={−1,0,1}\Omega=\{-1,0,1\}; the symmetry proposition turns the series into this real form.
  2. Step 2:
    12π∫02πei(ω−ω′)x dx=δωω′(ω,ω′∈Z)\frac1{2\pi}\int_0^{2\pi}e^{i(\omega-\omega')x}\,dx=\delta_{\omega\omega'}\qquad(\omega,\omega'\in\mathbb Z)
    For ω≠ω′\omega\ne\omega' the integrand is a full number of periods of a complex exponential and integrates to 00; for ω=ω′\omega=\omega' it is 11.
  3. Step 3:
    g^(ω):=12π∫02πg(x)e−iωxdx ⇒ f^(2)=∑ω′∈{−1,0,1}cω′δω′2=0\hat g(\omega):=\frac1{2\pi}\int_0^{2\pi}g(x)e^{-i\omega x}dx\ \Rightarrow\ \hat f(2)=\sum_{\omega'\in\{-1,0,1\}}c_{\omega'}\delta_{\omega'2}=0
    Project the model onto e2ixe^{2ix} using the orthogonality relation.
  4. Step 4:
    cos⁡2x=12e2ix+12e−2ix ⇒ cos⁡2x^(2)=12≠0\cos2x=\tfrac12e^{2ix}+\tfrac12e^{-2ix}\ \Rightarrow\ \widehat{\cos2x}(2)=\tfrac12\ne0
    The same projection of the target function.
  5. Step 5:
    f=cos⁡2x ⇒ 0=f^(2)=12, a contradictionf=\cos2x\ \Rightarrow\ 0=\hat f(2)=\tfrac12,\ \text{a contradiction}
    Equal functions have equal Fourier coefficients. The same argument with ΩL={−L,…,L}\Omega_L=\{-L,\dots,L\} excludes every frequency ∣ω∣>L\lvert\omega\rvert>L.

∎

Re-uploading as the route to richer models. Pérez-Salinas, Cervera-Lierta, Gil-Fuster and Latorre (2020) proposed to re-upload the data many times, interleaving encoding gates with trainable gates, and showed that even a single qubit then becomes a flexible classifier. The spectrum theorem explains why: each upload enlarges the frequency set by one, ΩL={−L,…,L}\Omega_L=\{-L,\dots,L\}, so the model class grows from degree-one trigonometric polynomials to degree-LL ones. Their result can be stated as follows.

Statement (Pérez-Salinas et al. 2020). A single qubit processed by layers L(i)=U(θi) U(x)L(i)=U(\theta_i)\,U(x), in which the data xx is re-uploaded in every layer and θi\theta_i are trainable, can approximate a broad class of classification boundaries, with an expressive power that grows with the number of layers; adding qubits and entanglement reduces the number of layers needed.

Two facts proved in this lesson make the statement precise in one dimension. First, the degree bound: with LL uploads only frequencies ∣ω∣≤L\lvert\omega\rvert\le L exist, so re-uploading is necessary to fit high-frequency structure. Second, the coefficient picture: the 2L+12L+1 coefficients cωc_\omega are functions of the trainable blocks. Schuld, Sweke and Meyer show that when the trainable blocks are arbitrary unitaries on a large enough register and the observable is arbitrary, the coefficients of any real trigonometric polynomial with frequencies in the spectrum can be realised, up to a normalisation imposed by ∥M∥\lVert M\rVert (a single qubit with M=ZM=Z reaches only a subset of them); combined with the Weierstrass approximation theorem for trigonometric polynomials (every continuous 2π2\pi-periodic function is a uniform limit of them), re-uploading models with growing LL are universal approximators for periodic functions. For nn features the same expansion, applied to every encoding gate, gives frequency vectors ω∈Ω(0)×⋯×Ω(n−1)\omega\in\Omega^{(0)}\times\cdots\times\Omega^{(n-1)} with Ω(j)={−Lj,…,Lj}\Omega^{(j)}=\{-L_j,\dots,L_j\} when feature jj is uploaded LjL_j times; a product RYR_Y encoding without re-uploading measured in Z⊗ZZ\otimes Z gives, for example, f(x)=cos⁡x0cos⁡x1f(x)=\cos x_0\cos x_1, which contains only the frequency vectors (±1,±1)(\pm1,\pm1).

The following NumPy experiment fixes four blocks Wℓ=RZ(γℓ)RY(θℓ)RZ(φℓ)W_\ell=R_Z(\gamma_\ell)R_Y(\theta_\ell)R_Z(\varphi_\ell), evaluates f(x)=⟨Z⟩f(x)=\langle Z\rangle of the RXR_X re-uploading model at N=16N=16 equally spaced points, and computes the coefficients cω=1N∑nf(xn)e−iωxnc_\omega=\frac1N\sum_nf(x_n)e^{-i\omega x_n} with the FFT (exact here, because ff is a trigonometric polynomial of degree L<N/2L<N/2). Each row lists ∣cω∣\lvert c_\omega\rvert for ω=−4,…,4\omega=-4,\dots,4 and checks c−ω=cω‾c_{-\omega}=\overline{c_\omega}: the support grows exactly to {−L,…,L}\{-L,\dots,L\}.

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]])

def rx(a):
    c, s = np.cos(a / 2), np.sin(a / 2)
    return np.array([[c, -1j * s], [-1j * s, c]])

def W(phi, theta, gamma):
    return rz(gamma) @ ry(theta) @ rz(phi)

Z = np.diag([1.0, -1.0])
angles = [(0.4, 1.3, 2.2), (2.9, 0.7, 1.6), (1.1, 2.4, 0.3), (0.8, 1.9, 2.7)]

def f(x, L):
    psi = W(*angles[0]) @ np.array([1.0, 0.0])
    for l in range(1, L + 1):
        psi = W(*angles[l]) @ (rx(x) @ psi)
    return float(np.real(psi.conj() @ Z @ psi))

N = 16
xs = 2 * np.pi * np.arange(N) / N
for L in (1, 2, 3):
    c = np.fft.fft([f(x, L) for x in xs]) / N
    mags = np.abs([c[w % N] for w in range(-4, 5)])
    hermitian = np.allclose([c[w % N] for w in range(1, 5)], np.conj([c[-w % N] for w in range(1, 5)]))
    print(L, np.round(mags, 4), bool(hermitian))

Expected output

1 [0.     0.     0.     0.3213 0.3547 0.3213 0.     0.     0.    ] True
2 [0.     0.     0.1534 0.1432 0.509  0.1432 0.1534 0.     0.    ] True
3 [0.     0.0253 0.1944 0.2717 0.1469 0.2717 0.1944 0.0253 0.    ] True

References

  1. M. Schuld, R. Sweke and J. J. Meyer, Effect of data encoding on the expressive power of variational quantum-machine-learning models, Physical Review A 103, 032430 (2021).doi:10.1103/PhysRevA.103.032430
  2. A. Pérez-Salinas, A. Cervera-Lierta, E. Gil-Fuster and J. I. Latorre, Data re-uploading for a universal quantum classifier, Quantum 4, 226 (2020).doi:10.22331/q-2020-02-06-226
  3. R. LaRose and B. Coyle, Robust data encodings for quantum classifiers, Physical Review A 102, 032420 (2020) (dense angle encoding).doi:10.1103/PhysRevA.102.032420
  4. M. Schuld and F. Petruccione, Machine Learning with Quantum Computers, 2nd ed., Springer (2021), Ch. 4 "Representing Data on a Quantum Computer" and Ch. 5 "Variational Circuits as Machine Learning Models".doi:10.1007/978-3-030-83098-4
  5. M. Schuld and N. Killoran, Quantum machine learning in feature Hilbert spaces, Physical Review Letters 122, 040504 (2019).doi:10.1103/PhysRevLett.122.040504
  6. V. Havlíček, A. D. Córcoles, K. Temme, A. W. Harrow, A. Kandala, J. M. Chow and J. M. Gambetta, Supervised learning with quantum-enhanced feature spaces, Nature 567, 209–212 (2019).doi:10.1038/s41586-019-0980-2

Hands-on labs

  • Angle-encode a two-feature datum

    1 step · auto-graded

    Write the angle-encoding feature map ∣ϕ(x)⟩=RY(x0)∣0⟩⊗RY(x1)∣0⟩\lvert\phi(x)\rangle=R_Y(x_0)\lvert0\rangle\otimes R_Y(x_1)\lvert0\rangle for a datum x=(x0,x1)x=(x_0,x_1) as a circuit that uses the data symbols x0,x1x_0,x_1, so that it works for every datum. The grader re-binds the symbols to three data points and checks ⟨Zj⟩=cos⁡xj\langle Z_j\rangle=\cos x_j and ⟨Xj⟩=sin⁡xj\langle X_j\rangle=\sin x_j on both qubits.

    Open lab