Computing Library › Worked Examples
Worked Examples

Quantum Phase Estimation Worked Out

Estimate the eigenphase of a unitary using a counting register, controlled powers, and an inverse QFT.

Goal

Given a unitary U and an eigenstate |u> with U|u> = exp(2 pi i phi)|u>, phase estimation writes an approximation of phi into a register of t counting qubits. Precision is 2^-t.

Structure

Kronos motion — phase estimation

A concrete case

Let phi = 0.101 in binary = 5/8, and use t = 3 counting qubits. The controlled powers kick back phases 2 pi phi, 2 pi (2 phi), 2 pi (4 phi) onto qubits 0,1,2. Because phi has an exact 3-bit expansion, the inverse QFT produces the state |101> with certainty; measurement returns 5, and phi = 5/8.

python
import numpy as np
t=3; phi=5/8
# phase kicked onto each counting qubit, then inverse QFT read-out
reg=np.ones(2**t,complex)/np.sqrt(2**t)
for k in range(2**t):
    reg[k]*=np.exp(2j*np.pi*phi*k)
N=2**t
Finv=np.array([[np.exp(-2j*np.pi*j*k/N) for k in range(N)] for j in range(N)])/np.sqrt(N)
out=Finv@reg
print(np.argmax(abs(out)**2))  # 5  ->  phi = 5/8

When phi is not exact

If phi lacks a t-bit expansion the readout becomes a peaked distribution around the nearest fraction; the probability of landing on the best t-bit estimate exceeds 4/pi^2 (about 0.405), and it sharpens with a few extra guard qubits. Phase estimation is the measurement primitive behind Shor's period finding and quantum chemistry energy readout.