Computing Library › Quantum Algorithms
Quantum Algorithms

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

Kronos motion — phase estimation

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

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.

python
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.