Skip to content

Phase estimation

Phase estimation is the most reused subroutine in quantum computing. Shor’s algorithm is phase estimation applied to multiplication. Finding the energy of a molecule is phase estimation applied to time evolution. It combines the two ideas you already have: phase kickback and the quantum Fourier transform.

Take a gate UU and a state ∣u⟩\ket{u} that UU leaves unchanged apart from a phase:

U∣u⟩=e2πiφ∣u⟩.U\ket{u} = e^{2\pi i\varphi}\ket{u}.

Such a state is an eigenstate of UU, and the factor in front is its eigenvalue. Because UU is unitary, every eigenvalue has magnitude 1, so it is fixed by a single number φ\varphi between 0 and 1. The task is to find φ\varphi.

For example, S∣1⟩=i∣1⟩S\ket{1} = i\ket{1}, and i=e2πi/4i = e^{2\pi i/4}. So ∣1⟩\ket{1} is an eigenstate of SS with φ=14\varphi = \tfrac14.

There is an obvious obstacle. Applying UU to ∣u⟩\ket{u} multiplies it by a global phase, and a global phase cannot be measured.

The way around it is to apply UU only some of the time. Add a control qubit in the state ∣+⟩\ket{+} and apply controlled-UU. The ∣0⟩\ket{0} part of the control leaves ∣u⟩\ket{u} alone. The ∣1⟩\ket{1} part applies UU and picks up the eigenvalue:

12(∣0⟩+∣1⟩)∣u⟩  ⟶  12(∣0⟩+e2πiφ∣1⟩)∣u⟩.\tfrac{1}{\sqrt2}\bigl(\ket{0} + \ket{1}\bigr)\ket{u} \;\longrightarrow\; \tfrac{1}{\sqrt2}\bigl(\ket{0} + e^{2\pi i\varphi}\ket{1}\bigr)\ket{u}.

The state ∣u⟩\ket{u} is unchanged, and the eigenvalue has become a relative phase on the control. This is phase kickback again. In Deutsch’s algorithm the oracle kicked back a sign, ±1\pm1. Here a general gate kicks back a general phase.

Check

A control qubit starts in ∣0⟩\ket{0}. You apply HH to it, then controlled-ZZ onto a second qubit in the state ∣1⟩\ket{1}, then HH to the control again. What does the control give when measured?

One control qubit is enough to tell φ=0\varphi = 0 from φ=12\varphi = \tfrac12. For other values the outcome is random, and you would need many repetitions to estimate φ\varphi from the statistics. There is a much better way.

Use several control qubits, called counting qubits, and let each one control a different power of UU. Applying UU twice multiplies ∣u⟩\ket{u} by e2πi 2φe^{2\pi i\,2\varphi}, four times by e2πi 4φe^{2\pi i\,4\varphi}, and so on. With tt counting qubits, let the bottom one control UU, the one above it U2U^2, then U4U^4, up to U2t−1U^{2^{t-1}} on the top one. Number the counting wires j=0,1,…,t−1j = 0, 1, \dots, t-1 from the top. Wire jj ends up in the state

12(∣0⟩+e2πi 2 t−1−jφ∣1⟩).\tfrac{1}{\sqrt2}\Bigl(\ket{0} + e^{2\pi i\,2^{\,t-1-j}\varphi}\ket{1}\Bigr).

Multiply these together and collect terms. A basis state ∣y⟩\ket{y} of the counting register gets one factor for each of its bits that is 1, and those factors combine into e2πiφye^{2\pi i\varphi y}:

12t∑y=02t−1e2πi φy∣y⟩.\frac{1}{\sqrt{2^t}}\sum_{y=0}^{2^t-1} e^{2\pi i\,\varphi y}\ket{y}.

Now suppose φ\varphi is a fraction with tt binary digits, φ=m/2t\varphi = m/2^t. Then this is exactly QFT∣m⟩\mathrm{QFT}\ket{m} from the last lesson. Apply the inverse QFT and the counting register becomes ∣m⟩\ket{m}. Measuring it gives the digits of φ\varphi with certainty.

That is the whole algorithm:

  1. Put tt counting qubits in ∣+⟩\ket{+}, next to a register holding ∣u⟩\ket{u}.
  2. Apply the controlled powers of UU.
  3. Apply the inverse QFT to the counting qubits and measure them.

Take U=SU = S and ∣u⟩=∣1⟩\ket{u} = \ket{1}, with two counting qubits. The powers are SS itself and S2=ZS^2 = Z, so the controlled gates you need are controlled-SS and controlled-ZZ.

PuzzleKick back the phases

