|q⟩ Bad Qubits

intermediate · Programming · Amplitude Amplification

Checkpoint: Amplify an Amplitude

This is the module checkpoint. You now know every moving part of amplitude amplification: the geometric interpretation, the oracle, the diffuser, and how to adapt all three to a custom subroutine. The challenge is to assemble the complete iteration from scratch on a concrete example and drive a target amplitude from 14\tfrac{1}{4} to 1\approx 1.

Setting up the problem

Consider the two-qubit subroutine

A=Ry ⁣(π3)I,\mathcal{A} = R_y\!\left(\frac{\pi}{3}\right) \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\!\frac{\pi}{6}\,|00\rangle + \sin\!\frac{\pi}{6}\,|10\rangle = \frac{\sqrt{3}}{2}|00\rangle + \frac{1}{2}|10\rangle.

The target (good) state is 10|10\rangle. Its initial probability is sin2(π/6)=(1/2)2=14\sin^2(\pi/6) = (1/2)^2 = \tfrac{1}{4}, so sinθ=12\sin\theta = \tfrac{1}{2} and θ=π6\theta = \tfrac{\pi}{6}.

One amplitude-amplification iteration rotates by 2θ=π32\theta = \tfrac{\pi}{3}, landing the state at angle (21+1)θ=3θ=π2(2 \cdot 1 + 1)\theta = 3\theta = \tfrac{\pi}{2}: probability 1 on the good state.

What the iteration looks like

The iteration is the composition of two reflections.

Oracle O\mathcal{O}: phase-flip every state in the good subspace.

O10=10,O00=00.\mathcal{O}|10\rangle = -|10\rangle, \qquad \mathcal{O}|00\rangle = |00\rangle.

Because the good state has qubit 0 equal to 1 and qubit 1 equal to 0, you build the oracle by temporarily flipping qubit 1 with XX, applying CZCZ (which marks 11|11\rangle), and undoing the flip:

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

Diffuser D\mathcal{D}: reflect about ψ=A00|\psi\rangle = \mathcal{A}|00\rangle.

D=A(20000I)A.\mathcal{D} = \mathcal{A}\,(2|00\rangle\langle 00| - I)\,\mathcal{A}^\dagger.

The inner factor 20000I2|00\rangle\langle 00| - I phase-flips everything except 00|00\rangle. Circuit realization: X2  CZ  X2X^{\otimes 2}\;CZ\;X^{\otimes 2} (which flips the sign of 00|00\rangle up to global phase), sandwiched between A\mathcal{A}^\dagger and A\mathcal{A}:

D=Ry ⁣(π3)  (XX)  CZ  (XX)  Ry ⁣(π3).\mathcal{D} = R_y\!\left(\tfrac{\pi}{3}\right) \;(X \otimes X)\;CZ\;(X \otimes X)\; R_y\!\left(-\tfrac{\pi}{3}\right).

Try it

The starter code applies subroutine A\mathcal{A}. Add the oracle and then the diffuser. The grader checks the output distribution — after one full iteration the probability on 10|10\rangle should be 11.

Run your code to see the quantum state.

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