Quantum Phase Estimation (QPE) turns an unobservable global phase into a measurable integer stored
in a binary register. This lesson shows how the three building blocks — a Hadamard layer,
controlled-U powers, and an inverse Quantum Fourier Transform — fit together into a single
circuit.
The goal
Given a unitary U and one of its eigenvectors ∣u⟩ with
U∣u⟩=e2πiφ∣u⟩,φ∈[0,1),
QPE writes an n-bit binary approximation of φ into a dedicated counting register of
n qubits. If φ is exactly representable as an n-bit fraction, the result is exact.
Circuit structure
The circuit uses two registers:
Counting register: n qubits, all initialised to ∣0⟩. These will hold the phase.
Eigenstate register: one or more qubits initialised to the eigenstate ∣u⟩.
Stage 1 — Hadamard layer
Apply H to every qubit in the counting register to create the uniform superposition
H⊗n∣0⟩⊗n=2n1k=0∑2n−1∣k⟩.
Stage 2 — Controlled-U powers
Index the counting qubits j=0,1,…,n−1 from MSB to LSB. Qubit j controls the
operation U2n−1−j on the eigenstate register.
Because U∣u⟩=e2πiφ∣u⟩, repeated application gives
U2k∣u⟩=e2πiφ⋅2k∣u⟩.
A controlled-U2k imprints the phase e2πiφ⋅2k on the control qubit only
when that qubit is ∣1⟩. After all n controlled operations the counting register is
2n1j=0⨂n−1(∣0⟩+e2πiφ⋅2n−1−j∣1⟩).
This tensor product is the Quantum Fourier Transform of ∣φ~⟩, where
φ~ is the integer 2nφ (exact when φ is an n-bit fraction).
Stage 3 — Inverse QFT
Applying QFT† to the counting register maps the Fourier-encoded state back to the
computational-basis state ∣φ~⟩. A measurement then reads out the n-bit
integer whose binary value gives the phase.
Worked example: U=S, n=2 counting qubits
The S gate has matrix diag(1,eiπ/2), so S∣1⟩=eiπ/2∣1⟩=e2πi⋅1/4∣1⟩.
The phase is φ=1/4, which in 2-bit binary is 0.012, encoding the integer φ~=1.
Stage 2 applies CS20=CS controlled by q1, then CS21=CZ controlled by q0.
Since S∣1⟩=i∣1⟩ and Z∣1⟩=−∣1⟩:
21(∣0⟩−∣1⟩)(∣0⟩+i∣1⟩)∣1⟩.
The counting register 21(∣0⟩−∣1⟩)(∣0⟩+i∣1⟩) equals QFT4∣01⟩, because
QFT∣j⟩=41∑k=03e2πijk/4∣k⟩, giving
QFT∣1⟩=21(1,i,−1,−i)T in the basis ∣00⟩,∣01⟩,∣10⟩,∣11⟩,
which matches the tensor product above.
Stage 3 (QFT† on q0,q1) returns the counting register to ∣01⟩. Measuring all three
qubits yields the bitstring 011 with certainty, and the top two bits 01=1/4⋅4 correctly
encode φ=1/4.
Try it
Build the complete QPE circuit for U=S with 2 counting qubits. The starter code prepares the
eigenstate ∣1⟩ on q2. Add Stage 1, Stage 2, Stage 3, and a final measurement. The grader
checks the output distribution, which should place all probability on the bitstring 011.
Run your code to see the quantum state.
Sign in on the full site to ask questions and join the discussion.