The task
Let be a unitary on some register and one of its eigenvectors. Because is unitary, the eigenvalue has modulus one, so
Phase estimation outputs an estimate of . The task sounds narrow, but much of quantum algorithms reduces to it: energies of a Hamiltonian are eigenphases of , and Shor's factoring algorithm is phase estimation applied to a modular multiplication. The method goes back to Kitaev (Kitaev 1995); the form taught here, with an inverse QFT, is the one presented by Cleve, Ekert, Macchiavello and Mosca (Cleve et al. 1998).
We assume three things: you can prepare (or a state with a large overlap with it, see below), you can apply controlled versions of for , and you have extra "counting" qubits.
Phase kickback
Put a control qubit in and apply controlled- to :
The target is unchanged, and the eigenvalue has moved onto the control as a relative phase. This is the same kickback that turned a bit oracle into a phase oracle in the Foundations lesson on introductory quantum algorithms. With controlled- the control picks up instead.
The circuit
Use counting qubits, written with the most significant bit. Apply a Hadamard to each, let counting qubit control , then apply the inverse QFT to the counting register and measure it. The controlled powers multiply into one phase per basis state: the basis state of the counting register picks up , because the bits of select which powers were applied, and . With , the register is now in
The diagram shows a concrete instance with : on one qubit, whose eigenvector has eigenphase , so each controlled power is a controlled phase gate.
The exact case
Compare the register state with the QFT from the previous lesson: . If for an integer , the register state is , so the inverse QFT returns with certainty and the measurement reveals all bits of . For example, with always yields , that is .
The general case
When is not a multiple of , apply and read off the amplitude of :
a geometric series. Using ,
This is a Fejér kernel centred on : a peak of width about around the true phase, with tails falling off like . Phases are defined modulo 1, so distances are measured on the circle; outcome is a neighbour of outcome .
Theorem (nearest estimate). Let be the outcome closest to on the circle, so . Then .
Proof. Write . On that interval , and for . Hence .
The bound is approached when lies exactly halfway between two grid points: then the two nearest outcomes share most of the probability almost equally.
Worked example
Take and , so and . The nearest outcome is (estimate ) with :
The next outcome, (estimate , ), has . Together the two nearest outcomes carry about 84% of the probability. With the nearest estimate is with probability ; with it is with probability . The probability of the nearest outcome does not grow steadily with : it depends on where falls relative to the integer grid.
How many counting qubits
Usually you want correct bits, meaning an estimate within of , with probability at least . The trick is to use more counting qubits than bits you want, so that the tails of the Fejér kernel are pushed far away in units of .
Theorem. With
counting qubits, the measured estimate satisfies (on the circle) with probability at least .
Sketch. Let be the best -bit estimate below . Using for , an outcome at distance grid steps from has or depending on the side, and summing the squares of these bounds over gives a failure probability of at most . Setting and requiring gives the formula. The full argument is in Nielsen and Chuang, section 5.2.1.
For and : , so . The extra qubits grow only logarithmically in . The exercise checks the guarantee numerically on random phases.
Cost, and why the powers matter
The circuit applies a total of times if each power is implemented by repetition. Precision therefore costs order applications of . Compare that with estimating a phase by repeating a single kickback experiment and averaging, which needs order repetitions to beat shot noise. For phase estimation to be efficient as a function of , though, must be implementable with far fewer than uses of . For a general it is not, and the cost grows exponentially in the number of bits. For modular multiplication it is, because can be computed by repeated squaring, and this is exactly what makes Shor's algorithm polynomial.
Inputs that are not eigenvectors
If the second register starts in , a superposition of eigenvectors with phases , linearity gives . Measuring the counting register returns an estimate of with probability and leaves the second register (approximately) in . So the outcome distribution is the mixture . This is how phase estimation can prepare eigenstates and why ground-state energy estimation needs an initial state with a reasonable overlap with the ground state: the success probability is proportional to it.
Order finding and Shor's algorithm
Here is the connection, stated rather than proved. For coprime integers and , let be the order of modulo , the smallest with . The unitary has eigenvectors with eigenphases for , and the easily prepared state is an equal superposition of them. Phase estimation on therefore returns an estimate of for a uniformly random , and the continued-fraction expansion of a sufficiently precise estimate recovers with good probability. Shor showed that the whole procedure, including the controlled modular exponentiation, runs in time polynomial in , and that factoring reduces to order finding (Shor 1997). Shor's result is a theorem about ideal quantum circuits; running it at cryptographic size additionally needs a fault-tolerant machine large enough for the arithmetic, a topic for the resource-estimation lesson.
Simulating it
Because the controlled powers only multiply basis states by phases when the target is an eigenvector, the counting-register distribution can be computed directly:
import numpy as np
phi, t = 0.3, 3
T = 2**t
k = np.arange(T)
register = np.exp(2j * np.pi * phi * k) / np.sqrt(T) # after the controlled powers
inverse_qft = np.exp(-2j * np.pi * np.outer(k, k) / T) / np.sqrt(T)
probs = np.abs(inverse_qft @ register) ** 2
print(np.round(probs, 4))
It prints [0.0216 0.0518 0.5775 0.2593 0.0409 0.0194 0.0145 0.0149], the worked example. The
KetQat SDK product simulates the gate sequence and returns the most probable outcome
(KetQat SDK):
from ketqat_runner import catalog
record = catalog.run("[email protected]", seed=1, phase=0.3, counting_qubits=5, shots=100)
print(record.result["estimated_phase"], round(record.result["success_probability"], 6))
This prints 0.3125 0.573081. The product assumes an exact eigenstate and does not model the
cost of the controlled powers.
Exercise: phase estimation and its precision
In phase-estimation-precision you build the kickback register, the inverse QFT and the outcome
distribution, then simulate the whole circuit for an arbitrary unitary, with controlled powers
acting on a target register. The checks compare your distribution with the closed form above,
confirm the exact dyadic case and the bound on a fine grid of phases, test the
counting-qubit formula on random phases, run the full circuit with a seeded random
unitary, test a superposition of two eigenvectors, and compare your probabilities with the SDK
product [email protected].
Common mistakes
- Wiring the powers in the wrong order. If counting qubit controls instead of , the register holds a bit-permuted Fourier state and the inverse QFT no longer recovers the phase: even a dyadic phase gives a spread-out distribution, not simply a bit-reversed answer. Fix the wiring, or apply the inverse QFT without its final swap layer, which undoes the reversal. Test with a dyadic phase, where the correct circuit gives a certain answer.
- Using the forward QFT at the end. It returns : an estimate of .
- Measuring distance on a line. Phases live on a circle; is close to the estimate .
- Expecting probability 1 for a non-dyadic phase. Only phases that are multiples of are recovered with certainty. Otherwise the nearest outcome is guaranteed only , and more counting qubits are the remedy.
- Ignoring the cost of . Counting qubits are cheap; implementing high powers of usually is not.
Summary
Phase estimation writes the eigenphase into a register through kickback from controlled powers , producing the state , which the inverse QFT turns into a peak at . Dyadic phases are recovered exactly. Otherwise the outcome distribution is , the nearest estimate has probability at least , and counting qubits give bits with probability at least . With a superposition as input, the output is a mixture weighted by the overlaps. Order finding is phase estimation on modular multiplication, which is why Shor's algorithm is efficient when modular exponentiation is. The next module turns to variational methods, starting with the variational quantum eigensolver.