|q⟩ Bad Qubits

intermediate · Programming · Quantum Phase Estimation

Checkpoint: Estimate a Phase

This checkpoint brings together every building block from the module — phase kickback, controlled-UU powers, and the inverse QFT — into a single working Quantum Phase Estimation (QPE) circuit.

The target problem

The SS gate (phase gate) acts on its eigenstate 1|1\rangle as

S1=(100i)(01)=i1=e2πi1/41.S|1\rangle = \begin{pmatrix}1 & 0 \\ 0 & i\end{pmatrix}\begin{pmatrix}0 \\ 1\end{pmatrix} = i|1\rangle = e^{2\pi i \cdot 1/4}|1\rangle.

The eigenphase is φ=1/4\varphi = 1/4. Written in two-bit binary, φ=0.012\varphi = 0.01_2, so a two-qubit QPE circuit should produce the bitstring 0101 in the counting register with certainty.

Circuit structure

A QPE circuit for n=2n = 2 counting qubits and a single-qubit target has four stages.

Stage 1 — Prepare the eigenstate. Apply XX to the target qubit (qubit 2), turning 0|0\rangle into the eigenstate 1|1\rangle.

Stage 2 — Superpose the counting register. Apply HH to each counting qubit (qubits 0 and 1), creating the uniform superposition

++=12(00+01+10+11).|+\rangle|+\rangle = \frac{1}{2}\bigl(|00\rangle + |01\rangle + |10\rangle + |11\rangle\bigr).

Stage 3 — Phase kickback. Each counting qubit kk controls S2kS^{2^k} on the target:

In standard QPE, the MSB counting qubit controls the highest power of UU so that the resulting superposition of the counting register equals the quantum Fourier transform of the phase integer. Because 1|1\rangle is an eigenstate of SS, each controlled-S2kS^{2^k} does not entangle the registers — it only multiplies the 1|1\rangle component of the respective counting qubit by the phase factor e2πi2kφe^{2\pi i \cdot 2^k \varphi}. After kickback, the counting register holds

12(00+eiπ/201+eiπ10+ei3π/211)=12j=03e2πiφjj.\frac{1}{2}\bigl(|00\rangle + e^{i\pi/2}|01\rangle + e^{i\pi}|10\rangle + e^{i3\pi/2}|11\rangle\bigr) = \frac{1}{2}\sum_{j=0}^{3} e^{2\pi i \varphi j}|j\rangle.

This is exactly QFT41\mathrm{QFT}_4|1\rangle, the quantum Fourier transform of the state 1|1\rangle (integer 1, encoding φ=1/22\varphi = 1/2^2).

Stage 4 — Inverse QFT. Applying QFT41\mathrm{QFT}_4^{-1} undoes the Fourier transform and collapses the counting register to 01|01\rangle. The 2-qubit inverse QFT circuit is

SWAP(0,1)    H1    CP(π/2)01    H0.\mathrm{SWAP}(0,1) \;\to\; H_1 \;\to\; CP(-\pi/2)_{0\to 1} \;\to\; H_0.

After the inverse QFT, measuring the counting register gives 01 with probability 1, so reading off φ=1/22=1/4\varphi = 1/2^2 = 1/4 is exact.

Try it

Implement the full QPE circuit. The grader checks the output distribution: the combined state of all three qubits should place all probability on the bitstring 011 (counting register 01, target qubit 1 — qubit 2 remains in 1|1\rangle since phase kickback leaves an eigenstate unchanged up to global phase).

Run your code to see the quantum state.

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