Path: blob/main/notebooks/ch-algorithms/quantum-phase-estimation.ipynb
3855 views
Quantum Phase Estimation
Quantum phase estimation is one of the most important subroutines in quantum computation. It serves as a central building block for many quantum algorithms. The objective of the algorithm is the following:
Given a unitary operator , the algorithm estimates in . Here is an eigenvector and is the corresponding eigenvalue. Since is unitary, all of its eigenvalues have a norm of 1.
The general quantum circuit for phase estimation is shown below. The top register contains 'counting' qubits, and the bottom contains qubits in the state : 
1.1 Intuition
The quantum phase estimation algorithm uses phase kickback to write the phase of (in the Fourier basis) to the qubits in the counting register. We then use the inverse QFT to translate this from the Fourier basis into the computational basis, which we can measure.
We remember (from the QFT chapter) that in the Fourier basis the topmost qubit completes one full rotation when counting between and . To count to a number, between and , we rotate this qubit by around the z-axis. For the next qubit we rotate by , then for the third qubit.

When we use a qubit to control the -gate, the qubit will turn (due to kickback) proportionally to the phase . We can use successive -gates to repeat this rotation an appropriate number of times until we have encoded the phase theta as a number between and in the Fourier basis.
Then we simply use to convert this into the computational basis.
1.2 Mathematical Foundation
As mentioned above, this circuit estimates the phase of a unitary operator . It estimates in , where is an eigenvector and is the corresponding eigenvalue. The circuit operates in the following steps:
i. Setup: is in one set of qubit registers. An additional set of qubits form the counting register on which we will store the value :
ii. Superposition: Apply a -bit Hadamard gate operation on the counting register:
iii. Controlled Unitary Operations: We need to introduce the controlled unitary that applies the unitary operator on the target register only if its corresponding control bit is . Since is a unitary operator with eigenvector such that , this means:
Applying all the controlled operations with , and using the relation :
where denotes the integer representation of n-bit binary numbers.
iv. Inverse Fourier Transform: Notice that the above expression is exactly the result of applying a quantum Fourier transform as we derived in the notebook on Quantum Fourier Transform and its Qiskit Implementation. Recall that QFT maps an n-qubit input state into an output as
Replacing by in the above expression gives exactly the expression derived in step 2 above. Therefore, to recover the state , apply an inverse Fourier transform on the auxiliary register. Doing so, we find
v. Measurement: The above expression peaks near . For the case when is an integer, measuring in the computational basis gives the phase in the auxiliary register with high probability:
For the case when is not an integer, it can be shown that the above expression still peaks near with probability better than [1].
Let’s take a gate we know well, the -gate, and use Quantum Phase Estimation to estimate its phase. You will remember that the -gate adds a phase of to the state :
Since QPE will give us where:
We expect to find:
In this example we will use three qubits and obtain an exact result (not an estimation!)
Now, set up the quantum circuit. We will use four qubits -- qubits 0 to 2 as counting qubits, and qubit 3 as the eigenstate of the unitary operator ().
We initialize by applying an gate:
Next, we apply Hadamard gates to the counting qubits:
Next we perform the controlled unitary operations. Remember: Qiskit orders its qubits the opposite way round to the circuit diagram in the overview.
We apply the inverse quantum Fourier transformation to convert the state of the counting register, then measure the counting register:
We see we get one result (001) with certainty, which translates to the decimal: 1. We now need to divide our result (1) by to get :
This is exactly the result we expected!
We are expecting the result , and we see our most likely results are 010(bin) = 2(dec) and 011(bin) = 3(dec). These two results would tell us that (off by 25%) and (off by 13%) respectively. The true value of lies between the values we can get from our counting bits, and this gives us uncertainty and imprecision.
3.2 The Solution
To get more precision we simply add more counting qubits. We are going to add two more counting qubits:
The two most likely measurements are now 01011 (decimal 11) and 01010 (decimal 10). Measuring these results would tell us is:
These two results differ from by 3% and 6% respectively. A much better precision!
We can hopefully see that the most likely result is 001 which is the result we would expect from the simulator. Unlike the simulator, there is a probability of measuring something other than 001, this is due to noise and gate errors in the quantum computer.
6. Looking Forward
The quantum phase estimation algorithm may seem pointless, since we have to know to perform the controlled- operations on our quantum computer. We will see in later chapters that it is possible to create circuits for which we don’t know , and for which learning theta can tell us something very useful (most famously how to factor a number!)