|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=sin⁡2 ⁣θ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 ∣0⟩⊗n|0\rangle^{\otimes n} into a state

∣ψ⟩=A∣0⟩=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=sin⁡2 ⁣θ.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=I−2 Π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(2∣0⟩⟨0∣−I)A†.\mathcal{D} = \mathcal{A}\bigl(2|0\rangle\langle 0| - I\bigr)\mathcal{A}^\dagger.

The composition D O\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 sin⁡2((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:

A∣00⟩=cos⁡ ⁣π6 ∣00⟩+sin⁡ ⁣π6 ∣10⟩=32∣00⟩+12∣10⟩.\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=(I⊗X) CZ (I⊗X).\mathcal{O} = (I \otimes X)\,CZ\,(I \otimes X).

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

D:A†,2∣00⟩⟨00∣−I,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 A∣00⟩\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.