The bottom wire holds the eigenstate ∣1⟩\ket{1}. Put both counting qubits into superposition and let the top one control S2S^2 and the middle one control SS. The target is 12(∣0⟩−∣1⟩)(∣0⟩+i∣1⟩)∣1⟩\tfrac12\bigl(\ket{0} - \ket{1}\bigr)\bigl(\ket{0} + i\ket{1}\bigr)\ket{1}.

This puzzle needs JavaScript.

Hint

First HH on both counting qubits. The top one then controls S2=ZS^2 = Z on the bottom wire, and the middle one controls SS.

The bottom qubit is still ∣1⟩\ket{1}. The counting qubits hold 12(∣00⟩+i∣01⟩−∣10⟩−i∣11⟩)\tfrac12\bigl(\ket{00} + i\ket{01} - \ket{10} - i\ket{11}\bigr), whose phases are iyi^y: one quarter-turn per step. Compare it with the second row of the matrix QFT4\mathrm{QFT}_4 in the last lesson. It is QFT∣1⟩\mathrm{QFT}\ket{1}.

Now undo the QFT. The inverse of the circuit you built last time is the same gates in reverse order, with controlled-S†S^\dagger in place of controlled-SS. The gate S†S^\dagger puts −i-i on ∣1⟩\ket{1} and undoes SS.

PuzzleRead the phase

The counting qubits start in the state from the last puzzle. Apply the inverse QFT so that they read 01, the binary digits of φ=0.01=14\varphi = 0.01 = \tfrac14. Your circuit is also tested on the states for φ=0\varphi = 0, 12\tfrac12 and 34\tfrac34, which should read 00, 10 and 11.

This puzzle needs JavaScript.

Hint

The QFT was HH, controlled-SS, HH, swap. Run it backwards: swap, HH on the bottom counting wire, controlled-S†S^\dagger, HH on the top one.

The register reads 01. As a binary fraction that is 0.01=140.01 = \tfrac14, the phase of SS on ∣1⟩\ket{1}.

Check

You run phase estimation on the gate TT with eigenstate ∣1⟩\ket{1} and three counting qubits. What do they read?

Usually φ\varphi is not an exact fraction with tt binary digits. Then the counting register is not exactly a Fourier basis state, and the outcome is no longer certain. The simulator shows the outcome probabilities.

SimulatorPhase estimation outcomes

Things to try:

  1. With 3 counting qubits, set φ\varphi to 16/64=0.2516/64 = 0.25. The outcome is certain. Now move to 20/6420/64, halfway between two outcomes. What is the chance of the most likely one?
  2. Keep φ=20/64\varphi = 20/64 and add counting qubits one at a time. When does the outcome become certain again?
  3. Set φ=21/64\varphi = 21/64 and step from 3 counting qubits up to 6. Watch how close the estimate is to the true phase, and not only how likely it is.

The distribution is always concentrated around the true phase. In the worst case, when φ\varphi falls exactly halfway between two outcomes, each of the two nearest ones still has probability at least 4/π2≈0.4054/\pi^2 \approx 0.405. Notice that an extra counting qubit can make the single most likely outcome less probable. That is no loss: the outcomes are packed twice as densely, so the likely ones are all closer to the truth. Adding a few counting qubits beyond the precision you need pushes the chance of an answer within that precision as close to 1 as you like.

Each extra digit of φ\varphi needs one more counting qubit, and that qubit controls a power of UU twice as large as the last. Reading tt digits uses UU a total of 2t−12^t - 1 times.

Check

You want one more decimal digit of φ\varphi. Roughly how much more work is it?

So an error of ϵ\epsilon in φ\varphi costs about 1/ϵ1/\epsilon uses of UU. That is still a good deal. Estimating a probability by repeating an experiment and counting outcomes needs about 1/ϵ21/\epsilon^2 repetitions for the same error.

Whether phase estimation gives a speedup overall depends on UU. In the worked example the powers were easy: S2S^2 is just ZZ. For a general UU, applying U2kU^{2^k} means applying UU over and over, 2k2^k times. The algorithm becomes powerful when there is a shortcut to high powers. Multiplication modulo a number has one, and that is the key to the next lesson.

One last fact turns phase estimation from a curiosity into a tool. Suppose the bottom register holds, not one eigenstate, but a superposition of several:

∣ψ⟩=c1∣u1⟩+c2∣u2⟩+…\ket{\psi} = c_1\ket{u_1} + c_2\ket{u_2} + \dots

The circuit is linear, so each eigenstate gets its own phase written into the counting register alongside it. Measuring the counting register then returns the phase φk\varphi_k of one of the eigenstates, chosen with probability ∣ck∣2|c_k|^2, and leaves the bottom register in the matching ∣uk⟩\ket{u_k}.

So you can run phase estimation on a state you know how to prepare, without knowing any eigenstate of UU, and receive the phase of a random eigenstate. Shor’s algorithm depends on exactly this.

RecallAnswer from memory, then check
LessonFinish this lesson