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.
The problem
Section titled “The problem”Take a gate and a state that leaves unchanged apart from a phase:
Such a state is an eigenstate of , and the factor in front is its eigenvalue. Because is unitary, every eigenvalue has magnitude 1, so it is fixed by a single number between 0 and 1. The task is to find .
For example, , and . So is an eigenstate of with .
There is an obvious obstacle. Applying to multiplies it by a global phase, and a global phase cannot be measured.
Making the phase visible
Section titled “Making the phase visible”The way around it is to apply only some of the time. Add a control qubit in the state and apply controlled-. The part of the control leaves alone. The part applies and picks up the eigenvalue:
The state 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, . Here a general gate kicks back a general phase.
A control qubit starts in . You apply to it, then controlled- onto a second qubit in the state , then to the control again. What does the control give when measured?
, so the control goes from to , and the final turns into . Here , which in binary is : the measured bit is the first binary digit of .
One control qubit is enough to tell from . For other values the outcome is random, and you would need many repetitions to estimate from the statistics. There is a much better way.
One digit per qubit
Section titled “One digit per qubit”Use several control qubits, called counting qubits, and let each one control a different power of . Applying twice multiplies by , four times by , and so on. With counting qubits, let the bottom one control , the one above it , then , up to on the top one. Number the counting wires from the top. Wire ends up in the state
Multiply these together and collect terms. A basis state of the counting register gets one factor for each of its bits that is 1, and those factors combine into :
Now suppose is a fraction with binary digits, . Then this is exactly from the last lesson. Apply the inverse QFT and the counting register becomes . Measuring it gives the digits of with certainty.
That is the whole algorithm:
- Put counting qubits in , next to a register holding .
- Apply the controlled powers of .
- Apply the inverse QFT to the counting qubits and measure them.
A worked example
Section titled “A worked example”Take and , with two counting qubits. The powers are itself and , so the controlled gates you need are controlled- and controlled-.
The bottom wire holds the eigenstate . Put both counting qubits into superposition and let the top one control and the middle one control . The target is .
This puzzle needs JavaScript.
Hint
First on both counting qubits. The top one then controls on the bottom wire, and the middle one controls .
The bottom qubit is still . The counting qubits hold , whose phases are : one quarter-turn per step. Compare it with the second row of the matrix in the last lesson. It is .
Now undo the QFT. The inverse of the circuit you built last time is the same gates in reverse order, with controlled- in place of controlled-. The gate puts on and undoes .
The counting qubits start in the state from the last puzzle. Apply the inverse QFT so that they read 01, the binary digits of . Your circuit is also tested on the states for , and , which should read 00, 10 and 11.
This puzzle needs JavaScript.
Hint
The QFT was , controlled-, , swap. Run it backwards: swap, on the bottom counting wire, controlled-, on the top one.
The register reads 01. As a binary fraction that is , the phase of on .
You run phase estimation on the gate with eigenstate and three counting qubits. What do they read?
, so , which is in binary.
When the phase does not fit
Section titled “When the phase does not fit”Usually is not an exact fraction with 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.
Things to try:
- With 3 counting qubits, set to . The outcome is certain. Now move to , halfway between two outcomes. What is the chance of the most likely one?
- Keep and add counting qubits one at a time. When does the outcome become certain again?
- Set 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 falls exactly halfway between two outcomes, each of the two nearest ones still has probability at least . 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.
What it costs
Section titled “What it costs”Each extra digit of needs one more counting qubit, and that qubit controls a power of twice as large as the last. Reading digits uses a total of times.
You want one more decimal digit of . Roughly how much more work is it?
One more decimal digit is a factor of 10 in precision, a little over three binary digits. The number of uses of doubles with each binary digit, so it grows about tenfold.
So an error of in costs about uses of . That is still a good deal. Estimating a probability by repeating an experiment and counting outcomes needs about repetitions for the same error.
Whether phase estimation gives a speedup overall depends on . In the worked example the powers were easy: is just . For a general , applying means applying over and over, 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.
You do not need an eigenstate
Section titled “You do not need an eigenstate”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:
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 of one of the eigenstates, chosen with probability , and leaves the bottom register in the matching .
So you can run phase estimation on a state you know how to prepare, without knowing any eigenstate of , and receive the phase of a random eigenstate. Shor’s algorithm depends on exactly this.
Remember it
Section titled “Remember it”What does phase estimation compute?
Given a gate and an eigenstate with , it writes the binary digits of into a register.
Why does phase estimation use controlled- and not itself?
On its own the eigenvalue is a global phase. With a control in it becomes a relative phase: .
What are the three steps of phase estimation?
Put the counting qubits in , apply controlled powers of onto the eigenstate, then apply the inverse QFT to the counting qubits and measure.
In phase estimation with counting qubits, which powers of are used?
, one per counting qubit, with the highest power on the most significant qubit.
How many uses of does phase estimation need to reach an error in the phase?
About : reading binary digits takes uses.
What does phase estimation return if the register holds a superposition of eigenstates?
The phase of one eigenstate , chosen with probability , and the register is left in that eigenstate.