Quantum Computation

Fourteen modules, from a single qubit to quantum key distribution, each taught in the format that fits it best. Click gates onto a Bloch sphere, build circuits, run Bell tests and Grover search, watch noise shrink a state, then check yourself with concept questions and practice problems.

Follows the chapter order of M. A. Nielsen and I. L. Chuang, Quantum Computation and Quantum Information, 10th Anniversary Edition (Cambridge University Press, 2010), and covers all twelve chapters; Chapters 1 and 2 get two modules each. Chapter numbers refer to that book; the questions and examples here are written for this page.

InteractiveNielsen–Chuang, Ch. 1: Introduction and overview

Qubits and the Bloch sphere

A qubit's state is a pair of complex numbers. Throw away the overall phase, which no experiment can see, and what is left is a point on a sphere. Every single-qubit gate is then a rotation of that sphere, and you can watch each one turn the state.

The idea

Qubit. A unit vector |ψ⟩=α|0⟩+β|1⟩\ket{\psi}=\alpha\ket{0}+\beta\ket{1} in ℂ2\C^2, with |α|2+|β|2=1|\alpha|^2+|\beta|^2=1. Measuring in the computational basis gives 00 with probability |α|2|\alpha|^2 and 11 with probability |β|2|\beta|^2.
Bloch sphere. The states |ψ⟩\ket\psi and eiγ|ψ⟩e^{i\gamma}\ket\psi give the same probabilities for every measurement, so up to this global phase every qubit state can be written
|ψ⟩=cos⁡θ2|0⟩+eiφsin⁡θ2|1⟩,r→=(sin⁡θcos⁡φ, sin⁡θsin⁡φ, cos⁡θ).\ket\psi=\cos\tfrac\theta2\,\ket0+e^{i\varphi}\sin\tfrac\theta2\,\ket1,\qquad \vec r=(\sin\theta\cos\varphi,\ \sin\theta\sin\varphi,\ \cos\theta).

|0⟩\ket0 is the north pole, |1⟩\ket1 the south pole, and |±⟩=(|0⟩±|1⟩)/2\ket\pm=(\ket0\pm\ket1)/\sqrt2 and |±i⟩=(|0⟩±i|1⟩)/2\ket{\pm i}=(\ket0\pm i\ket1)/\sqrt2 sit on the equator along ±x\pm x and ±y\pm y. The common gates are

X=(0110), Y=(0−ii0), Z=(100−1), H=12(111−1), S=(100i), T=(100eiπ/4).X=\begin{pmatrix}0&1\\1&0\end{pmatrix},\ Y=\begin{pmatrix}0&-i\\i&0\end{pmatrix},\ Z=\begin{pmatrix}1&0\\0&-1\end{pmatrix},\ H=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix},\ S=\begin{pmatrix}1&0\\0&i\end{pmatrix},\ T=\begin{pmatrix}1&0\\0&e^{i\pi/4}\end{pmatrix}.
Gates are rotations. For a real unit vector n^\hat n, Rn^(θ)=e−iθn^⋅σ→/2=cos⁡θ2I−isin⁡θ2(n^⋅σ→)R_{\hat n}(\theta)=e^{-i\theta\,\hat n\cdot\vec\sigma/2}=\cos\tfrac\theta2\,I-i\sin\tfrac\theta2\,(\hat n\cdot\vec\sigma) rotates the Bloch vector by θ\theta about n^\hat n. Every one-qubit unitary is eiγRn^(θ)e^{i\gamma}R_{\hat n}(\theta) for some γ,n^,θ\gamma,\hat n,\theta. For example XX is a half turn about xx, HH a half turn about (x+z)/2(x+z)/\sqrt2, SS a quarter turn about zz, and TT an eighth of a turn about zz.
Angles double. Orthogonal states are antipodal on the sphere, not perpendicular: the angle between Bloch vectors is twice the angle between the state vectors.

Explore

the state r→\vec r path of the last gate its rotation axis · drag to turn the sphere
Start from
Apply a gate

Worked example

Find the rotation performed by the gate SHSH (first HH, then SS), and what happens if you apply it three times.

  1. Where does HH send the three Bloch axes xx, yy, zz?

    HH is a half turn about (x+z)/2(x+z)/\sqrt2. A half turn swaps the two axes symmetric about its axis and reverses the one perpendicular to it: x↦zx\mapsto z, z↦xz\mapsto x, y↦−yy\mapsto -y. Check: H|0⟩=|+⟩H\ket0=\ket+ and H|+i⟩=eiπ/4|−i⟩H\ket{+i}=e^{i\pi/4}\ket{-i}.

  2. And SS?

    A quarter turn counterclockwise about zz: x↦yx\mapsto y, y↦−xy\mapsto -x, z↦zz\mapsto z. Indeed S|+⟩=(|0⟩+i|1⟩)/2=|+i⟩S\ket+=(\ket0+i\ket1)/\sqrt2=\ket{+i}.

  3. Compose them. What does SHSH do to the axes, and what rotation is that?

    x↦z↦zx\mapsto z\mapsto z,  y↦−y↦x\ y\mapsto -y\mapsto x,  z↦x↦y\ z\mapsto x\mapsto y. So SHSH cycles z→y→x→zz\to y\to x\to z. A rotation that permutes the axes cyclically fixes the diagonal (1,1,1)/3(1,1,1)/\sqrt3 and turns by a third of a full turn. The cycle x→y→zx\to y\to z is +2π/3+2\pi/3 about that axis, so ours, the reverse cycle, is

    SH=eiγRn^(−2π/3),n^=13(1,1,1).SH = e^{i\gamma}R_{\hat n}(-2\pi/3),\qquad \hat n=\tfrac1{\sqrt3}(1,1,1).
  4. Try it in the explorer: start at |0⟩\ket0 and press H, S three times over. Then compute (SH)3(SH)^3 exactly.

    The state goes |0⟩→|+i⟩→|+⟩→|0⟩\ket0\to\ket{+i}\to\ket+\to\ket0 on the sphere, as the cycle predicts. Three thirds of a turn is the identity rotation, so (SH)3(SH)^3 is a multiple of II. Multiplying the matrices gives

    (SH)3=eiπ/4I.(SH)^3 = e^{i\pi/4}\,I.

    The phase eiπ/4e^{i\pi/4} is global, so it is invisible, but the amplitudes shown in the explorer do carry it.

Check your understanding

Which pair of states can be told apart by some measurement (given many copies)?

  1. |0⟩+|1⟩\ket0+\ket1 and −|0⟩−|1⟩-\ket0-\ket1 (normalised)These differ by the global factor −1-1. Every probability |⟨ϕ|ψ⟩|2|\langle\phi|\psi\rangle|^2 is unchanged by a global phase.
  2. |0⟩+|1⟩\ket0+\ket1 and |0⟩−|1⟩\ket0-\ket1 (normalised)
  3. |1⟩\ket1 and i|1⟩i\ket1ii multiplies the whole state, so it is a global phase.
A relative phase between |0⟩\ket0 and |1⟩\ket1 moves the Bloch vector around the equator: |+⟩\ket+ and |−⟩\ket- are antipodal, and a measurement in the XX basis tells them apart with certainty. A global phase doesn't move the Bloch vector at all.

What is T8T^8?

  1. Exactly II
  2. −I-I: eight eighth-turns make a full turn, and Rz(2π)=−IR_z(2\pi)=-IRz(2π)R_z(2\pi) is indeed −I-I, but TT is Rz(π/4)R_z(\pi/4) times the phase eiπ/8e^{i\pi/8}, and that phase also gets raised to the 8th power.
  3. ZZT2=ST^2=S and S2=ZS^2=Z, so ZZ is T4T^4. Keep going.
T=diag(1,eiπ/4)T=\mathrm{diag}(1,e^{i\pi/4}), so T8=diag(1,e2πi)=IT^8=\mathrm{diag}(1,e^{2\pi i})=I. As a rotation, T8=eiπRz(2π)=(−1)(−I)=IT^8 = e^{i\pi}R_z(2\pi)=(-1)(-I)=I. The sign of a full rotation and the global phase cancel.

The Bloch vectors of two pure states make an angle of 90∘90^\circ. What is |⟨ϕ|ψ⟩|2|\langle\phi|\psi\rangle|^2?

  1. 00Orthogonal states are antipodal (180∘180^\circ apart), not perpendicular.
  2. 1/21/2
  3. 1/21/\sqrt2That's |⟨ϕ|ψ⟩||\langle\phi|\psi\rangle|, before squaring.
For pure states |⟨ϕ|ψ⟩|2=(1+r→⋅s→)/2|\langle\phi|\psi\rangle|^2=(1+\vec r\cdot\vec s)/2. At 90∘90^\circ, r→⋅s→=0\vec r\cdot\vec s=0, giving 1/21/2. Example: |0⟩\ket0 and |+⟩\ket+.

Practice

Locate a stateFrom amplitudes to the Bloch vector

Find the Bloch vector of |ψ⟩=(|0⟩+(1+i)|1⟩)/3\ket\psi=\big(\ket0+(1+i)\ket1\big)/\sqrt3.

Hint

For α|0⟩+β|1⟩\alpha\ket0+\beta\ket1, the Bloch vector is (2Re(α‾β), 2Im(α‾β), |α|2−|β|2)\big(2\,\mathrm{Re}(\bar\alpha\beta),\ 2\,\mathrm{Im}(\bar\alpha\beta),\ |\alpha|^2-|\beta|^2\big).

Solution

α‾β=(1+i)/3\bar\alpha\beta=(1+i)/3, so x=y=2/3x=y=2/3, and z=1/3−2/3=−1/3z=1/3-2/3=-1/3. Check: 4/9+4/9+1/9=14/9+4/9+1/9=1. The state is just below the equator, halfway between +x+x and +y+y.

A square root of NOTRotations by half the angle

Find a unitary VV with V2=XV^2=X, and describe it on the Bloch sphere.

Hint

XX is a half turn about xx, so try a quarter turn about xx, and fix the phase afterwards.

Solution

Rx(π/2)2=Rx(π)=−iXR_x(\pi/2)^2=R_x(\pi)=-iX. Multiplying by eiπ/4e^{i\pi/4} fixes the phase, since (eiπ/4)2(−i)=1(e^{i\pi/4})^2(-i)=1:

V=eiπ/4Rx(π/2)=12(1+i1−i1−i1+i),V2=X.V=e^{i\pi/4}R_x(\pi/2)=\tfrac12\begin{pmatrix}1+i&1-i\\1-i&1+i\end{pmatrix},\qquad V^2=X.

On the sphere VV is a quarter turn about xx. (Rx in the explorer with θ = π/2 does the same rotation, with a different global phase.)

More practice: Nielsen–Chuang, Exercises 4.1, 4.4 and 4.6.

Animated lessonNielsen–Chuang, Ch. 1: Introduction and overview

Bell states and teleportation

With one shared entangled pair and two classical bits, Alice can hand Bob an unknown qubit without ever learning what it is. The animation follows the state through the circuit and shows, at each moment, what Bob would hold for each result Alice could get.

The idea

Two qubits. The state space is ℂ2⊗ℂ2≅ℂ4\C^2\otimes\C^2\cong\C^4, with basis |00⟩,|01⟩,|10⟩,|11⟩\ket{00},\ket{01},\ket{10},\ket{11}. A state is a product if it equals |a⟩⊗|b⟩\ket a\otimes\ket b, and entangled otherwise.
Bell states. HH on the first qubit followed by a CNOT turns |xy⟩\ket{xy} into
|βxy⟩=|0y⟩+(−1)x|1y‾⟩2:|β00⟩=|00⟩+|11⟩2, |β01⟩=|01⟩+|10⟩2, |β10⟩=|00⟩−|11⟩2, |β11⟩=|01⟩−|10⟩2.\ket{\beta_{xy}}=\frac{\ket{0\,y}+(-1)^x\ket{1\,\bar y}}{\sqrt2}:\qquad \ket{\beta_{00}}=\tfrac{\ket{00}+\ket{11}}{\sqrt2},\ \ket{\beta_{01}}=\tfrac{\ket{01}+\ket{10}}{\sqrt2},\ \ket{\beta_{10}}=\tfrac{\ket{00}-\ket{11}}{\sqrt2},\ \ket{\beta_{11}}=\tfrac{\ket{01}-\ket{10}}{\sqrt2}.
No cloning. No unitary sends |ψ⟩|0⟩↦|ψ⟩|ψ⟩\ket\psi\ket0\mapsto\ket\psi\ket\psi for every |ψ⟩\ket\psi: it would have to preserve inner products, but ⟨ϕ|ψ⟩\langle\phi|\psi\rangle and ⟨ϕ|ψ⟩2\langle\phi|\psi\rangle^2 differ unless the states are equal or orthogonal. So a teleported qubit cannot also stay with Alice.
Teleportation identity. If Alice holds |ψ⟩\ket\psi and shares |β00⟩\ket{\beta_{00}} with Bob, then after Alice applies CNOT (her two qubits) and HH (her first qubit),
|ψ⟩|β00⟩ ⟼ 12∑m1,m2∈{0,1}|m1m2⟩⊗Xm2Zm1|ψ⟩.\ket\psi\ket{\beta_{00}}\ \longmapsto\ \frac12\sum_{m_1,m_2\in\{0,1\}}\ket{m_1m_2}\otimes X^{m_2}Z^{m_1}\ket\psi.

Alice measures, gets m1m2m_1m_2 with probability 1/41/4 whatever |ψ⟩\ket\psi is, and sends the two bits. Bob applies Xm2X^{m_2} then Zm1Z^{m_1} and holds |ψ⟩\ket\psi.

Nothing travels faster than light. Until the bits arrive, Bob's qubit is an equal mixture of the four branches, which is the state I/2I/2 for every |ψ⟩\ket\psi.

Watch

Alice's unknown state
Alice's measurement result
Top: the circuit, Alice's two qubits above and Bob's below. Bottom: Bob's qubit in each branch m1m2m_1m_2, that is, what he would hold if Alice measured now. Bob's state Alice's |ψ⟩\ket\psi, for comparison
  1. Alice holds an unknown qubit |ψ⟩\ket\psi. Two more qubits start in |0⟩\ket0. No branch shows |ψ⟩\ket\psi on Bob's side yet.
  2. HH and CNOT make the Bell pair |β00⟩\ket{\beta_{00}}. Alice keeps one half, Bob takes the other.
  3. Alice applies CNOT from |ψ⟩\ket\psi to her half of the pair. Bob's branches are now |0⟩\ket0 or |1⟩\ket1: only the amplitudes' sizes have moved, not the phase.
  4. Alice applies HH to her first qubit. Every branch is now equally likely and holds |ψ⟩\ket\psi up to a Pauli: Xm2Zm1|ψ⟩X^{m_2}Z^{m_1}\ket\psi.
  5. Alice measures and gets m1m2m_1m_2. The other branches vanish; Bob holds Xm2Zm1|ψ⟩X^{m_2}Z^{m_1}\ket\psi but doesn't yet know which.
  6. The two bits reach Bob. He applies Xm2X^{m_2}, then Zm1Z^{m_1}, and now holds exactly |ψ⟩\ket\psi. Alice's copy is gone.

