Skip to main content
Introducing The Quantum Infrastructure Cloud Learn more
Back to Course
lab

Phase estimation

35 min

Quantum circuit

The problem

A gate U has an eigenstate |ψ⟩ with U|ψ⟩ = e2πiφ|ψ⟩. Phase estimation reads the number φ, between 0 and 1, into a register of counting qubits.

How it works

  • Put t counting qubits in superposition with Hadamards.
  • Counting qubit k controls U2k on |ψ⟩. Because |ψ⟩ is an eigenstate, the phase e2πiφ2k kicks back onto the counting qubit.
  • An inverse quantum Fourier transform turns those phases into the binary digits of φ.

If φ has an exact t-bit binary expansion the result is exact on every shot. Otherwise the outcomes spread, peaked at the nearest t-bit value.

The lab

U is the T gate and |ψ⟩ = |1⟩: T|1⟩ = eiπ/4|1⟩, so φ = 1/8, which is 0.001 in binary. The controlled powers are cp(pi / 4), cp(pi / 2) and cp(pi), that is T, T² and T⁴. In this program m[0] holds the lowest bit, so the estimate is φ = (m[0] + 2·m[1] + 4·m[2]) / 8. Our run read m[0] = 1, m[1] = 0, m[2] = 0 on all 1,000 shots: φ = 1/8.

Why it matters

Phase estimation is the core of Shor’s factoring algorithm, through order finding, and of many quantum chemistry methods that estimate energies as phases.

HiQ lab 1

Phase estimation of the T gate

Estimate the eigenphase of T on |1>, which is 1/8, with three counting qubits and an inverse quantum Fourier transform.

phase-estimation.qcosHiQ Assembly
// Phase estimation of the T gate, whose eigenphase is 1/8, with three counting qubits.// The counting bits read m[0] = 1, m[1] = 0, m[2] = 0: binary 0.001 = 1/8.program phase_estimationqubits c[3], targetbits m[3]​// The eigenstate |1> of T.x targetrepeat i in 0..3 {  h c[i]}​// Controlled T^(2^k): c[0] applies T once, c[1] twice, c[2] four times.cp(pi / 4) c[0], targetcp(pi / 2) c[1], targetcp(pi) c[2], target​// Inverse quantum Fourier transform on the counting register.swap c[0], c[2]h c[0]cp(-pi / 2) c[1], c[0]h c[1]cp(-pi / 4) c[2], c[0]cp(-pi / 2) c[2], c[1]h c[2]​repeat i in 0..3 {  measure c[i] -> m[i]}
What you should see
m[0] = 1, m[1] = 0, m[2] = 0 on every shot, so the estimate is (1 + 2·0 + 4·0) / 8 = 1/8.
What we measured
m[0] = 1, m[1] = 0, m[2] = 0 on all 1,000 shots. QCOS checked this program and ran it on a Softquantus Cloud simulator, 1,000 shots, 13 November 2026.

Check it yourself

Save the program as phase-estimation.qcos, set QCOS_API_KEY to a key from your workspace on the Softquantus Research Platform, and ask QCOS to check it. Change a line, check again, and see what the checker says.

pip install softqcossoftqcos lang check phase-estimation.qcos