Quantum Phase Estimation: Worked Example
A step-by-step walkthrough estimating the eigenphase of a single-qubit unitary using a small ancilla register.
The goal
Quantum phase estimation (QPE) finds the phase phi in an eigenvalue exp(2 pi i phi) of a unitary U, given an eigenstate |u> with U|u> = exp(2 pi i phi)|u>. We will estimate phi for the phase gate U = diag(1, exp(2 pi i phi)) acting on the |1> eigenstate, using a three-qubit counting register.
Setup
Take phi = 0.625 = 0.101 in binary, so exactly three bits suffice. The eigenstate is |u> = |1>. Use three counting qubits initialized to |000> and the target qubit in |1>.
The steps
- Apply Hadamards to all three counting qubits, producing a uniform superposition.
- Apply controlled-U^{2^k}: counting qubit k (k = 0,1,2) controls U raised to 2^k, kicking a phase exp(2 pi i 2^k phi) onto the |1> branch.
- Phase kickback writes the binary digits of phi into the counting register's relative phases.
- Apply the inverse quantum Fourier transform to the counting register.
- Measure the counting register to read the binary fraction of phi.
Following the phases
After the controlled operations, the counting register holds sum over y of exp(2 pi i phi y)|y> up to normalization, the Fourier basis representation of phi. The inverse QFT converts this into the computational basis state closest to the binary expansion of phi. For phi = 0.101, measurement yields 101, read as 0.101 in binary = 0.625, recovering phi exactly.
phi = 0.625
bits = 3
# ideal readout for exactly-representable phi
val = int(round(phi * 2**bits)) # 5
binary = format(val, '0{}b'.format(bits)) # '101'
print(binary, val / 2**bits) # 101 0.625
Non-exact phases and precision
When phi is not exactly representable in t bits, measurement returns the nearest t-bit value with high probability and nearby values with smaller probability; the estimate is accurate to about 2^-t. Adding counting qubits improves precision but requires higher powers of U, increasing circuit depth. This depth cost motivates the iterative and Kitaev variants that use a single ancilla. QPE is the engine of Shor's algorithm, counting, and chemistry energy estimation.