Worked example

Suppose Alice and Bob share |β11⟩=(|01⟩−|10⟩)/2\ket{\beta_{11}}=(\ket{01}-\ket{10})/\sqrt2 instead of |β00⟩\ket{\beta_{00}}, and Alice does exactly the same steps. Which correction must Bob apply for each result?

  1. Write |β11⟩\ket{\beta_{11}} as a one-qubit operation on Bob's half of |β00⟩\ket{\beta_{00}}.

    (I⊗X)|β00⟩=(|01⟩+|10⟩)/2(I\otimes X)\ket{\beta_{00}}=(\ket{01}+\ket{10})/\sqrt2, and then (I⊗Z)(I\otimes Z) gives (−|01⟩+|10⟩)/2=−|β11⟩(-\ket{01}+\ket{10})/\sqrt2=-\ket{\beta_{11}}. So |β11⟩=−(I⊗ZX)|β00⟩\ket{\beta_{11}}=-(I\otimes ZX)\ket{\beta_{00}}.

  2. Why can we pretend Bob applied ZXZX at the very start?

    Alice's CNOT, HH and measurement act only on her two qubits, and ZXZX acts only on Bob's. Operators on different qubits commute, so the extra ZXZX can be moved past all of Alice's steps.

  3. So what does Bob hold after Alice reports m1m2m_1m_2?

    Up to a sign, ZXXm2Zm1|ψ⟩ZX\,X^{m_2}Z^{m_1}\ket\psi. He must undo this with Zm1Xm2XZZ^{m_1}X^{m_2}XZ (read right to left: apply ZZ first).

  4. Simplify the four corrections.

    Using X2=Z2=IX^2=Z^2=I and ZX=−XZZX=-XZ:

    00: XZ,01: Z,10: X (up to sign),11: nothing.00:\ XZ,\qquad 01:\ Z,\qquad 10:\ X\ (\text{up to sign}),\qquad 11:\ \text{nothing}.

    Check 1111: Bob holds ZX⋅XZ|ψ⟩=|ψ⟩ZX\cdot XZ\ket\psi=\ket\psi up to sign. Any shared Bell state works, as long as Alice and Bob agree in advance which one it is.

Check your understanding

Alice has measured, but her two bits haven't reached Bob. What state should Bob use to predict his own measurements?

  1. |ψ⟩\ket\psiThen Alice could signal instantly, by choosing |ψ⟩\ket\psi and letting Bob measure.
  2. Xm2Zm1|ψ⟩X^{m_2}Z^{m_1}\ket\psiThat's correct only for someone who knows m1m2m_1m_2. Bob doesn't.
  3. The maximally mixed state I/2I/2, whatever |ψ⟩\ket\psi is
Each of the four Pauli-rotated copies of |ψ⟩\ket\psi has probability 1/41/4, and 14∑PP|ψ⟩⟨ψ|P†=I/2\tfrac14\sum_P P\ket\psi\bra\psi P^\dagger=I/2 for the Paulis I,X,Z,XZI,X,Z,XZ. Bob's statistics don't depend on |ψ⟩\ket\psi until the bits arrive.

Is 12(|00⟩+|01⟩+|10⟩+|11⟩)\tfrac12(\ket{00}+\ket{01}+\ket{10}+\ket{11}) entangled?

  1. Yes: all four basis states appear.The number of terms depends on the basis. Try to factor it.
  2. No: it is |+⟩⊗|+⟩\ket+\otimes\ket+.
  3. Yes: it's one of the Bell states.Each Bell state has only two terms in this basis.
Write the amplitudes as a matrix (c00c01c10c11)\big(\begin{smallmatrix}c_{00}&c_{01}\\c_{10}&c_{11}\end{smallmatrix}\big). The state is a product exactly when this matrix has rank 1, i.e. c00c11=c01c10c_{00}c_{11}=c_{01}c_{10}. Here 14=14\tfrac14=\tfrac14.

Why does Alice apply HH to |ψ⟩\ket\psi's qubit before measuring?

  1. Without it, Bob's branch states are just |0⟩\ket0 or |1⟩\ket1, and the phase of |ψ⟩\ket\psi would be lost in the measurement.
  2. It is part of making the Bell pair.The Bell pair's HH acts on Alice's other qubit, earlier in the circuit.
  3. It only changes a global phase, so it could be skipped.Scrub the animation to just before the HH: Bob's branches are |0⟩\ket0 or |1⟩\ket1, not copies of |ψ⟩\ket\psi.
After the CNOT, the branches are α|0⟩,α|1⟩,β|1⟩,β|0⟩\alpha\ket0,\alpha\ket1,\beta\ket1,\beta\ket0: a measurement then would reveal partial information about |α|,|β||\alpha|,|\beta| and destroy the relative phase. The HH mixes the branches so each one carries all of |ψ⟩\ket\psi, and each outcome has probability 1/41/4.

Practice

Back from the Bell basisChange of basis

Express |01⟩\ket{01} and |11⟩\ket{11} as combinations of Bell states.

Hint

Add and subtract Bell states that contain the same two basis vectors.

Solution

|β01⟩+|β11⟩=22|01⟩\ket{\beta_{01}}+\ket{\beta_{11}}=\tfrac{2}{\sqrt2}\ket{01}, so |01⟩=(|β01⟩+|β11⟩)/2\ket{01}=(\ket{\beta_{01}}+\ket{\beta_{11}})/\sqrt2. Similarly |β00⟩−|β10⟩=2|11⟩\ket{\beta_{00}}-\ket{\beta_{10}}=\sqrt2\ket{11}, so |11⟩=(|β00⟩−|β10⟩)/2\ket{11}=(\ket{\beta_{00}}-\ket{\beta_{10}})/\sqrt2.

Teleporting entanglementEntanglement swapping

Charlie and Alice share |β00⟩\ket{\beta_{00}}, and Alice and Bob share another |β00⟩\ket{\beta_{00}}. Alice teleports her half of the first pair to Bob, using the second pair. What do Charlie and Bob end up with?

Hint

Teleportation is linear: it works term by term on 12(|0⟩C|0⟩A+|1⟩C|1⟩A)\tfrac1{\sqrt2}(\ket0_C\ket0_A+\ket1_C\ket1_A).

Solution

