|q⟩ Bad Qubits

intermediate · Programming · Amplitude Amplification

Boosting a Known Subroutine

Grover's search is a special case of a much more general technique: amplitude amplification. Any quantum subroutine A\mathcal{A} that succeeds with some probability p=sin2 ⁣θp = \sin^2\!\theta can be repeatedly amplified until pp approaches 1, using roughly π/(4θ)\lfloor\pi/(4\theta)\rfloor iterations — a quadratic speedup over classical repetition.

The Setup

Let A\mathcal{A} be a quantum circuit on nn qubits that transforms 0n|0\rangle^{\otimes n} into a state

ψ=A0=sinθgood+cosθbad,|\psi\rangle = \mathcal{A}|0\rangle = \sin\theta\,|\text{good}\rangle + \cos\theta\,|\text{bad}\rangle,

where good|\text{good}\rangle is the subspace of "successful" computational outcomes and bad|\text{bad}\rangle is its orthogonal complement. The success probability after a single run of A\mathcal{A} is

p=sin2 ⁣θ.p = \sin^2\!\theta.

Amplitude amplification replaces repeated classical sampling with a unitary iteration that rotates the state inside the two-dimensional plane spanned by good|\text{good}\rangle and bad|\text{bad}\rangle.

One Amplification Iteration

A single iteration consists of two reflections:

  1. Oracle O\mathcal{O}: reflect about bad|\text{bad}\rangle — phase-flip every "good" basis state by 1-1.

O=I2Πgood,\mathcal{O} = I - 2\,\Pi_{\text{good}},

where Πgood\Pi_{\text{good}} projects onto the good subspace.

  1. Diffuser (reflection about ψ|\psi\rangle):

D=A(200I)A.\mathcal{D} = \mathcal{A}\bigl(2|0\rangle\langle 0| - I\bigr)\mathcal{A}^\dagger.

The composition DO\mathcal{D}\,\mathcal{O} is a rotation by 2θ2\theta in the good/bad plane. Starting at angle θ\theta from bad|\text{bad}\rangle, after kk iterations the state is at angle (2k+1)θ(2k+1)\theta, giving success probability sin2((2k+1)θ)\sin^2((2k+1)\theta).

A Concrete Example

Consider the 2-qubit subroutine

A=Ry(π/3)I,\mathcal{A} = R_y(\pi/3) \otimes I,

which acts only on qubit 0 and leaves qubit 1 in 0|0\rangle:

A00=cos ⁣π600+sin ⁣π610=3200+1210.\mathcal{A}|00\rangle = \cos\!\tfrac{\pi}{6}\,|00\rangle + \sin\!\tfrac{\pi}{6}\,|10\rangle = \frac{\sqrt{3}}{2}|00\rangle + \frac{1}{2}|10\rangle.

Here sinθ=12\sin\theta = \frac{1}{2}, so θ=π/6\theta = \pi/6 and the initial success probability on 10|10\rangle is 14\frac{1}{4}.

The oracle phase-flips 10|10\rangle. Because 10|10\rangle has qubit 0 equal to 1 and qubit 1 equal to 0, we build it as: flip qubit 1 (X), apply CZCZ, flip qubit 1 back (X):

O=(IX)CZ(IX).\mathcal{O} = (I \otimes X)\,CZ\,(I \otimes X).

The diffuser rebuilds A00\mathcal{A}|00\rangle from the zero state:

D:A,20000I,A.\mathcal{D}: \quad \mathcal{A}^\dagger,\quad 2|00\rangle\langle 00| - I,\quad \mathcal{A}.

The phase-flip of 00|00\rangle is: X on both qubits, then CZCZ, then X on both qubits.

After one full iteration the state becomes 10-|10\rangle, putting all probability on the good state 10|10\rangle.

Try it

The starter code applies the subroutine A\mathcal{A}. Add the oracle that phase-flips the good state 10|10\rangle, then add the diffuser that reflects about A00\mathcal{A}|00\rangle. The grader checks the output distribution — it should put all probability on 10|10\rangle.

Run your code to see the quantum state.

Sign in on the full site to ask questions and join the discussion.