|q⟩ Bad Qubits

intermediate · Programming · Amplitude Amplification

The Amplification Operator

Grover's search and its generalization, amplitude amplification, both rely on two geometric primitives: a reflection about a "marked" subspace, and a reflection about the initial state. The composition of these two reflections — called the amplification operator or Grover iterate GG — rotates the quantum state toward the marked subspace.

The two reflections

Let s=Hn0n|s\rangle = H^{\otimes n}|0^n\rangle be the uniform superposition over nn qubits, and let τ|\tau\rangle be the marked state (or subspace). Two unitary reflections are needed.

1. Oracle reflection UfU_f

The oracle flips the sign of every marked basis state and leaves unmarked states unchanged:

Ufx={xif x is marked,xotherwise.U_f |\mathbf{x}\rangle = \begin{cases} -|\mathbf{x}\rangle & \text{if } \mathbf{x} \text{ is marked,} \\ |\mathbf{x}\rangle & \text{otherwise.} \end{cases}

In matrix terms Uf=I2ττU_f = I - 2|\tau\rangle\langle\tau|. The oracle is a reflection about the complement of the marked subspace.

2. Diffuser DD (reflection about s|s\rangle)

The diffuser reflects every amplitude about the mean, equivalently it reflects the state vector about s|s\rangle:

D=2ssI.D = 2|s\rangle\langle s| - I.

For a uniform initial state on nn qubits we can implement DD with a standard circuit identity. Because s=Hn0n|s\rangle = H^{\otimes n}|0^n\rangle, we can conjugate a reflection about 0n|0^n\rangle by HnH^{\otimes n}:

D=Hn(20n0nI)Hn.D = H^{\otimes n}\bigl(2|0^n\rangle\langle 0^n| - I\bigr)H^{\otimes n}.

The inner factor 20n0nI2|0^n\rangle\langle 0^n| - I flips the sign of every state except 0n|0^n\rangle, which is the same as flipping the sign of 0n|0^n\rangle alone (up to global phase):

20n0nI  =  (I20n0n).2|0^n\rangle\langle 0^n| - I \;=\; -(I - 2|0^n\rangle\langle 0^n|).

For two qubits the circuit realization is straightforward. The sign of 00|00\rangle is flipped by conjugating a CZCZ gate (which flips 11|11\rangle) with XX on each qubit:

X2  CZ  X2.X^{\otimes 2}\;CZ\;X^{\otimes 2}.

The full two-qubit diffuser circuit is therefore

D=H2  X2  CZ  X2  H2.D = H^{\otimes 2}\;X^{\otimes 2}\;CZ\;X^{\otimes 2}\;H^{\otimes 2}.

The Grover iterate

Applying the oracle followed by the diffuser gives the Grover iterate G=DUfG = D\,U_f. Each application of GG rotates the state by 2θ2\theta toward the marked state, where sinθ=M/N\sin\theta = \sqrt{M/N}, MM is the number of marked items, and N=2nN = 2^n. After kπ4N/Mk \approx \tfrac{\pi}{4}\sqrt{N/M} iterations the amplitude on the marked state is maximized (Nielsen and Chuang, §6.1).

For N=4N = 4 and M=1M = 1, the initial angle satisfies sinθ=1/4=1/2\sin\theta = \sqrt{1/4} = 1/2, so θ=π/6\theta = \pi/6. One application of GG rotates the state by 2θ=π/32\theta = \pi/3, placing the total angle at (21+1)θ=3θ=π/2(2\cdot 1+1)\theta = 3\theta = \pi/2 — exactly the marked state. A single iteration therefore suffices for certainty. For larger NN (where θ\theta is smaller) one iterate does not reach π/2\pi/2, so more are needed — up to the optimal kπ4N/Mk \approx \tfrac{\pi}{4}\sqrt{N/M}.

Try it

Build the diffuser for two qubits. The grader checks the full unitary matrix, so the identity circuit will fail — you must implement the genuine reflection DD.

Run your code to see the quantum state.

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