The protocol maps |c⟩C|a⟩A\ket{c}_C\ket{a}_A to |c⟩C|a⟩B\ket{c}_C\ket{a}_B (after Bob's correction) for each basis state aa, with the same correction for both terms, since the correction depends only on Alice's outcome. By linearity Charlie and Bob share |β00⟩\ket{\beta_{00}}, though Charlie and Bob never interacted.

More practice: Nielsen–Chuang, Exercises 1.2, 2.69 and 4.33.

SimulationNielsen–Chuang, Ch. 2: Introduction to quantum mechanics

Measurement and density operators

Quantum mechanics predicts probabilities, and probabilities only show up as frequencies over many runs. Measure a prepared state again and again, watch the frequency settle, and find out which preparations no experiment can tell apart.

The idea

The postulates, briefly. A closed system's state is a unit vector in a Hilbert space; it evolves by unitaries; the state space of a composite system is the tensor product. A measurement is a set of operators {Mm}\{M_m\} with ∑mMm†Mm=I\sum_m M_m^\dagger M_m=I: outcome mm has probability p(m)=⟨ψ|Mm†Mm|ψ⟩p(m)=\bra\psi M_m^\dagger M_m\ket\psi and leaves the state Mm|ψ⟩/p(m)M_m\ket\psi/\sqrt{p(m)}.
Projective measurement. An observable A=∑mmPmA=\sum_m m\,P_m (spectral decomposition) is measured by the projectors PmP_m. Its mean is ⟨A⟩=⟨ψ|A|ψ⟩\langle A\rangle=\bra\psi A\ket\psi. For a qubit with Bloch vector r→\vec r, measuring n^⋅σ→\hat n\cdot\vec\sigma gives
p(+1)=1+r→⋅n^2,⟨n^⋅σ→⟩=r→⋅n^.p(+1)=\frac{1+\vec r\cdot\hat n}{2},\qquad \langle \hat n\cdot\vec\sigma\rangle = \vec r\cdot\hat n.
Density operator. If the system is |ψi⟩\ket{\psi_i} with probability pip_i, its state is ρ=∑ipi|ψi⟩⟨ψi|\rho=\sum_i p_i\ket{\psi_i}\bra{\psi_i}: positive with trace 1, and p(m)=tr(Mm†Mmρ)p(m)=\mathrm{tr}(M_m^\dagger M_m\rho). For a qubit,
ρ=12(I+r→⋅σ→),|r→|≤1,pure⟺|r→|=1.\rho=\tfrac12\big(I+\vec r\cdot\vec\sigma\big),\qquad |\vec r|\le1,\qquad \text{pure}\iff|\vec r|=1.
Same ρ\rho, same physics. Every measurement probability depends on the ensemble only through ρ\rho. Two ensembles with the same density operator cannot be told apart by any experiment.
Superposition is not mixture. |+⟩\ket+ and "|0⟩\ket0 or |1⟩\ket1 with probability 12\tfrac12" give the same ZZ statistics. Their density operators differ (r→=(1,0,0)\vec r=(1,0,0) against r→=0\vec r=0), and an XX measurement shows it.

Explore

prepared state r→\vec r measurement axis: outcome +1+1 toward the arrow · drag to turn
Preparation
Measure
frequency of +1+1 so far Born probability, with a band of ±2\pm2 standard deviations

Worked example

A qubit is prepared in |ψ⟩=32|0⟩+12|1⟩\ket\psi=\tfrac{\sqrt3}2\ket0+\tfrac12\ket1 (the "tilted" preparation in the explorer). Predict its ZZ and XX statistics, then check them against its density matrix.

  1. What are the probabilities in the ZZ basis?

    p(0)=3/4p(0)=3/4 and p(1)=1/4p(1)=1/4, so ⟨Z⟩=3/4−1/4=1/2\langle Z\rangle=3/4-1/4=1/2.

  2. What is p(+)p(+) for an XX measurement?

    ⟨+|ψ⟩=12(32+12)\langle+|\psi\rangle=\tfrac1{\sqrt2}\big(\tfrac{\sqrt3}2+\tfrac12\big), so

    p(+)=(3+1)28=2+34≈0.933.p(+)=\frac{(\sqrt3+1)^2}{8}=\frac{2+\sqrt3}{4}\approx0.933.
  3. Find the Bloch vector and confirm p(+)=(1+rx)/2p(+)=(1+r_x)/2.

    cos⁡θ2=32\cos\tfrac\theta2=\tfrac{\sqrt3}2 gives θ=π/3\theta=\pi/3, and φ=0\varphi=0. So r→=(sin⁡π3,0,cos⁡π3)=(32,0,12)\vec r=(\sin\tfrac\pi3,0,\cos\tfrac\pi3)=(\tfrac{\sqrt3}2,0,\tfrac12), and (1+32)/2=(2+3)/4(1+\tfrac{\sqrt3}2)/2=(2+\sqrt3)/4. The zz-component 1/21/2 is ⟨Z⟩\langle Z\rangle, as it should be.

  4. Write ρ\rho and compute tr(ρX)\mathrm{tr}(\rho X).

    ρ=|ψ⟩⟨ψ|=(3/43/43/41/4),tr(ρX)=ρ01+ρ10=32=rx.\rho=\ket\psi\bra\psi=\begin{pmatrix}3/4&\sqrt3/4\\ \sqrt3/4&1/4\end{pmatrix},\qquad \mathrm{tr}(\rho X)=\rho_{01}+\rho_{10}=\frac{\sqrt3}2=r_x.

    In the explorer, run 1000 shots in XX: the frequency should land within about 20.933⋅0.067/1000≈0.0162\sqrt{0.933\cdot0.067/1000}\approx0.016 of 0.933.

Check your understanding

Preparation A: |0⟩\ket0 or |1⟩\ket1, each with probability 12\tfrac12. Preparation B: |+⟩\ket+ or |−⟩\ket-, each with probability 12\tfrac12. Can any measurement tell A from B?

  1. Yes: measure XX. B always gives a definite XX outcome.Each member of B has a definite XX value, but you don't know which member was sent. Try both in the explorer.
  2. Only a measurement on many copies at once.Even joint measurements on many copies see ρ⊗n\rho^{\otimes n}, which is the same for A and B.
  3. No: both have ρ=I/2\rho=I/2.
12(|0⟩⟨0|+|1⟩⟨1|)=12(|+⟩⟨+|+|−⟩⟨−|)=I/2\tfrac12(\ket0\bra0+\ket1\bra1)=\tfrac12(\ket+\bra++\ket-\bra-)=I/2. Probabilities depend only on ρ\rho, so A and B give identical statistics for every measurement.

A qubit has Bloch vector r→\vec r. What is the mean value of the observable n^⋅σ→\hat n\cdot\vec\sigma?

  1. r→⋅n^\vec r\cdot\hat n
  2. (1+r→⋅n^)/2(1+\vec r\cdot\hat n)/2That's the probability of the outcome +1+1. The mean is p(+1)−p(−1)p(+1)-p(-1).
  3. (r→⋅n^)2(\vec r\cdot\hat n)^2Squaring belongs to amplitudes, not to Bloch components.
⟨n^⋅σ→⟩=tr(12(I+r→⋅σ→)n^⋅σ→)=r→⋅n^\langle\hat n\cdot\vec\sigma\rangle=\mathrm{tr}\big(\tfrac12(I+\vec r\cdot\vec\sigma)\,\hat n\cdot\vec\sigma\big)=\vec r\cdot\hat n, using tr(σjσk)=2δjk\mathrm{tr}(\sigma_j\sigma_k)=2\delta_{jk} and trσj=0\mathrm{tr}\,\sigma_j=0.

You measure ZZ on 100 fresh copies of |+⟩\ket+ and get 58 zeros. What should you conclude?

  1. The source is not producing |+⟩\ket+.How big a fluctuation is normal for 100 shots?
  2. Nothing alarming: the count has standard deviation 5, so 58 is 1.6 standard deviations from 50.
  3. Earlier measurements disturbed the later copies.Each shot uses a fresh copy, so earlier outcomes have no effect.
The number of zeros is binomial with n=100n=100, p=12p=\tfrac12: standard deviation np(1−p)=5\sqrt{np(1-p)}=5. Deviations of order n\sqrt n are expected; the explorer's band shows this shrinking like 1/N1/\sqrt N in the frequency.

Practice

Purity on the Bloch ballPure states live on the surface

Show that tr(ρ2)=(1+|r→|2)/2\mathrm{tr}(\rho^2)=(1+|\vec r|^2)/2 for a qubit, and conclude that ρ\rho is pure exactly when |r→|=1|\vec r|=1.

Hint

(r→⋅σ→)2=|r→|2I(\vec r\cdot\vec\sigma)^2=|\vec r|^2I, because the Pauli matrices anticommute and square to II.

Solution

ρ2=14(I+2r→⋅σ→+|r→|2I)\rho^2=\tfrac14\big(I+2\,\vec r\cdot\vec\sigma+|\vec r|^2I\big), and the Paulis are traceless, so trρ2=14(2+2|r→|2)\mathrm{tr}\rho^2=\tfrac14(2+2|\vec r|^2). A density operator is pure iff trρ2=1\mathrm{tr}\rho^2=1 (its eigenvalues are then 1 and 0), i.e. iff |r→|=1|\vec r|=1.

An ensemble on two axesFrom an ensemble to ρ\rho

A source emits |0⟩\ket0 or |+i⟩\ket{+i}, each with probability 12\tfrac12. Find ρ\rho, its Bloch vector, its purity, and the probability of outcome 0 in a ZZ measurement.

Solution

Bloch vectors average: r→=12(0,0,1)+12(0,1,0)=(0,12,12)\vec r=\tfrac12(0,0,1)+\tfrac12(0,1,0)=(0,\tfrac12,\tfrac12). Then

ρ=12(I+r→⋅σ→)=(3/4−i/4i/41/4),\rho=\tfrac12(I+\vec r\cdot\vec\sigma)=\begin{pmatrix}3/4&-i/4\\ i/4&1/4\end{pmatrix},

with purity (1+12)/2=34(1+\tfrac12)/2=\tfrac34, so the state is mixed. p(0)=ρ00=34p(0)=\rho_{00}=\tfrac34, which matches 12⋅1+12⋅12\tfrac12\cdot1+\tfrac12\cdot\tfrac12.

More practice: Nielsen–Chuang, Exercises 2.59, 2.61, 2.71 and 2.72.

InteractiveNielsen–Chuang, Ch. 2: Introduction to quantum mechanics

Entanglement and Bell's inequality

If every measurement result were fixed in advance by shared local information, one combination of correlations, the CHSH quantity SS, could never exceed 2. Entangled qubits reach 222\sqrt2. Turn the four measurement directions and run the experiment.

The idea

Schmidt decomposition. Every pure state of a system ABAB can be written |ψ⟩=∑iλi|iA⟩|iB⟩\ket\psi=\sum_i\lambda_i\ket{i_A}\ket{i_B} with orthonormal |iA⟩\ket{i_A}, orthonormal |iB⟩\ket{i_B}, and λi≥0\lambda_i\ge0, ∑λi2=1\sum\lambda_i^2=1. The state is entangled exactly when more than one λi\lambda_i is nonzero.
Reduced state. Alice's half is described by ρA=trB|ψ⟩⟨ψ|=∑iλi2|iA⟩⟨iA|\rho_A=\mathrm{tr}_B\ket\psi\bra\psi=\sum_i\lambda_i^2\ket{i_A}\bra{i_A}. For a Bell state ρA=I/2\rho_A=I/2: Alice alone sees pure noise.
CHSH inequality. Suppose each run assigns definite values A,A′,B,B′∈{±1}A,A',B,B'\in\{\pm1\} to the four possible measurements, and Alice's choice of setting does not affect Bob's values. Then
A(B−B′)+A′(B+B′)=±2⟹S=E(a,b)−E(a,b′)+E(a′,b)+E(a′,b′)≤2,A(B-B')+A'(B+B')=\pm2\quad\Longrightarrow\quad S=E(a,b)-E(a,b')+E(a',b)+E(a',b')\le 2,

where EE is the average of the product of the two ±1\pm1 results.

The quantum prediction. For |β00⟩\ket{\beta_{00}}, with Alice measuring cos⁡aZ+sin⁡aX\cos a\,Z+\sin a\,X and Bob cos⁡bZ+sin⁡bX\cos b\,Z+\sin b\,X,
E(a,b)=cos⁡(a−b),S=22  at a=0, a′=π2, b=π4, b′=3π4.E(a,b)=\cos(a-b),\qquad S=2\sqrt2\ \text{ at } a=0,\ a'=\tfrac\pi2,\ b=\tfrac\pi4,\ b'=\tfrac{3\pi}4.

222\sqrt2 is the largest value quantum mechanics allows (Tsirelson's bound).

Explore

Source
Drag the four directions (angles from zz toward xx). Alice: a,a′a, a' Bob: b,b′b, b'
Correlation EE against the angle difference. quantum cos⁡Δ\cos\Delta the local model sampled estimates

Worked example

The explorer uses |β00⟩\ket{\beta_{00}}. Work out the correlations of the singlet |β11⟩=(|01⟩−|10⟩)/2\ket{\beta_{11}}=(\ket{01}-\ket{10})/\sqrt2 instead, and find its best CHSH value.

  1. Compute ⟨Z⊗Z⟩\langle Z\otimes Z\rangle, ⟨X⊗X⟩\langle X\otimes X\rangle and ⟨Z⊗X⟩\langle Z\otimes X\rangle in the singlet.

    Z⊗ZZ\otimes Z multiplies both |01⟩\ket{01} and |10⟩\ket{10} by −1-1: mean −1-1. X⊗XX\otimes X swaps |01⟩↔|10⟩\ket{01}\leftrightarrow\ket{10}, turning the singlet into minus itself: mean −1-1. Z⊗XZ\otimes X maps it to (|00⟩+|11⟩)/2(\ket{00}+\ket{11})/\sqrt2, which is orthogonal to it: mean 0. Likewise ⟨X⊗Z⟩=0\langle X\otimes Z\rangle=0.

  2. Expand E(a,b)E(a,b).

    E(a,b)=cos⁡acos⁡b⟨ZZ⟩+sin⁡asin⁡b⟨XX⟩+(cross terms=0)=−cos⁡(a−b).E(a,b)=\cos a\cos b\,\langle ZZ\rangle+\sin a\sin b\,\langle XX\rangle+(\text{cross terms}=0)=-\cos(a-b).

    The singlet is perfectly anticorrelated along every common axis.

  3. Evaluate SS at the settings that give 222\sqrt2 for |β00⟩\ket{\beta_{00}}.

    Every correlation changes sign, so S=−22S=-2\sqrt2. The inequality really bounds |S||S|: local models satisfy −2≤S≤2-2\le S\le2, because A(B−B′)+A′(B+B′)=±2A(B-B')+A'(B+B')=\pm2. Relabelling Bob's outcomes (±1→∓1\pm1\to\mp1) turns the singlet's −22-2\sqrt2 into +22+2\sqrt2.

  4. Where exactly does the local argument fail for quantum systems?

    It assumes all four values A,A′,B,B′A,A',B,B' exist in every run. In the quantum experiment only one setting per side is measured, and cos⁡aZ+sin⁡aX\cos a\,Z+\sin a\,X and cos⁡a′Z+sin⁡a′X\cos a'\,Z+\sin a'\,X don't commute, so there is no joint value of AA and A′A' to plug into the identity.

Check your understanding

Alice and Bob share |β00⟩\ket{\beta_{00}}. Alice measures in some basis of her choice, then Bob measures ZZ. Does Alice's choice change the probabilities Bob sees?

  1. Yes: her measurement collapses his qubit.It collapses to a state that depends on her random outcome. Average over that outcome.
  2. No: Bob's reduced state is I/2I/2 whatever she does.
  3. Only if she measures ZZ too.Then the outcomes are correlated, but Bob's own frequencies are still 50/50.
Operations on Alice's qubit can't change ρB=trAρ\rho_B=\mathrm{tr}_A\rho. Entanglement shows up in correlations, which need both records to be compared; it can't be used to signal.

Point all four directions along zz (a=a′=b=b′a=a'=b=b'). What is SS for |β00⟩\ket{\beta_{00}}?

  1. 0Every correlation is cos⁡0=1\cos 0=1 here, not 0; only the signs in SS can cancel them.
  2. 2
  3. 4One of the four terms enters with a minus sign.
  4. 222\sqrt2That needs the directions spread out by 45∘45^\circ steps.
All four correlations are cos⁡0=1\cos0=1, so S=1−1+1+1=2S=1-1+1+1=2. Perfect correlation along one axis is easy to fake classically. Press "All along z" and compare the two sources.

An experiment measures S=2.7±0.05S=2.7\pm0.05. What has it ruled out?

  1. Quantum mechanics.Quantum mechanics predicts values up to 22≈2.832\sqrt2\approx2.83.
  2. Every model in which outcomes are fixed by shared local variables and neither side's setting affects the other's result.
  3. Entanglement between the two qubits.The other way around: unentangled (separable) states always satisfy |S|≤2|S|\le2, so a violation certifies entanglement.
The CHSH bound uses only the two assumptions in the correct answer, plus free choice of settings. A violation means at least one of them fails in nature.

Practice

Four terms, two in disguiseA Schmidt decomposition

Find the Schmidt decomposition and ρA\rho_A for |ψ⟩=12(|00⟩+|01⟩+|10⟩−|11⟩)\ket\psi=\tfrac12(\ket{00}+\ket{01}+\ket{10}-\ket{11}).

Hint

Group the terms by the first qubit.

Solution

|ψ⟩=12(|0⟩|+⟩+|1⟩|−⟩)\ket\psi=\tfrac1{\sqrt2}\big(\ket0\ket++\ket1\ket-\big). This is a Schmidt form with λ1=λ2=1/2\lambda_1=\lambda_2=1/\sqrt2, so the state is maximally entangled and ρA=I/2\rho_A=I/2. (Its amplitude matrix is H/2H/\sqrt2, and 12HH†=I/2\tfrac12HH^\dagger=I/2.)

Product states obey CHSHNo entanglement, no violation

Show that |S|≤2|S|\le2 for every product state |α⟩|β⟩\ket\alpha\ket\beta, whatever the four settings.

Hint

For a product state, E(a,b)=⟨A⟩⟨B⟩E(a,b)=\langle A\rangle\langle B\rangle. Use |x−y|+|x+y|=2max⁡(|x|,|y|)|x-y|+|x+y|=2\max(|x|,|y|).

Solution

With ⟨A⟩,⟨A′⟩,⟨B⟩,⟨B′⟩∈[−1,1]\langle A\rangle,\langle A'\rangle,\langle B\rangle,\langle B'\rangle\in[-1,1],

|S|=|⟨A⟩(⟨B⟩−⟨B′⟩)+⟨A′⟩(⟨B⟩+⟨B′⟩)|≤|⟨B⟩−⟨B′⟩|+|⟨B⟩+⟨B′⟩|≤2.|S|=\big|\langle A\rangle(\langle B\rangle-\langle B'\rangle)+\langle A'\rangle(\langle B\rangle+\langle B'\rangle)\big|\le|\langle B\rangle-\langle B'\rangle|+|\langle B\rangle+\langle B'\rangle|\le2.

Mixtures of product states inherit the bound, since SS is linear in ρ\rho.

More practice: Nielsen–Chuang, Exercises 2.75, 2.78 and 2.79.

Worked examplesNielsen–Chuang, Ch. 3: Introduction to computer science

Reversible computation and complexity

A quantum computer evolves by unitaries, so whatever it computes it must compute reversibly. Classical logic can be made reversible at modest cost, which is why a quantum computer can run any classical algorithm, and the scratch work has to be cleaned up afterwards.

The idea

Circuits. A Boolean circuit is built from gates such as AND, OR, NOT, with wires that can be copied (FANOUT). NAND alone, with FANOUT, is universal: it can build every Boolean function.
Toffoli gate. (a,b,c)↦(a,b,c⊕︎ab)(a,b,c)\mapsto(a,\,b,\,c\oplus ab). It is a permutation of the 8 inputs and its own inverse. With c=1c=1 it outputs NAND; with a=b=1a=b=1 it is NOT on cc; with a=1,c=0a=1,c=0 it copies bb. So reversible circuits can compute anything.
Landauer's principle. Erasing one bit of information in an environment at temperature TT dissipates at least kBTln⁡2k_BT\ln2 of heat. Reversible gates erase nothing, so in principle they need not dissipate.
Uncomputation (Bennett). A reversible circuit for ff leaves garbage: (x,0,0)↦(x,g(x),f(x))(x,0,0)\mapsto(x,g(x),f(x)). Copy f(x)f(x) into a fresh register with CNOTs, then run the circuit backwards. The result is (x,0,0,f(x))(x,0,0,f(x)), at about twice the gate count.
Complexity classes. P: decided in polynomial time. NP: "yes" answers can be checked in polynomial time. BPP: decided by a randomised polynomial algorithm with error at most 1/3. BQP: the same for quantum circuits. Known: P⊆BPP⊆BQP⊆PSPACE\mathrm P\subseteq\mathrm{BPP}\subseteq\mathrm{BQP}\subseteq\mathrm{PSPACE}. Whether any of these inclusions is strict is open.
Not a shortcut to NP. Factoring is in BQP (Shor) but is not believed to be NP-complete, and there is no known efficient quantum algorithm for NP-complete problems.

Worked example

Build a reversible circuit that computes y=x1x2x3y=x_1x_2x_3 (AND of three bits) into a target bit, using Toffoli gates and one scratch bit ww, and leave the scratch bit clean. Then see why the cleaning matters quantum mechanically.

  1. One Toffoli computes the AND of two bits. How?

    Toffoli(x1,x2;w)(x_1,x_2;w) with w=0w=0 gives w=0⊕︎x1x2=x1x2w=0\oplus x_1x_2=x_1x_2.

  2. Now get x1x2x3x_1x_2x_3 into the target yy (initially 0).

    Toffoli(w,x3;y)(w,x_3;y) gives y=x1x2x3y=x_1x_2x_3. The scratch bit ww still holds x1x2x_1x_2: this is garbage.

  3. Why is the garbage harmful on a quantum computer?

    On a superposition of inputs the circuit produces ∑xcx|x⟩|w(x)⟩|f(x)⟩\sum_x c_x\ket x\ket{w(x)}\ket{f(x)} instead of ∑xcx|x⟩|0⟩|f(x)⟩\sum_x c_x\ket x\ket0\ket{f(x)}. The garbage register is entangled with the input. Tracing it out leaves the rest in a mixed state, and the interference that a quantum algorithm relies on is lost.

  4. Clean up ww.

    Apply Toffoli(x1,x2;w)(x_1,x_2;w) once more: w↦x1x2⊕︎x1x2=0w\mapsto x_1x_2\oplus x_1x_2=0. Nothing it depends on (x1,x2x_1,x_2) has changed, so the uncomputation is exact. The circuit is three Toffolis, and its output is (x1,x2,x3,w=0,y=x1x2x3)(x_1,x_2,x_3,\,w=0,\,y=x_1x_2x_3).

  5. Generalise to the AND of nn bits. How many Toffolis and scratch bits?

    Chain the partial ANDs x1x2, x1x2x3, …x_1x_2,\ x_1x_2x_3,\ \dots into n−2n-2 scratch bits, with the last Toffoli writing into the target: n−1n-1 gates. Uncompute the n−2n-2 scratch bits in reverse order: n−2n-2 more. Total 2n−32n-3 Toffolis and n−2n-2 clean scratch bits; for n=3n=3, three Toffolis and one scratch bit, as above.

  6. What does Landauer's principle say about the ordinary irreversible AND gate on uniformly random inputs?

    The input carries 2 bits of entropy. The output is 1 with probability 1/41/4, so it carries H(1/4)≈0.811H(1/4)\approx0.811 bits. The gate erases about 2−0.811=1.192-0.811=1.19 bits, so it must dissipate at least 1.19kBTln⁡21.19\,k_BT\ln2 per use. The reversible version keeps x1,x2x_1,x_2, erases nothing, and has no such floor.

Check your understanding

A Toffoli gate gets inputs (a,b,1)(a,b,1). What is its third output?

  1. a∧ba\wedge bThe target starts at 1, so it becomes 1⊕︎ab1\oplus ab.
  2. ¬(a∧b)\neg(a\wedge b), the NAND
  3. a⊕︎ba\oplus bToffoli multiplies the controls; XOR would need two CNOTs.
1⊕︎ab1\oplus ab is 0 exactly when a=b=1a=b=1. Since NAND is universal, so is Toffoli, with constant inputs and spare outputs allowed.

Why must every gate in a quantum circuit be reversible?

  1. Closed quantum evolution is unitary, and unitaries are invertible.
  2. To avoid Landauer heat, which would destroy the qubits.Heat is a practical concern; the requirement is more basic than that.
  3. Because of the no-cloning theorem.No-cloning forbids copying unknown states; reversibility comes from unitarity itself.
A unitary UU has inverse U†U^\dagger. Irreversible steps (such as a reset) are possible only by involving an environment or a measurement, which is not a gate on the qubits alone.

Which of these is known to be true?

  1. BPP⊆BQP⊆PSPACE\mathrm{BPP}\subseteq\mathrm{BQP}\subseteq\mathrm{PSPACE}
  2. NP ⊆\subseteq BQPOpen, and widely doubted: search gives only a square-root speed-up for unstructured problems.
  3. Factoring is NP-completeFactoring (as a decision problem) lies in NP ∩ co-NP, which makes NP-completeness unlikely.
A quantum circuit can simulate coin flips, giving BPP ⊆ BQP. A classical machine can add up the amplitudes of all paths through a quantum circuit using polynomial space, giving BQP ⊆ PSPACE.

Practice

A reversible ORDe Morgan with a Toffoli

Using one Toffoli and some NOT gates, compute a∨ba\vee b into a target bit and leave a,ba,b unchanged.

Hint

a∨b=¬(¬a∧¬b)a\vee b=\neg(\neg a\wedge\neg b).

Solution

NOT aa and bb, apply Toffoli onto a target that starts at 1 (giving 1⊕︎a‾b‾=a∨b1\oplus\bar a\bar b=a\vee b), then NOT aa and bb again to restore them.

The Fredkin gateControlled swap

The Fredkin gate swaps its second and third bits when the first is 1. Show it never changes the number of 1s, and use it with constant inputs to compute AND and NOT.

Solution

It either does nothing or swaps two bits, so the count of 1s is unchanged. Input (a,b,0)(a,b,0): if a=1a=1 the output is (1,0,b)(1,0,b), otherwise (0,b,0)(0,b,0); the third output is abab. Input (a,0,1)(a,0,1): if a=1a=1 the output is (1,1,0)(1,1,0), otherwise (0,0,1)(0,0,1); the third output is ¬a\neg a, and the second is a copy of aa.

More practice: Nielsen–Chuang, Exercises 3.29, 3.31 and 3.32.

SimulatorNielsen–Chuang, Ch. 4: Quantum circuits

Quantum circuits

Single-qubit gates and CNOT are enough to build any unitary. Put gates on three wires and watch all eight amplitudes change, column by column. Entanglement shows up as a qubit whose own state is no longer pure.

The idea

Many qubits. nn qubits have 2n2^n amplitudes, one for each bit string. Here |q1q2q3⟩\ket{q_1q_2q_3} lists the wires top to bottom. A gate UU on wire kk acts as I⊗⋯⊗U⊗⋯⊗II\otimes\cdots\otimes U\otimes\cdots\otimes I.
Controlled gates. Controlled-UU maps |c⟩|t⟩↦|c⟩Uc|t⟩\ket c\ket t\mapsto\ket c\,U^c\ket t. CNOT is controlled-XX; CZ is controlled-ZZ, which multiplies |11⟩\ket{11} by −1-1 and is symmetric in its two qubits.
Universality. CNOT and all one-qubit gates generate every unitary exactly. The finite set {H,S,T,CNOT}\{H, S, T, \mathrm{CNOT}\} approximates any unitary to accuracy ε\varepsilon, and by the Solovay–Kitaev theorem a one-qubit gate costs only O(logc⁡(1/ε))O(\log^c(1/\varepsilon)) gates from the set, for a constant cc near 2.
Phase kickback. If the target is an eigenvector, U|u⟩=eiϕ|u⟩U\ket u=e^{i\phi}\ket u, then controlled-UU sends (a|0⟩+b|1⟩)|u⟩↦(a|0⟩+eiϕb|1⟩)|u⟩(a\ket0+b\ket1)\ket u\mapsto(a\ket0+e^{i\phi}b\ket1)\ket u. The phase lands on the control. With CNOT and |u⟩=|−⟩\ket u=\ket-, ϕ=π\phi=\pi.
Exponential bookkeeping. A simulator like the one below stores 2n2^n numbers. That is easy for 3 qubits and hopeless for 300, which is part of why quantum computers might be powerful.

Explore

Gate to place
Load a circuit
Click a cell to place the gate. For CNOT and CZ, click the control, then the target in the same column. Click a gate again to remove it.
Bar height: probability |cx|2|c_x|^2. The dial above each bar shows the amplitude cxc_x as an arrow in the complex plane (pointing right means positive real).

Worked example

Load "Deutsch–Jozsa" in the simulator. It tests whether f:{0,1}2→{0,1}f:\{0,1\}^2\to\{0,1\} is constant or balanced with one call to the oracle |x⟩|y⟩↦|x⟩|y⊕︎f(x)⟩\ket x\ket y\mapsto\ket x\ket{y\oplus f(x)}, here for f(x1,x2)=x1⊕︎x2f(x_1,x_2)=x_1\oplus x_2, built from two CNOTs into the third wire. Work through the circuit by hand.

  1. After XX on wire 3 and HH on all three wires, what is the state?

    |+⟩|+⟩|−⟩=12∑x∈{0,1}2|x⟩⊗|−⟩\ket+\ket+\ket-=\tfrac12\sum_{x\in\{0,1\}^2}\ket x\otimes\ket-.

  2. What does the oracle do to |x⟩|−⟩\ket x\ket-?

    |x⟩(|f(x)⟩−|1⊕︎f(x)⟩)/2=(−1)f(x)|x⟩|−⟩\ket x\big(\ket{f(x)}-\ket{1\oplus f(x)}\big)/\sqrt2=(-1)^{f(x)}\ket x\ket-: phase kickback. So the state becomes

    12(|00⟩−|01⟩−|10⟩+|11⟩)|−⟩=|−⟩|−⟩|−⟩.\tfrac12\big(\ket{00}-\ket{01}-\ket{10}+\ket{11}\big)\ket-=\ket-\ket-\ket-.
  3. Apply HH to wires 1 and 2. What is measured?

    H|−⟩=|1⟩H\ket-=\ket1, so the result is |11⟩|−⟩\ket{11}\ket-: wires 1 and 2 read 1111 with certainty. The simulator shows probability 12\tfrac12 on each of |110⟩\ket{110} and |111⟩\ket{111} because wire 3 is |−⟩\ket-.

  4. What would a constant ff give, and why does this decide the question?

    For constant ff the kickback is a global sign, the first two wires stay |++⟩\ket{++}, and the final HHs return |00⟩\ket{00}. For any balanced ff, the amplitude of |00⟩\ket{00} after the final HHs is 14∑x(−1)f(x)=0\tfrac14\sum_x(-1)^{f(x)}=0. So "00" means constant and anything else means balanced. Remove one CNOT from the oracle (it becomes f=x1f=x_1 or x2x_2, still balanced) and check that 00 still never appears.

Check your understanding

In a CZ gate, which qubit is the control?

  1. The top one, by convention.Write out its matrix and swap the qubits.
  2. Either: CZ is symmetric.
  3. The one in state |1⟩\ket1.Control is a role in the circuit, not a property of the state.
CZ =diag(1,1,1,−1)=\mathrm{diag}(1,1,1,-1): it multiplies |11⟩\ket{11} by −1-1 and leaves the rest alone, which doesn't distinguish the qubits. Even for CNOT the roles depend on basis: in the |±⟩\ket\pm basis, control and target swap.

HH on wire 1 then CNOT 1→2 turns |00⟩\ket{00} into a Bell state. What if the CNOT comes first and the HH second?

  1. The same Bell state.Look at what the CNOT does when its control is |0⟩\ket0.
  2. The product state |+⟩|0⟩\ket+\ket0.
  3. A different Bell state.No entangling step acts on a superposition, so no entanglement can appear.
With control |0⟩\ket0 the CNOT does nothing, and then HH just makes |+⟩|0⟩\ket+\ket0. Gates don't commute in general, so order matters; try both in the simulator and look at the purities.

Control in |+⟩\ket+, target in |−⟩\ket-. What does a CNOT produce?

  1. |+⟩|−⟩\ket+\ket-, unchanged.The target is unchanged. The control is not.
  2. |−⟩|−⟩\ket-\ket-
  3. An entangled state.The target is an eigenvector of XX, so the output stays a product.
X|−⟩=−|−⟩X\ket-=-\ket-, so CNOT|x⟩|−⟩=(−1)x|x⟩|−⟩\,\ket x\ket-=(-1)^x\ket x\ket-. The control picks up the relative sign: |+⟩↦|−⟩\ket+\mapsto\ket-. This is phase kickback, the engine of Deutsch–Jozsa and phase estimation.

Practice

Three-qubit GHZ stateEntangled, but each pair is not

Give a circuit that makes (|000⟩+|111⟩)/2(\ket{000}+\ket{111})/\sqrt2 from |000⟩\ket{000}. Then trace out qubit 3 and decide whether qubits 1 and 2 are entangled with each other.

Solution

HH on wire 1, then CNOT 1→2 and CNOT 2→3 (the "GHZ" preset). Tracing out qubit 3 gives ρ12=12(|00⟩⟨00|+|11⟩⟨11|)\rho_{12}=\tfrac12(\ket{00}\bra{00}+\ket{11}\bra{11}), a classical mixture of product states: perfectly correlated, but not entangled. Each single qubit has purity 12\tfrac12, the minimum.

Kickback from controlled-SReading off an eigenvalue

A controlled-SS gate has its control in |+⟩\ket+ and its target in |1⟩\ket1. What is the output, and how could you tell the phase from a measurement of the control?

Hint

|1⟩\ket1 is an eigenvector of SS. With which eigenvalue?

Solution

S|1⟩=i|1⟩S\ket1=i\ket1, so the output is 12(|0⟩+i|1⟩)|1⟩=|+i⟩|1⟩\tfrac1{\sqrt2}(\ket0+i\ket1)\ket1=\ket{+i}\ket1. Measuring the control in the YY basis gives +1+1 with certainty; in the XX basis it gives each outcome half the time. Phase estimation generalises this: controlled powers of UU write the eigenphase into a register, and an inverse Fourier transform reads it out.

More practice: Nielsen–Chuang, Exercises 4.13, 4.17 and 4.20.

SimulationNielsen–Chuang, Ch. 5: The quantum Fourier transform and its applications

Fourier transform and period finding

Shor's algorithm turns factoring into finding the period of x↦axmodNx\mapsto a^x\bmod N. The quantum Fourier transform turns a periodic superposition into sharp peaks, and a short continued-fraction calculation reads the period off one measurement. Here it is for N=15N=15 and N=21N=21.

The idea

Quantum Fourier transform. On tt qubits, with Q=2tQ=2^t,
|j⟩ ⟼ 1Q∑k=0Q−1e2πijk/Q|k⟩.\ket j\ \longmapsto\ \frac1{\sqrt Q}\sum_{k=0}^{Q-1}e^{2\pi i\,jk/Q}\ket k.

It is unitary and needs only O(t2)O(t^2) gates (Hadamards and controlled phase rotations), against O(t2t)O(t\,2^t) steps for the classical fast Fourier transform of 2t2^t numbers. The catch: the output amplitudes can't be read, only sampled.

Order. For aa coprime to NN, the order rr is the least r>0r>0 with ar≡1(modN)a^r\equiv1\pmod N.
From order to factors. If rr is even and ar/2≢−1(modN)a^{r/2}\not\equiv-1\pmod N, then gcd⁡(ar/2−1,N)\gcd(a^{r/2}-1,N) and gcd⁡(ar/2+1,N)\gcd(a^{r/2}+1,N) are nontrivial factors of NN. For odd NN that isn't a prime power, a random aa works with probability at least 1/21/2.
Order finding. Prepare 1Q∑x|x⟩|axmodN⟩\frac1{\sqrt Q}\sum_x\ket x\ket{a^x\bmod N}, apply the QFT to the first register and measure it, getting yy. Then y/Qy/Q is close to s/rs/r for a uniformly random s∈{0,…,r−1}s\in\{0,\dots,r-1\}. If Q≥N2Q\ge N^2, the fraction s/rs/r (in lowest terms) is one of the continued-fraction convergents of y/Qy/Q.
Lowest terms. If gcd⁡(s,r)>1\gcd(s,r)>1, continued fractions return a proper divisor of rr. Check whether aq≡1a^q\equiv1; if not, try small multiples of qq or run again.

Explore

N
Base a
P(y)P(y) after the QFT the ideal peak positions sQ/rsQ/r your measured yy

Worked example

Factor N=21N=21 with a=2a=2 and t=9t=9 counting qubits (Q=512≥212=441Q=512\ge21^2=441). Set the explorer to the same values to follow along.

  1. What is the order of 2 modulo 21? (The quantum computer finds this; we check it by hand.)

    2,4,8,16,32≡11,22≡12,4,8,16,32\equiv11,22\equiv1. So r=6r=6.

  2. Where are the peaks of P(y)P(y)?

    Near y=sQ/r=512s/6y=sQ/r=512s/6: 0, 85.3, 170.7, 256, 341.3, 426.70,\ 85.3,\ 170.7,\ 256,\ 341.3,\ 426.7. Since 6 doesn't divide 512, the peaks spill onto neighbouring yy.

  3. Suppose the measurement gives y=427y=427. Expand 427/512427/512 as a continued fraction and list the convergents.

    512=1⋅427+85, 427=5⋅85+2, 85=42⋅2+1, 2=2⋅1512=1\cdot427+85,\ 427=5\cdot85+2,\ 85=42\cdot2+1,\ 2=2\cdot1, so 427/512=[0;1,5,42,2]427/512=[0;1,5,42,2], with convergents

    01,11,56,211253,427512.\tfrac01,\quad\tfrac11,\quad\tfrac56,\quad\tfrac{211}{253},\quad\tfrac{427}{512}.

    The last convergent with denominator below N=21N=21 is 5/65/6, so the candidate is r=6r=6. Check: 26=64=3⋅21+12^6=64=3\cdot21+1.

  4. Turn r=6r=6 into factors.

    rr is even and 23=8≢−1(mod21)2^{3}=8\not\equiv-1\pmod{21}. Then gcd⁡(8−1,21)=7\gcd(8-1,21)=7 and gcd⁡(8+1,21)=3\gcd(8+1,21)=3, and 21=3⋅721=3\cdot7.

  5. What if the measurement had given y=341y=341?

    341/512=[0;1,1,1,170]341/512=[0;1,1,1,170], convergents 0, 1, 12, 23, 3415120,\ 1,\ \tfrac12,\ \tfrac23,\ \tfrac{341}{512}. The candidate is q=3q=3, but 23=8≢12^3=8\not\equiv1. Here s=4s=4 shares the factor 2 with r=6r=6, and 4/64/6 reduced to 2/32/3. Trying the multiple 2q=62q=6 works.

Check your understanding

N=15N=15, a=7a=7 (order 4), Q=256Q=256. Which outcomes yy can occur?

  1. Any yy, with peaks near multiples of 64.When rr divides QQ the cancellation away from the peaks is exact.
  2. Only 0,64,128,1920, 64, 128, 192, each with probability 1/41/4.
  3. Only y=64y=64, which gives r=4r=4 directly.ss is uniformly random in {0,1,2,3}\{0,1,2,3\}, so all four peaks are equally likely.
With r|Qr\mid Q, the sum ∑ke2πikry/Q\sum_k e^{2\pi i\,kry/Q} is zero unless ry/Qry/Q is an integer, i.e. yy is a multiple of Q/r=64Q/r=64. Only y=64y=64 and y=192y=192 (ss odd, coprime to 4) give rr directly; y=128y=128 gives 1/21/2.

You measure y=0y=0. What do you learn?

  1. Nothing: 0/Q=0/10/Q=0/1, the candidate order is 1, and you run again.
  2. That r=Qr=Q.The order is at most NN, far below QQ.
  3. That aa is a bad choice.y=0y=0 (that is, s=0s=0) has probability about 1/r1/r for every aa.
The s=0s=0 peak always exists and carries no information about rr. It is one reason the algorithm is repeated a few times.

Why take Q≥N2Q\ge N^2?

  1. The QFT only works when QQ is a perfect square.The QFT works for every Q=2tQ=2^t.
  2. Then |y/Q−s/r|≤1/(2Q)≤1/(2r2)|y/Q-s/r|\le1/(2Q)\le1/(2r^2), which guarantees s/rs/r is a convergent of y/Qy/Q.
  3. To make the peaks wider and easier to hit.Larger QQ makes the peaks narrower relative to their spacing.
A classical theorem: if |x−s/r|≤1/(2r2)|x-s/r|\le1/(2r^2), then s/rs/r is a convergent of xx. With r<Nr<N and Q≥N2Q\ge N^2 the peaks are sharp enough. Lower tt in the explorer and watch the continued fractions start to fail.

Practice

The four-point transformQFT by hand

Write the matrix of the QFT for Q=4Q=4, check that for Q=2Q=2 it is HH, and show that applying the Q=4Q=4 transform twice sends |j⟩\ket j to |−jmod4⟩\ket{-j\bmod4}.

Solution

With ω=e2πi/4=i\omega=e^{2\pi i/4}=i, the entries are ωjk/2\omega^{jk}/2:

F4=12(11111i−1−i1−11−11−i−1i),F2=12(111−1)=H.F_4=\frac12\begin{pmatrix}1&1&1&1\\1&i&-1&-i\\1&-1&1&-1\\1&-i&-1&i\end{pmatrix},\qquad F_2=\tfrac1{\sqrt2}\begin{pmatrix}1&1\\1&-1\end{pmatrix}=H.

(F2)jl=1Q∑kωk(j+l)(F^2)_{jl}=\tfrac1Q\sum_k\omega^{k(j+l)}, which is 1 when j+l≡0(modQ)j+l\equiv0\pmod Q and 0 otherwise. So F2|l⟩=|−l⟩F^2\ket l=\ket{-l}, and F4=IF^4=I.

Exact peaksWhy r|Qr\mid Q gives a clean comb

Let rr divide QQ and |ϕ⟩=r/Q∑k=0Q/r−1|x0+kr⟩\ket\phi=\sqrt{r/Q}\sum_{k=0}^{Q/r-1}\ket{x_0+kr}. Show that the QFT of |ϕ⟩\ket\phi is 1r∑s=0r−1e2πix0s/r|sQ/r⟩\frac1{\sqrt r}\sum_{s=0}^{r-1}e^{2\pi i\,x_0s/r}\ket{sQ/r}.

Hint

The amplitude of |y⟩\ket y contains the geometric sum ∑ke2πikry/Q\sum_k e^{2\pi i\,kry/Q}.

Solution

The amplitude of |y⟩\ket y is rQe2πix0y/Q∑k=0Q/r−1e2πikry/Q\frac{\sqrt r}{Q}e^{2\pi i x_0y/Q}\sum_{k=0}^{Q/r-1}e^{2\pi i\,kry/Q}. The sum is Q/rQ/r if ry/Q∈ℤry/Q\in\Z, i.e. y=sQ/ry=sQ/r, and 0 otherwise. At y=sQ/ry=sQ/r the amplitude is rQ⋅Qre2πix0s/r=1re2πix0s/r\frac{\sqrt r}{Q}\cdot\frac Qr\,e^{2\pi i x_0s/r}=\frac1{\sqrt r}e^{2\pi ix_0s/r}. The offset x0x_0 only affects phases, so measuring axmodNa^x\bmod N first changes nothing about P(y)P(y).

More practice: Nielsen–Chuang, Exercises 5.10, 5.18 and 5.19.

InteractiveNielsen–Chuang, Ch. 6: Quantum search algorithms

Grover search as a rotation

Each Grover iteration is two reflections, and two reflections make a rotation. In the plane spanned by "marked" and "unmarked", the state turns by a fixed angle each step, so about π4N/M\tfrac\pi4\sqrt{N/M} steps reach a marked item, and further steps overshoot.

The idea

Oracle. O|x⟩=(−1)f(x)|x⟩O\ket x=(-1)^{f(x)}\ket x, where f(x)=1f(x)=1 for the MM marked items out of N=2nN=2^n. (A bit-flip oracle with its output qubit in |−⟩\ket- acts this way, by phase kickback.)
Grover iteration. G=(2|ψ⟩⟨ψ|−I)OG=(2\ket\psi\bra\psi-I)\,O, where |ψ⟩=H⊗n|0⟩\ket\psi=H^{\otimes n}\ket0 is the uniform superposition. The second factor, the diffusion, maps each amplitude cxc_x to 2c‾−cx2\bar c-c_x: an inversion about the mean.
The geometry. Let |α⟩\ket\alpha and |β⟩\ket\beta be the uniform superpositions of unmarked and marked items. Then |ψ⟩=cos⁡θ2|α⟩+sin⁡θ2|β⟩\ket\psi=\cos\tfrac\theta2\ket\alpha+\sin\tfrac\theta2\ket\beta with sin⁡θ2=M/N\sin\tfrac\theta2=\sqrt{M/N}. OO reflects about |α⟩\ket\alpha, the diffusion reflects about |ψ⟩\ket\psi, and together they rotate by θ\theta:
Gk|ψ⟩=cos⁡(2k+1)θ2|α⟩+sin⁡(2k+1)θ2|β⟩,Psuccess=sin2⁡(2k+1)θ2.G^k\ket\psi=\cos\tfrac{(2k+1)\theta}2\ket\alpha+\sin\tfrac{(2k+1)\theta}2\ket\beta,\qquad P_{\text{success}}=\sin^2\tfrac{(2k+1)\theta}2.
Optimality. Any quantum algorithm that finds a marked item with high probability needs Ω(N/M)\Omega(\sqrt{N/M}) oracle calls, so Grover's algorithm is optimal up to a constant factor.

Explore

the state |ψ⟩\ket\psi, the start the mirror of the last reflection
Success probability after kk iterations. where you are now

Worked example

Search N=16N=16 items with one marked item, tracking the actual amplitudes. (Set n=4n=4, M=1M=1 in the explorer.)

  1. What is θ\theta, and what does the formula predict for k=1,2,3,4k=1,2,3,4?

    sin⁡θ2=14\sin\tfrac\theta2=\tfrac14, so θ2≈14.48∘\tfrac\theta2\approx14.48^\circ. The success probabilities sin2⁡((2k+1)⋅14.48∘)\sin^2\big((2k+1)\cdot14.48^\circ\big) are 0.473, 0.908, 0.961, 0.5820.473,\ 0.908,\ 0.961,\ 0.582. Best is k=3k=3, close to π416≈3.1\tfrac\pi4\sqrt{16}\approx3.1.

  2. Do the first iteration with amplitudes. All 16 start at 14\tfrac14.

    Oracle: the marked amplitude becomes −14-\tfrac14. The mean is (15⋅14−14)/16=0.21875(15\cdot\tfrac14-\tfrac14)/16=0.21875. Inversion about the mean: unmarked 2(0.21875)−0.25=0.18752(0.21875)-0.25=0.1875; marked 2(0.21875)+0.25=0.68752(0.21875)+0.25=0.6875. Probability 0.68752=0.4730.6875^2=0.473, as predicted.

  3. Do the second and third iterations.

    Second: mean (15⋅0.1875−0.6875)/16=0.1328(15\cdot0.1875-0.6875)/16=0.1328; unmarked 0.07810.0781, marked 0.95310.9531, probability 0.9080.908. Third: mean (15⋅0.0781−0.9531)/16=0.0137(15\cdot0.0781-0.9531)/16=0.0137; unmarked −0.0508-0.0508, marked 0.98050.9805, probability 0.9610.961.

  4. The unmarked amplitudes just went negative. What does that tell you?

    The state has rotated past |β⟩\ket\beta: its |α⟩\ket\alpha-component is now negative. A fourth iteration moves it further from |β⟩\ket\beta, and the probability drops to 0.5820.582. A classical search with 3 queries succeeds with probability only 3/163/16, or 4/164/16 if you guess one of the unchecked items at the end.

Check your understanding

N=220≈106N=2^{20}\approx10^6, one marked item. Roughly how many iterations give the best chance of success?

  1. About 20That's log2⁡N\log_2N. Search is quadratically faster than classical, not exponentially.
  2. About 800
  3. About 500,000That's the average for a classical search.
π4220=π4⋅1024≈804\tfrac\pi4\sqrt{2^{20}}=\tfrac\pi4\cdot1024\approx804. Each iteration rotates by θ≈2/N\theta\approx2/\sqrt N, and the state has to turn through about π/2\pi/2.

You run twice the optimal number of iterations. The success probability is then

  1. close to 1, since extra iterations can't hurt.The iteration is a rotation, and it keeps turning past |β⟩\ket\beta.
  2. close to 0.
  3. about 1/2.After twice the optimum the angle is close to π\pi, not 3π/43\pi/4.
The optimum puts the angle near π/2\pi/2; twice as many steps put it near π\pi, that is, near −|α⟩-\ket\alpha, where the marked amplitude is almost zero. Try "Run to the best k", then keep pressing "Full iteration".

What does the oracle step alone do to the measurement probabilities?

  1. It raises the probability of the marked items.It only flips the sign of their amplitudes.
  2. Nothing: it changes signs, and probabilities are squared magnitudes.
  3. It sets the marked amplitudes to zero.A unitary can't destroy amplitude; it reflects it.
On its own the sign flip is invisible to a computational-basis measurement. The diffusion step turns the sign difference into a size difference. Press Oracle alone in the explorer and watch the probability readout.

Practice

Eight itemsChoosing the number of iterations

For N=8N=8 and M=1M=1, find θ\theta, the best number of iterations, and its success probability.

Solution

sin⁡θ2=1/8\sin\tfrac\theta2=1/\sqrt8 gives θ2≈20.7∘\tfrac\theta2\approx20.7^\circ. The angles (2k+1)θ/2(2k+1)\theta/2 are 62.1∘,103.5∘,144.9∘62.1^\circ, 103.5^\circ, 144.9^\circ for k=1,2,3k=1,2,3, with probabilities 0.781,0.945,0.3300.781, 0.945, 0.330. Best is k=2k=2, at about 94.5%94.5\%.

A quarter markedCertainty in one step

Show that if exactly a quarter of the items are marked, one Grover iteration finds a marked item with certainty.

Solution

sin⁡θ2=1/4=12\sin\tfrac\theta2=\sqrt{1/4}=\tfrac12, so θ2=30∘\tfrac\theta2=30^\circ and after one iteration the angle is 3⋅30∘=90∘3\cdot30^\circ=90^\circ: the state is exactly |β⟩\ket\beta. (With amplitudes: after the oracle the mean is 12N\tfrac1{2\sqrt N}, so unmarked amplitudes 1N\tfrac1{\sqrt N} become 0.)

More practice: Nielsen–Chuang, Exercises 6.2 and 6.3.

InteractiveNielsen–Chuang, Ch. 7: Quantum computers: physical realization

Driving a qubit: Rabi oscillations

In NMR, ion traps and cavity QED, a gate is a pulse of radiation of a chosen length. On resonance the qubit swings all the way from |0⟩\ket0 to |1⟩\ket1 and back. Off resonance it precesses about a tilted axis and never fully flips, which is one way real gates go wrong.

The idea

What a physical qubit needs. A robust way to represent quantum information, a way to perform a universal set of unitaries, a way to prepare a known initial state, and a way to measure the result, all with decoherence slow compared with the gates.
Driven two-level system. In a frame rotating with the drive, a qubit driven with Rabi frequency Ω\Omega and detuning Δ\Delta (drive frequency minus qubit frequency, up to sign convention) has, with ℏ=1\hbar=1,
H=Δ2Z+Ω2X.H=\tfrac\Delta2\,Z+\tfrac\Omega2\,X.
Rabi formula. e−iHte^{-iHt} rotates the Bloch vector about n^=(Ω,0,Δ)/Ω′\hat n=(\Omega,0,\Delta)/\Omega' at angular speed Ω′=Ω2+Δ2\Omega'=\sqrt{\Omega^2+\Delta^2}. Starting in |0⟩\ket0,
P1(t)=Ω2Ω2+Δ2sin2⁡(Ω′t2).P_1(t)=\frac{\Omega^2}{\Omega^2+\Delta^2}\,\sin^2\!\Big(\frac{\Omega' t}2\Big).

On resonance a pulse of area Ωt=π\Omega t=\pi (a "π\pi pulse") is XX up to phase, and Ωt=π/2\Omega t=\pi/2 makes an equal superposition. Shifting the phase of the drive changes XX to cos⁡χX+sin⁡χY\cos\chi\,X+\sin\chi\,Y, which gives rotations about any axis in the equatorial plane.

Explore

the state rotation axis n^\hat n its path during the pulse · drag to turn
P1P_1 against pulse area on resonance, for comparison

Worked example

Design a pulse that takes |0⟩\ket0 to |+⟩\ket+ on a resonantly driven qubit with Ω/2π=50\Omega/2\pi=50 kHz, and estimate the error if the drive is detuned by Δ=0.1Ω\Delta=0.1\,\Omega.

  1. A drive with phase χ=0\chi=0 rotates about xx. Can it reach |+⟩\ket+ from |0⟩\ket0?

    No. A rotation about xx moves the north pole around the circle in the yy–zz plane, through |−i⟩\ket{-i} and |1⟩\ket1, never reaching +x+x.

  2. Which axis and angle work, and what is the matrix?

    A quarter turn about +y+y (drive phase χ=π/2\chi=\pi/2) sends +z+z to +x+x:

    Ry(π/2)=12(1−111),Ry(π/2)|0⟩=|+⟩.R_y(\pi/2)=\tfrac1{\sqrt2}\begin{pmatrix}1&-1\\1&1\end{pmatrix},\qquad R_y(\pi/2)\ket0=\ket+.
  3. How long is the pulse?

    We need Ωt=π/2\Omega t=\pi/2, so t=π/(2Ω)=π/(2⋅2π⋅50kHz)=5 μst=\pi/(2\Omega)=\pi/(2\cdot2\pi\cdot50\,\text{kHz})=5\ \mu\text{s}.

  4. With Δ=0.1Ω\Delta=0.1\,\Omega, how far off is a π\pi pulse? (Set Δ/Ω = 0.10 in the explorer.)

    The axis tilts by arctan⁡0.1≈5.7∘\arctan0.1\approx5.7^\circ, and the largest possible P1P_1 is Ω2/(Ω2+Δ2)=1/1.01≈0.990\Omega^2/(\Omega^2+\Delta^2)=1/1.01\approx0.990. The nominal π\pi pulse is also slightly too short for the faster rotation: Ω′t=π1.01\Omega' t=\pi\sqrt{1.01}, giving P1=0.990sin2⁡(0.5025π)≈0.990P_1=0.990\,\sin^2(0.5025\pi)\approx0.990. So the error is about 1%, second order in Δ/Ω\Delta/\Omega.

Check your understanding

On resonance, a 2π2\pi pulse is applied to α|0⟩+β|1⟩\alpha\ket0+\beta\ket1. The result is

  1. exactly the original state.The Bloch vector comes back, but Rx(2π)R_x(2\pi) is not the identity matrix.
  2. −(α|0⟩+β|1⟩)-(\alpha\ket0+\beta\ket1).
  3. β|0⟩+α|1⟩\beta\ket0+\alpha\ket1.That (up to phase) is what a π\pi pulse does: half a turn about xx.
Rx(2π)=cos⁡πI−isin⁡πX=−IR_x(2\pi)=\cos\pi\,I-i\sin\pi\,X=-I. The sign is a global phase for an isolated qubit, but it becomes a measurable relative phase if the qubit is in superposition with a third, undriven level. A spin-12\tfrac12 state needs a 4π4\pi rotation to return to itself exactly.

The detuning equals the Rabi frequency, Δ=Ω\Delta=\Omega. What is the largest P1P_1 any pulse length can give?

  1. 1, with a long enough pulseOff resonance the oscillation has reduced amplitude, however long you wait.
  2. 1/2
  3. 1/4The amplitude is Ω2/(Ω2+Δ2)\Omega^2/(\Omega^2+\Delta^2); don't square it again.
Ω2/(Ω2+Δ2)=1/2\Omega^2/(\Omega^2+\Delta^2)=1/2. The axis is tilted 45∘45^\circ from zz, so the state circles from the north pole down to the equator and back. Set Δ/Ω = 1 in the explorer.

A qubit has coherence time T2=1T_2=1 ms and a π\pi pulse takes 10 μ10\ \mus. Roughly how many sequential gates fit before coherence is mostly lost?

  1. About 10Divide the two times.
  2. About 100
  3. About 10,000Check the units: 1 ms is 1000 μs.
T2/tgate=1000/10=100T_2/t_{\text{gate}}=1000/10=100. This ratio, not either time alone, is the figure of merit, and error correction needs it to be large.

Practice

How far down?The precession cone

With detuning Δ\Delta, the Bloch vector starting at the north pole moves on a circle around n^\hat n. Find the lowest zz it reaches, and check that it agrees with the Rabi formula.

Hint

Rotating z^\hat z by π\pi about n^\hat n gives the point on the circle farthest from where it started.

Solution

A half turn sends z^\hat z to 2(n^⋅z^)n^−z^2(\hat n\cdot\hat z)\hat n-\hat z, whose zz-component is 2nz2−1=2Δ2/Ω′2−12n_z^2-1=2\Delta^2/\Omega'^2-1. Then P1=(1−z)/2=1−Δ2/Ω′2=Ω2/Ω′2P_1=(1-z)/2=1-\Delta^2/\Omega'^2=\Omega^2/\Omega'^2, the amplitude in the Rabi formula.

Pulse lengths for an ionUnits

An ion qubit is driven with Ω/2π=100\Omega/2\pi=100 kHz. How long are its π\pi and π/2\pi/2 pulses?

Solution

tπ=π/Ω=1/(2⋅100kHz)=5 μt_\pi=\pi/\Omega=1/(2\cdot100\,\text{kHz})=5\ \mus and tπ/2=2.5 μt_{\pi/2}=2.5\ \mus. A common slip is to use Ω=100\Omega=100 kHz instead of 2π×1002\pi\times100 kHz, which gives a time 2π2\pi times too long.

More practice: Nielsen–Chuang, Exercises 7.18 and 7.31.

InteractiveNielsen–Chuang, Ch. 8: Quantum noise and quantum operations

Noise on the Bloch ball

A qubit that interacts with its surroundings no longer evolves by a unitary. Its evolution is a quantum operation, and for one qubit every such operation squashes and shifts the Bloch ball into an ellipsoid inside it. Pick a channel and watch the ball deform.

The idea

Quantum operation. A map of density operators of the form
ℰ(ρ)=∑kEkρEk†,∑kEk†Ek=I.\mathcal E(\rho)=\sum_k E_k\,\rho\,E_k^\dagger,\qquad \sum_k E_k^\dagger E_k=I.

The EkE_k are Kraus operators (operation elements). Every such map arises from a unitary interaction with an environment that starts in a fixed state and is then discarded, and conversely. These maps are exactly the trace-preserving, completely positive ones.

On one qubit. Writing ρ=12(I+r→⋅σ→)\rho=\tfrac12(I+\vec r\cdot\vec\sigma), every quantum operation acts as an affine map r→↦Mr→+c→\vec r\mapsto M\vec r+\vec c. The image of the ball is an ellipsoid. The common channels:
  • Bit flip (XX with probability pp): (x,y,z)↦(x,(1−2p)y,(1−2p)z)(x,y,z)\mapsto(x,\,(1-2p)y,\,(1-2p)z).
  • Phase flip (ZZ with probability pp): (x,y,z)↦((1−2p)x,(1−2p)y,z)(x,y,z)\mapsto((1-2p)x,\,(1-2p)y,\,z).
  • Depolarising, ρ↦(1−p)ρ+pI/2\rho\mapsto(1-p)\rho+p\,I/2: r→↦(1−p)r→\vec r\mapsto(1-p)\vec r.
  • Amplitude damping (energy loss, |1⟩→|0⟩\ket1\to\ket0 with probability γ\gamma), E0=(1001−γ)E_0=\big(\begin{smallmatrix}1&0\\0&\sqrt{1-\gamma}\end{smallmatrix}\big), E1=(0γ00)E_1=\big(\begin{smallmatrix}0&\sqrt\gamma\\0&0\end{smallmatrix}\big): (x,y,z)↦(1−γx,1−γy,γ+(1−γ)z)(x,y,z)\mapsto(\sqrt{1-\gamma}\,x,\,\sqrt{1-\gamma}\,y,\,\gamma+(1-\gamma)z).
  • Phase damping (loss of coherence without energy loss): (x,y,z)↦(1−λx,1−λy,z)(x,y,z)\mapsto(\sqrt{1-\lambda}\,x,\,\sqrt{1-\lambda}\,y,\,z).
Positive is not enough. The map must stay positive when it acts on half of an entangled pair. The transpose ρ↦ρ𝖳\rho\mapsto\rho^{\mathsf T} (a reflection y↦−yy\mapsto-y of the ball) maps the ball to itself, but it is not a quantum operation.

Explore

the Bloch sphere its image under the channel input state after each application · drag to turn
Channel

Worked example

Alice and Bob share |β00⟩\ket{\beta_{00}}, and Bob's qubit goes through a depolarising channel with parameter pp. For which pp do they still violate CHSH, and for which pp are they still entangled?

  1. Find the shared state.

    The channel replaces Bob's qubit by I/2I/2 with probability pp. Since Alice's reduced state is I/2I/2,

    ρ=(1−p)|β00⟩⟨β00|+pI4.\rho=(1-p)\ket{\beta_{00}}\bra{\beta_{00}}+p\,\frac{I}{4}.
  2. What are the CHSH correlations now?

    The I/4I/4 part has E=0E=0 for every pair of settings, so E(a,b)=(1−p)cos⁡(a−b)E(a,b)=(1-p)\cos(a-b) and the best value is S=22(1−p)S=2\sqrt2\,(1-p). This exceeds 2 only when p<1−1/2≈0.293p<1-1/\sqrt2\approx0.293.

  3. Is the state entangled for larger pp? Use the partial transpose: a separable state stays positive under it.

    The partial transpose of |β00⟩⟨β00|\ket{\beta_{00}}\bra{\beta_{00}} is 12SWAP\tfrac12\mathrm{SWAP}, with eigenvalues 12,12,12,−12\tfrac12,\tfrac12,\tfrac12,-\tfrac12. So the partial transpose of ρ\rho has smallest eigenvalue −1−p2+p4-\tfrac{1-p}2+\tfrac p4, negative exactly when p<2/3p<2/3. For two qubits this test is also sufficient, so ρ\rho is entangled iff p<2/3p<2/3.

  4. Put the two thresholds together.

    For 0.293<p<2/30.293<p<2/3 the pair is entangled but the CHSH test can't show it. Bell violation is a stronger property than entanglement. Its fidelity with |β00⟩\ket{\beta_{00}}, 1−3p/41-3p/4, crosses 1/21/2 exactly at p=2/3p=2/3.

Check your understanding

Apply the channel many times. Which channel drives every input to the same pure state?

  1. DepolarisingIt drives everything to the centre, I/2I/2, which is mixed.
  2. Phase flipIt drives each state to the point on the zz-axis below or above it, so different inputs end in different places.
  3. Amplitude damping
Amplitude damping with nn applications is amplitude damping with γn=1−(1−γ)n→1\gamma_n=1-(1-\gamma)^n\to1, whose image is the single point |0⟩\ket0. It models a qubit relaxing to its ground state. Set n = 12 in the explorer.

A pure state goes through the depolarising channel with parameter pp. What is the purity trρ2\mathrm{tr}\rho^2 of the output?

  1. 1−p1-pThat's the length of the output Bloch vector. Purity is (1+|r→|2)/2(1+|\vec r|^2)/2.
  2. (1+(1−p)2)/2\big(1+(1-p)^2\big)/2
  3. 1−p/21-p/2That's the largest eigenvalue, (1+|r→|)/2(1+|\vec r|)/2.
|r→′|=1−p|\vec r'|=1-p, and trρ2=(1+|r→|2)/2\mathrm{tr}\rho^2=(1+|\vec r|^2)/2. At p=1p=1 it reaches the minimum 1/21/2.

The transpose map ρ↦ρ𝖳\rho\mapsto\rho^{\mathsf T} sends every qubit density operator to a density operator. Is it a quantum operation?

  1. Yes: it maps the Bloch ball onto itself.That shows it is positive. Quantum operations must be completely positive.
  2. No: applied to one half of |β00⟩\ket{\beta_{00}} it produces an operator with a negative eigenvalue.
  3. Yes: it is unitary conjugation by YY.YρYY\rho Y flips both xx and zz; the transpose flips only yy. A reflection is not a rotation.
Transposing Bob's half of |β00⟩⟨β00|\ket{\beta_{00}}\bra{\beta_{00}} gives 12\tfrac12SWAP, which has eigenvalue −12-\tfrac12. A physical process on Bob's qubit must leave the joint state physical, so the transpose is not one. Unitaries act on the ball as rotations, never as reflections.

Practice

Two flips make a depolariser?Composing channels

Apply a bit flip with probability pp and then a phase flip with probability qq. Find the combined map on Bloch vectors. For which p,qp,q is it a depolarising channel?

Solution

The scalings multiply: (x,y,z)↦((1−2q)x, (1−2p)(1−2q)y, (1−2p)z)(x,y,z)\mapsto\big((1-2q)x,\ (1-2p)(1-2q)y,\ (1-2p)z\big). Depolarising needs all three factors equal: 1−2q=1−2p1-2q=1-2p and (1−2p)2=1−2p(1-2p)^2=1-2p. So p=q=0p=q=0 (no noise) or p=q=12p=q=\tfrac12 (everything sent to I/2I/2). Otherwise the ellipsoid is squashed most along yy.

Kraus operators for depolarising noiseUsing the Paulis

Find Kraus operators for ρ↦(1−p)ρ+pI/2\rho\mapsto(1-p)\rho+p\,I/2.

Hint

For every qubit ρ\rho, 14(ρ+XρX+YρY+ZρZ)=I/2\tfrac14(\rho+X\rho X+Y\rho Y+Z\rho Z)=I/2.

Solution

Substituting, ℰ(ρ)=(1−3p4)ρ+p4(XρX+YρY+ZρZ)\mathcal E(\rho)=\big(1-\tfrac{3p}4\big)\rho+\tfrac p4(X\rho X+Y\rho Y+Z\rho Z), so

E0=1−3p/4I,E1=p2X,E2=p2Y,E3=p2Z,E_0=\sqrt{1-3p/4}\,I,\quad E_1=\tfrac{\sqrt p}2X,\quad E_2=\tfrac{\sqrt p}2Y,\quad E_3=\tfrac{\sqrt p}2Z,

and ∑Ek†Ek=(1−3p4+3p4)I=I\sum E_k^\dagger E_k=(1-\tfrac{3p}4+\tfrac{3p}4)I=I.

More practice: Nielsen–Chuang, Exercises 8.22, 8.27 and 8.30.

InteractiveNielsen–Chuang, Ch. 9: Distance measures for quantum information

Trace distance and fidelity

How different are two quantum states? Trace distance answers operationally: it is the best advantage you can get in telling them apart with one measurement. Fidelity is a generalised overlap. On the Bloch ball both have pictures, and noise can only bring states closer.

The idea

Trace distance. D(ρ,σ)=12tr|ρ−σ|D(\rho,\sigma)=\tfrac12\,\mathrm{tr}|\rho-\sigma|, half the sum of the absolute eigenvalues of ρ−σ\rho-\sigma. For qubits it is half the Euclidean distance between Bloch vectors: D=12|r→−s→|D=\tfrac12|\vec r-\vec s|.
What it means. D(ρ,σ)=maxP⁡tr(P(ρ−σ))D(\rho,\sigma)=\max_P\mathrm{tr}\big(P(\rho-\sigma)\big) over projectors PP. So if you are handed ρ\rho or σ\sigma with probability 12\tfrac12 each, the best measurement guesses right with probability 12+12D\tfrac12+\tfrac12D. For qubits the best measurement is along r→−s→\vec r-\vec s.
Fidelity. F(ρ,σ)=trρ1/2σρ1/2F(\rho,\sigma)=\mathrm{tr}\sqrt{\rho^{1/2}\sigma\rho^{1/2}}. For pure states F=|⟨ψ|ϕ⟩|F=|\langle\psi|\phi\rangle|, and F(|ψ⟩,σ)=⟨ψ|σ|ψ⟩F(\ket\psi,\sigma)=\sqrt{\bra\psi\sigma\ket\psi}. For qubits,
F2=12(1+r→⋅s→+(1−|r→|2)(1−|s→|2)).F^2=\tfrac12\Big(1+\vec r\cdot\vec s+\sqrt{(1-|\vec r|^2)(1-|\vec s|^2)}\Big).
Noise only helps confusion. For every trace-preserving quantum operation, D(ℰ(ρ),ℰ(σ))≤D(ρ,σ)D(\mathcal E(\rho),\mathcal E(\sigma))\le D(\rho,\sigma) and F(ℰ(ρ),ℰ(σ))≥F(ρ,σ)F(\mathcal E(\rho),\mathcal E(\sigma))\ge F(\rho,\sigma). The two measures bound each other:
1−F ≤ D ≤ 1−F2,1-F\ \le\ D\ \le\ \sqrt{1-F^2},

with the upper bound an equality for pure states.

Explore

The xx–zz slice of the Bloch ball. Drag ρ\rho and σ\sigma . Hollow dots: the states after noise. best measurement axis
Try

Worked example

Compare |0⟩\ket0 and |+⟩\ket+: find DD, FF, the best measurement, and what depolarising noise with p=12p=\tfrac12 does. (Press "|0⟩\ket0 vs |+⟩\ket+" in the explorer.)

  1. Find the trace distance.

    r→=(0,0,1)\vec r=(0,0,1), s→=(1,0,0)\vec s=(1,0,0), |r→−s→|=2|\vec r-\vec s|=\sqrt2, so D=2/2≈0.707D=\sqrt2/2\approx0.707.

  2. Find the fidelity, and check both bounds.

    F=|⟨0|+⟩|=1/2≈0.707F=|\langle0|+\rangle|=1/\sqrt2\approx0.707. Then 1−F≈0.293≤0.7071-F\approx0.293\le0.707, and 1−F2=1/2≈0.707\sqrt{1-F^2}=\sqrt{1/2}\approx0.707: the upper bound is attained, as it must be for pure states.

  3. What measurement tells them apart best, and how often does it succeed?

    Measure along (r→−s→)/|r→−s→|=(−1,0,1)/2(\vec r-\vec s)/|\vec r-\vec s|=(-1,0,1)/\sqrt2, halfway between |0⟩\ket0 and |−⟩\ket-; guess |0⟩\ket0 on outcome +1+1. Success probability 12+12⋅0.707≈0.854\tfrac12+\tfrac12\cdot0.707\approx0.854. Measuring ZZ instead gives only 0.750.75.

  4. After depolarising noise with p=12p=\tfrac12, recompute DD and FF.

    Both Bloch vectors halve: D′=0.354D'=0.354. With r→′⋅s→′=0\vec r'\cdot\vec s'=0 and |r→′|2=|s→′|2=14|\vec r'|^2=|\vec s'|^2=\tfrac14,

    F′2=12(1+0+34)=78,F′≈0.935.F'^2=\tfrac12\big(1+0+\tfrac34\big)=\tfrac78,\qquad F'\approx0.935.

    Distance went down and fidelity up, as contractivity says.

Check your understanding

What is D(|0⟩,|1⟩)D(\ket0,\ket1)?

  1. 2The Bloch vectors are 2 apart, but DD has a factor 12\tfrac12.
  2. 1
  3. 0.5Orthogonal states are perfectly distinguishable, the maximum.
DD ranges from 0 to 1, and D=1D=1 means a single measurement tells the states apart with certainty: here a ZZ measurement.

Two states have D=0.1D=0.1. You get one copy of one of them, each with probability 12\tfrac12. What is the best chance of naming it correctly?

  1. 0.1Guessing blindly already gives 0.5.
  2. 0.55
  3. 0.9That would need the states to be nearly orthogonal.
The optimum is 12+12D\tfrac12+\tfrac12D. Trace distance is the advantage over a coin flip, doubled.

Can some quantum operation make two states more distinguishable?

  1. Yes, a suitable unitary.Unitaries preserve DD exactly: they move the two Bloch points rigidly.
  2. Yes, a measurement that sharpens them.A measurement whose result is kept is also a trace-preserving operation, and it obeys the same bound.
  3. No, not if it is trace-preserving.
Contractivity: D(ℰ(ρ),ℰ(σ))≤D(ρ,σ)D(\mathcal E(\rho),\mathcal E(\sigma))\le D(\rho,\sigma). Processing can't create distinguishability; it can only preserve or lose it. Raise the noise in the explorer and watch DD fall.

Practice

Pure versus maximally mixedBoth formulas

Compute DD and FF for |0⟩\ket0 and I/2I/2, and check the bounds 1−F≤D≤1−F21-F\le D\le\sqrt{1-F^2}.

Solution

D=12|(0,0,1)−0|=12D=\tfrac12|(0,0,1)-0|=\tfrac12. F=⟨0|I2|0⟩=1/2≈0.707F=\sqrt{\bra0\tfrac I2\ket0}=1/\sqrt2\approx0.707. Bounds: 0.293≤0.5≤0.7070.293\le0.5\le0.707, both strict, because I/2I/2 is mixed.

Commuting statesBack to classical distances

Suppose ρ=∑ipi|i⟩⟨i|\rho=\sum_ip_i\ket i\bra i and σ=∑iqi|i⟩⟨i|\sigma=\sum_iq_i\ket i\bra i are diagonal in the same basis. Show that DD and FF reduce to the classical distances between the distributions pp and qq.

Solution

ρ−σ=∑i(pi−qi)|i⟩⟨i|\rho-\sigma=\sum_i(p_i-q_i)\ket i\bra i, so D=12∑i|pi−qi|D=\tfrac12\sum_i|p_i-q_i|, the classical total variation distance. And ρ1/2σρ1/2=∑ipiqi|i⟩⟨i|\rho^{1/2}\sigma\rho^{1/2}=\sum_ip_iq_i\ket i\bra i, so F=∑ipiqiF=\sum_i\sqrt{p_iq_i}, the Bhattacharyya overlap. The quantum measures are new only when the states don't commute.

More practice: Nielsen–Chuang, Exercises 9.6, 9.12 and 9.13.

SimulationNielsen–Chuang, Ch. 10: Quantum error-correction

The three-qubit bit-flip code

You can't copy an unknown qubit, and you can't look at it without disturbing it. Even so, α|0⟩+β|1⟩\alpha\ket0+\beta\ket1 can be spread over three qubits so that a single bit flip is found and undone without anyone learning α\alpha or β\beta. Flip qubits by hand, then run thousands of noisy rounds.

The idea

Encoding. α|0⟩+β|1⟩↦α|000⟩+β|111⟩\alpha\ket0+\beta\ket1\mapsto\alpha\ket{000}+\beta\ket{111}, by two CNOTs from the data qubit onto two fresh |0⟩\ket0s. This is an entangled state, not three copies.
Syndrome. Measure the parities Z1Z2Z_1Z_2 and Z2Z3Z_2Z_3. Both |000⟩\ket{000} and |111⟩\ket{111} (and their versions with the same qubit flipped) give the same values, so the measurement learns only which qubit, if any, was flipped:
(+,+): none,(−,+): qubit 1,(−,−): qubit 2,(+,−): qubit 3.(+,+):\ \text{none},\qquad(-,+):\ \text{qubit 1},\qquad(-,-):\ \text{qubit 2},\qquad(+,-):\ \text{qubit 3}.
When it helps. If each qubit flips independently with probability pp, the code fails only when two or more flip:
pL=3p2(1−p)+p3=3p2−2p3,p_L=3p^2(1-p)+p^3=3p^2-2p^3,

which is smaller than pp for every p<12p<\tfrac12.

General codes. A code with projector PP corrects a set of errors {Ei}\{E_i\} iff PEi†EjP=αijPPE_i^\dagger E_jP=\alpha_{ij}P for a Hermitian matrix (αij)(\alpha_{ij}). Correcting XX, YY and ZZ on a qubit corrects every error on it (errors are discretised by the syndrome measurement). Nesting this code inside a phase-flip version of itself gives Shor's 9-qubit code, which corrects any single-qubit error.

Explore

no code: pp with the code: 3p2−2p33p^2-2p^3 your simulated runs
One round by hand: flip these qubits

Worked example

Encode 0.6|0⟩+0.8|1⟩0.6\ket0+0.8\ket1. Follow one round with a single error and one with a double error.

  1. Write the encoded state, and the state after an XX error on qubit 2.

    0.6|000⟩+0.8|111⟩0.6\ket{000}+0.8\ket{111}, and after X2X_2: 0.6|010⟩+0.8|101⟩0.6\ket{010}+0.8\ket{101}.

  2. What syndrome is measured, and what is the state afterwards?

    On both terms, qubits 1 and 2 differ and qubits 2 and 3 differ, so (Z1Z2,Z2Z3)=(−1,−1)(Z_1Z_2,Z_2Z_3)=(-1,-1) with certainty. Since the outcome was certain, the state is undisturbed: 0.60.6 and 0.80.8 are untouched, and nobody learned them.

  3. Correct and decode.

    (−,−)(-,-) points to qubit 2. Applying X2X_2 restores 0.6|000⟩+0.8|111⟩0.6\ket{000}+0.8\ket{111}, and reversing the encoder gives 0.6|0⟩+0.8|1⟩0.6\ket0+0.8\ket1.

  4. Now suppose qubits 1 and 2 both flip. What happens?

    The state is 0.6|110⟩+0.8|001⟩0.6\ket{110}+0.8\ket{001}, the syndrome is (+,−)(+,-), which points to qubit 3. "Correcting" qubit 3 gives 0.6|111⟩+0.8|000⟩0.6\ket{111}+0.8\ket{000}: a logical XX. The decoded state is 0.8|0⟩+0.6|1⟩0.8\ket0+0.6\ket1, whose overlap with the original is 0.6⋅0.8+0.8⋅0.6=0.960.6\cdot0.8+0.8\cdot0.6=0.96. The code has silently made an error; the fidelity happens to be high only because this particular state is close to its own image under XX.

Check your understanding

An XX error hits qubit 3 of α|000⟩+β|111⟩\alpha\ket{000}+\beta\ket{111}. What syndrome (Z1Z2,Z2Z3)(Z_1Z_2,Z_2Z_3) is measured?

  1. (−,+)(-,+)That pattern means qubit 1 disagrees with qubit 2.
  2. (+,−)(+,-)
  3. It depends on α\alpha and β\beta.Both terms, |001⟩\ket{001} and |110⟩\ket{110}, have the same parities.
After the error the state is α|001⟩+β|110⟩\alpha\ket{001}+\beta\ket{110}. Qubits 1 and 2 agree, qubits 2 and 3 differ, in both terms. The syndrome is a fact about the error, not about the encoded data.

Why doesn't measuring Z1Z2Z_1Z_2 collapse the encoded superposition, when measuring Z1Z_1 would?

  1. |000⟩\ket{000} and |111⟩\ket{111} have the same Z1Z2Z_1Z_2 value but opposite Z1Z_1 values.
  2. Because two-qubit measurements never disturb states.A Bell measurement disturbs plenty. It's about which eigenspace the state lies in.
  3. It does collapse it, but the correction step undoes that.The correction is a fixed XX, which can't restore lost amplitudes.
The encoded state lies entirely inside one eigenspace of Z1Z2Z_1Z_2, so the measurement has a certain outcome and leaves it alone. Z1Z_1 would distinguish |000⟩\ket{000} from |111⟩\ket{111}, revealing |α|2|\alpha|^2 versus |β|2|\beta|^2 and destroying the superposition.

Can this code correct a phase flip Z1Z_1?

  1. Yes, it corrects any single-qubit error.That's Shor's 9-qubit code, not this one.
  2. No: Z1Z_1 turns the codeword into another codeword, so the syndrome is trivial.
  3. Yes, by applying ZZ to all three qubits.The syndrome gives no sign that anything happened, so the decoder wouldn't know to.
Z1(α|000⟩+β|111⟩)=α|000⟩−β|111⟩Z_1(\alpha\ket{000}+\beta\ket{111})=\alpha\ket{000}-\beta\ket{111}: a logical ZZ, undetectable. To handle phase flips, encode in the |±⟩\ket\pm basis instead; to handle both, nest the two codes.

Practice

Is it worth it?Numbers

At p=0.1p=0.1, what is pLp_L and by what factor has the code helped? At what pp does the code stop helping?

Solution

pL=3(0.01)−2(0.001)=0.028p_L=3(0.01)-2(0.001)=0.028, about 3.6 times better than 0.1. Solving 3p2−2p3=p3p^2-2p^3=p gives p=12p=\tfrac12 (and p=0,1p=0,1); the code helps for all 0<p<120<p<\tfrac12. Check with the slider and "Run".

A small rotation, not a flipErrors are discretised

Instead of a flip, qubit 1 suffers the small rotation e−iεX1e^{-i\varepsilon X_1}. Show that the syndrome measurement turns this into either no error or a full X1X_1, and that the code then recovers the state exactly.

Solution

e−iεX1|ψL⟩=cos⁡ε|ψL⟩−isin⁡εX1|ψL⟩e^{-i\varepsilon X_1}\ket{\psi_L}=\cos\varepsilon\ket{\psi_L}-i\sin\varepsilon\,X_1\ket{\psi_L}. The two terms lie in the syndrome spaces (+,+)(+,+) and (−,+)(-,+). The measurement picks the first with probability cos2⁡ε\cos^2\varepsilon (leaving |ψL⟩\ket{\psi_L}) or the second with probability sin2⁡ε\sin^2\varepsilon (leaving X1|ψL⟩X_1\ket{\psi_L}, which is then corrected). Either way the result is |ψL⟩\ket{\psi_L}.

More practice: Nielsen–Chuang, Exercises 10.3 and 10.4.

InteractiveNielsen–Chuang, Ch. 11: Entropy and information

Entropy and entanglement

Shannon entropy measures the uncertainty of a random variable; von Neumann entropy does the same for a quantum state. For a pure state of two qubits, the entropy of either half measures how entangled they are. Set the four amplitudes and watch it.

The idea

Shannon entropy. H(p)=−∑ipilog2⁡piH(p)=-\sum_ip_i\log_2p_i bits. For two outcomes, the binary entropy H(p)=−plog2⁡p−(1−p)log2⁡(1−p)H(p)=-p\log_2p-(1-p)\log_2(1-p), which peaks at 1 bit when p=12p=\tfrac12.
Von Neumann entropy. S(ρ)=−tr(ρlog2⁡ρ)=H(λ)S(\rho)=-\mathrm{tr}(\rho\log_2\rho)=H(\lambda), the Shannon entropy of the eigenvalues of ρ\rho. S=0S=0 exactly for pure states, and S≤log2⁡dS\le\log_2 d in dimension dd.
Two halves of a pure state. If |ψ⟩AB\ket\psi_{AB} is pure, S(ρA)=S(ρB)S(\rho_A)=S(\rho_B): both reduced states have the Schmidt coefficients squared as eigenvalues. This common value is the entropy of entanglement, 0 for product states and 1 bit for Bell states.
Quantum oddities. Subadditivity S(A,B)≤S(A)+S(B)S(A,B)\le S(A)+S(B) holds as classically, but the whole can have less entropy than a part: for a Bell state S(A,B)=0<S(A)=1S(A,B)=0<S(A)=1. Measuring ρ\rho in any basis gives outcomes with Shannon entropy at least S(ρ)S(\rho), with equality in the eigenbasis.

Explore

Binary entropy H(λ)H(\lambda). S(ρA)S(\rho_A) at the smaller eigenvalue λ\lambda Shannon entropy of a ZZ measurement on AA
The reduced states in the xx–zz slice of the Bloch ball. ρA\rho_A ρB\rho_B

Worked example

Find the entropy of entanglement of |ψ⟩=15(|00⟩+2|01⟩+2|10⟩)\ket\psi=\tfrac1{\sqrt5}\big(\ket{00}+\sqrt2\ket{01}+\sqrt2\ket{10}\big), and compare it with the entropy of a ZZ measurement on qubit AA. (It is a preset in the explorer.)

  1. Arrange the amplitudes in a matrix CC (rows: AA, columns: BB) and compute ρA=CC†\rho_A=CC^\dagger.

    C=15(1220),ρA=CC†=15(3222).C=\frac1{\sqrt5}\begin{pmatrix}1&\sqrt2\\ \sqrt2&0\end{pmatrix},\qquad \rho_A=CC^\dagger=\frac15\begin{pmatrix}3&\sqrt2\\ \sqrt2&2\end{pmatrix}.
  2. Find the eigenvalues of ρA\rho_A.

    Trace 1, determinant (6−2)/25=4/25(6-2)/25=4/25. The eigenvalues solve λ2−λ+425=0\lambda^2-\lambda+\tfrac4{25}=0: λ=0.8\lambda=0.8 and 0.20.2. (Also det⁡ρA=|det⁡C|2=(2/5)2\det\rho_A=|\det C|^2=(2/5)^2.) The Schmidt coefficients are 0.8\sqrt{0.8} and 0.2\sqrt{0.2}.

  3. Compute S(ρA)S(\rho_A).

    S=H(0.2)=−0.2log2⁡0.2−0.8log2⁡0.8≈0.464+0.258=0.722S=H(0.2)=-0.2\log_20.2-0.8\log_20.8\approx0.464+0.258=0.722 bits.

  4. What is the Shannon entropy of a ZZ measurement on AA alone?

    p(A=0)=ρ00=0.6p(A=0)=\rho_{00}=0.6, so H(0.6)≈0.971H(0.6)\approx0.971 bits, more than 0.722. The ZZ basis isn't ρA\rho_A's eigenbasis (the off-diagonal entry is nonzero), so measuring in it adds uncertainty.

Check your understanding

A pure two-qubit state has S(ρA)=1S(\rho_A)=1. What is S(ρAB)S(\rho_{AB})?

  1. 2Subadditivity gives an upper bound, S(A,B)≤S(A)+S(B)=2S(A,B)\le S(A)+S(B)=2, not the value.
  2. 1The joint state is pure.
  3. 0
Pure states have zero entropy. The whole is perfectly known while each part is maximally uncertain, which has no classical analogue: classically H(X,Y)≥H(X)H(X,Y)\ge H(X).

Which is more entangled: cos⁡π8|00⟩+sin⁡π8|11⟩\cos\tfrac\pi8\ket{00}+\sin\tfrac\pi8\ket{11}, or 12(|00⟩−|01⟩+|10⟩−|11⟩)\tfrac12(\ket{00}-\ket{01}+\ket{10}-\ket{11})?

  1. The first.
  2. The second: it has four terms.It factors as |+⟩⊗|−⟩\ket+\otimes\ket-.
  3. They are equally entangled.The second is a product state, with entropy 0.
The first is already in Schmidt form with λ2=sin2⁡π8≈0.146\lambda^2=\sin^2\tfrac\pi8\approx0.146, giving H(0.146)≈0.60H(0.146)\approx0.60 bits. The second has amplitude matrix C=12(1−11−1)C=\tfrac12\big(\begin{smallmatrix}1&-1\\1&-1\end{smallmatrix}\big) with det⁡C=0\det C=0, so it is a product.

ρ\rho has eigenvalues 0.9 and 0.1. You measure it in a basis that is not its eigenbasis. The Shannon entropy of the outcomes is

  1. exactly H(0.1)≈0.47H(0.1)\approx0.47 bits.That equality holds only in the eigenbasis.
  2. less than 0.47 bits.The eigenbasis is the basis that minimises the outcome entropy.
  3. more than 0.47 bits.
The outcome probabilities are averages of the eigenvalues, pj=∑i|⟨j|ei⟩|2λip_j=\sum_i|\langle j|e_i\rangle|^2\lambda_i, which makes them more even unless the basis is the eigenbasis. More even means more entropy. This is how the explorer's gold point stays at or above the blue one.

Practice

Entropy of an ensembleQuantum entropy can be smaller

A source emits |0⟩\ket0, |1⟩\ket1 or |+⟩\ket+, each with probability 13\tfrac13. Compute S(ρ)S(\rho) and compare it with the Shannon entropy log2⁡3\log_23 of the source's choice.

Solution

Averaging Bloch vectors, r→=13(0,0,1)+13(0,0,−1)+13(1,0,0)=(13,0,0)\vec r=\tfrac13(0,0,1)+\tfrac13(0,0,-1)+\tfrac13(1,0,0)=(\tfrac13,0,0). The eigenvalues are (1±|r→|)/2=23,13(1\pm|\vec r|)/2=\tfrac23,\tfrac13, so S=H(13)≈0.918S=H(\tfrac13)\approx0.918 bits, less than log2⁡3≈1.585\log_23\approx1.585. Because the states aren't orthogonal, ρ\rho holds less entropy than the label that picked them.

Equal entropiesFrom the Schmidt decomposition

Show that S(ρA)=S(ρB)S(\rho_A)=S(\rho_B) for every pure state |ψ⟩AB\ket\psi_{AB}, even when AA and BB have different dimensions.

Solution

Write |ψ⟩=∑iλi|iA⟩|iB⟩\ket\psi=\sum_i\lambda_i\ket{i_A}\ket{i_B}. Then ρA=∑iλi2|iA⟩⟨iA|\rho_A=\sum_i\lambda_i^2\ket{i_A}\bra{i_A} and ρB=∑iλi2|iB⟩⟨iB|\rho_B=\sum_i\lambda_i^2\ket{i_B}\bra{i_B}: the same nonzero eigenvalues. Extra zero eigenvalues in the larger system add nothing to the entropy.

More practice: Nielsen–Chuang, Exercises 11.11, 11.12 and 11.14.

SimulationNielsen–Chuang, Ch. 12: Quantum information theory

Quantum key distribution

Learning anything about a non-orthogonal state disturbs it. The BB84 protocol turns that into security: an eavesdropper who gains information about the key leaves errors that Alice and Bob can measure. Send qubits with and without Eve on the line.

The idea

BB84. For each round Alice picks a random bit and a random basis, ZZ or XX, and sends |0⟩,|1⟩\ket0,\ket1 or |+⟩,|−⟩\ket+,\ket-. Bob measures in a random basis. Afterwards they announce the bases (not the bits) and keep only the rounds where the bases agree (sifting, about half). They reveal a random sample of the kept bits to estimate the error rate, then use error correction and privacy amplification to distil a shorter secret key.
Information gain causes disturbance. Any interaction that lets Eve learn something about which of two non-orthogonal states was sent must change at least one of them. (If it didn't, Eve could use it to copy or distinguish them, contradicting no-cloning.)
Intercept–resend. If Eve measures a fraction ff of the qubits in a random basis and resends what she saw, she picks the wrong basis half the time, and then Bob's sifted bit is random. The error rate in the sifted key is f/4f/4.
Security threshold. The Shor–Preskill proof shows a secret key can be extracted at rate 1−2H(e)1-2H(e) per sifted bit when the error rate is ee. This is positive for e≲11%e\lesssim11\%.
Holevo bound. If Alice encodes xx in states ρx\rho_x with probabilities pxp_x, the information Bob can obtain by any measurement is at most χ=S(∑xpxρx)−∑xpxS(ρx)\chi=S\big(\sum_xp_x\rho_x\big)-\sum_xp_xS(\rho_x). For one qubit, χ≤1\chi\le1 bit.

Explore

One column per qubit. Bases: + is ZZ, × is XX. rounds Eve intercepted kept after sifting Bob's bit differs from Alice's

Worked example

Eve intercepts every qubit (f=1f=1), measuring each in a random basis and resending the state she found. Work out the error rate she causes, how much she learns, and how quickly she is caught.

  1. Consider a sifted round (Alice and Bob used the same basis). What happens if Eve guessed that basis too?

    She gets Alice's bit exactly and resends the same state. No error, and Eve knows the bit.

  2. And if Eve used the other basis?

    Her result is random and she resends, say, |+⟩\ket+ when Alice sent |0⟩\ket0. Bob measures in Alice's basis and gets a random bit: an error with probability 12\tfrac12.

  3. Combine the cases: error rate and Eve's chance of knowing a sifted bit.

    Error rate 12⋅0+12⋅12=14\tfrac12\cdot0+\tfrac12\cdot\tfrac12=\tfrac14. Eve's guess at a sifted bit is right with probability 12⋅1+12⋅12=34\tfrac12\cdot1+\tfrac12\cdot\tfrac12=\tfrac34. If she intercepts only a fraction ff of the qubits, the error rate is f/4f/4.

  4. Alice and Bob compare 20 sifted bits. How likely is it that they see no error at all?

    (3/4)20≈0.003(3/4)^{20}\approx0.003. Comparing a few dozen bits catches a full intercept–resend attack almost surely. Partial attacks are subtler, which is why the protocol estimates the rate and then distils the key.

Check your understanding

Why does Alice use two bases rather than just |0⟩\ket0 and |1⟩\ket1?

  1. Orthogonal states can be measured and resent perfectly, so Eve would leave no trace.
  2. To double the key rate.Sifting throws half the rounds away, so two bases lower the raw rate.
  3. Because a single basis would violate the Holevo bound.One bit per qubit in one basis is exactly at the Holevo bound, not beyond it.
Disturbance is forced only for non-orthogonal states. Mixing two conjugate bases means Eve can't know which basis to measure in without knowing Alice's choice, which is revealed only after the qubit has reached Bob.

Eve intercepts every qubit with a randomly chosen basis. What error rate do Alice and Bob see in the sifted key?

  1. 50%She only chooses the wrong basis half the time.
  2. 25%
  3. 12.5%That would be the rate if she intercepted half the qubits.
Wrong basis with probability 12\tfrac12, then a random result for Bob with probability 12\tfrac12 of disagreement. Set the slider to 100% and send 10,000 qubits.

Alice sends one qubit, prepared in any of infinitely many states. How much classical information can Bob extract, at most?

  1. Unlimited: the amplitudes are continuous.Bob can't read amplitudes, only sample outcomes.
  2. 1 bit
  3. 2 bitsThat's superdense coding, which needs a pre-shared entangled pair.
Holevo: χ≤S(ρ)≤log2⁡2=1\chi\le S(\rho)\le\log_22=1. A qubit has a continuum of states but carries at most one classical bit.

Practice

A lazy eavesdropperAlways the same basis

Eve intercepts every qubit but always measures in the XX basis. What error rate does she cause in the sifted key, and what does she learn?

Solution

In sifted rounds where Alice used ZZ (half of them), Eve's basis is wrong and Bob errs with probability 12\tfrac12; in rounds with XX there is no error. Error rate: 14\tfrac14, the same as before. She learns every XX-basis bit exactly and nothing about the ZZ-basis ones, so after the bases are announced she knows exactly which of her bits are good.

How much key survives?The Shor–Preskill rate

Alice and Bob measure an error rate of 5% in their sifted key. Using the rate 1−2H(e)1-2H(e), what fraction of the sifted bits becomes secret key? What about at 11%?

Solution

H(0.05)≈0.286H(0.05)\approx0.286, so the rate is 1−0.573≈0.431-0.573\approx0.43: about 43 key bits per 100 sifted bits. At 11%, H(0.11)≈0.4999H(0.11)\approx0.4999 and the rate is essentially zero. One H(e)H(e) pays for error correction and the other for privacy amplification.

More practice: Nielsen–Chuang, Exercises 12.27 and 12.29.