Lesson 05: Quantum phase estimation
Kento Ueda (May 15, 2024)
Approximate QPU time to run this experiment is 7 seconds.
This notebook provides the fundamental concepts and implementation of the Quantum Fourier Transformation (QFT) and Quantum Phase Estimation (QPE).
Click here to download this notebook in Jupyter format.
Click here to download the pdf of the original lecture. Please note that some code snippets may become deprecated since these are static images.
1. Introduction
Quantum Fourier Transformation (QFT)
The Quantum Fourier Transformation is the quantum counterpart of the classical discrete Fourier transform. It is a linear transformation applied to the quantum states, mapping computational bases into their Fourier basis representations. The QFT plays a key role in many quantum algorithms, offering an efficient method to extract periodicity information from quantum states. The QFT can be implemented with operations with quantum gates such as Hadamard gates and Control-Phase gates for qubits, enabling exponential speedup over classical Fourier transformation.
- Applications: It is a foundational part in quantum algorithms such as Shor's algorithm for factoring large integers and discrete logarithm.
Quantum Phase Estimation (QPE)
Quantum Phase Estimation is a quantum algorithm used to estimate the phase associated with an eigenvector of a unitary operator. This algorithm provides a bridge between the abstract mathematical properties of quantum states and their computational applications.
- Applications: It can solve problems such as finding eigenvalues of unitary matrices and simulating quantum systems.
Together, QFT and QPE form the essential backbone of many quantum algorithms solving problems that are infeasible for classical computers. By the end of this notebook, you will gain an understanding of how these techniques are implemented.
2. Basic of Quantum Fourier Transformation (QFT)
No output produced
From the analogy with the discrete Fourier transform, the QFT acts on a quantum state
for qubits and maps it to the quantum state
where .
Or the unitary matrix representation:
2.1 Intuition
The quantum Fourier transform (QFT) transforms between two bases, the computational (Z) basis, and the Fourier basis. But what does the Fourier basis mean in this context? You likely recall that the Fourier transform of a function describes the convolution of onto a sinusoidal function with frequency . In Layman's terms: the Fourier transform is a function describing how much of each frequency we would need to build up a function out of sine functions (or cosine functions). To get a better sense for what the QFT means in this context, consider the stepped images below which show a number encoded in binary, using four qubits:
In the computational basis, we store numbers in binary using the states and :
Note the frequency with which the different qubits change; the leftmost qubit flips with every increment in the number, the next with every 2 increments, the third with every 4 increments, and so on.
If we apply a quantum Fourier transform to these states, we map
(We often denote states in the Fourier basis using the tilde (~)).
In the Fourier basis, we store numbers using different rotations around the Z-axis:
The number we want to store dictates the angle at which each qubit is rotated around the Z-axis. In the state , all qubits are in the state . As seen in the example above, to encode the state on 4 qubits, we rotated the leftmost qubit by full turns ( radians). The next qubit is turned double this ( radians, or full turns), this angle is then doubled for the qubit after, and so on.
Again, note the frequency with which each qubit changes. The leftmost qubit (
2.2 Example: 1-qubit QFT
Let's consider the case of .
The unitary matrix can be written:
This operation is the result of applying the Hadamard gate().
2.3 Product representation of QFT
Let's generalize a transformation for , acting on the state .
2.4 Example: Circuit construction of 3 qubits QFT
From the above description, it may not be clear how to construct a QFT circuit. For now, simply note that we expect three qubits to have phases that evolve at different "rates". Understand exactly how this is translated into a circuit is left as an exercise to the reader. There are multiple diagrams and examples in the lecture pdf. Additional resources include this lesson from Fundamentals of Quantum Algorithms.
We will demonstrate QFT using simulators, only. So will not use the Qiskit patterns framework, until we move on to quantum phase estimation.
No output produced
Output:
Output:
Output:
Output:
We try to apply QFT to as an example.
First, we confirm the binary notation of the integer 5 and create the circuit encoding the state 5:
Output:
'0b101'
Output:
We check the quantum states using the Aer simulator:
Output:
Finally, we add QFT and view the final state of our qubits:
Output:
Output:
We can see out QFT function has worked correctly. Qubit 0 has been rotated by of a full turn, qubit 1 by full turns (equivalent to of a full turn), and qubit 2 by full turns (equivalent to of a full turn).
2.5 Exercise: QFT
(1) Implement QFT of 4 qubits.
No output produced
(2) Apply QFT to , simulate and plot the statevector using the Bloch sphere.
No output produced
Solution of the exercise: QFT
(1)
Output:
(2)
Output:
'0b1110'
Output:
Output:
Output:
3 Basic of Quantum Phase Estimation (QPE)
Given a unitary operation , the QPE estimates in since is unitary, all of its eigenvalues have a norm of 1.
3.1 Procedure
1. Setup
is in one set of qubit registers. An additional set of qubits form the counting register on which we will store the value :
2. Superposition
Apply a -bit Hadamard gate operation on the counting register:
3. 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:
3.2 Example: T-gate QPE
Let's use gate as an example of QPE and estimate its phase .
We expect to find:
where
We initialize of the eigenvector of gate by applying an gate:
Output:
Next, we apply Hadamard gates to the counting qubits:
Output:
We perform the controlled unitary operations:
Output:
We apply the inverse quantum Fourier transformation to convert the state of the counting register, then measure the counting register:
No output produced
Output:
Output:
We can simulate using Aer simulator:
Output:
We see we get one result (
Shor's algorithm allows us to factorize a number by building a circuit with unknown and obtaining .
3.3 Exercise:
Estimate using 3 qubits for counting and a qubit for an eigenvector.
. Since we want to implement , we need to set .
No output produced
Solution of the exercise:
Output:
Output:
4. Execution using Qiskit Runtime Primitives Sampler
We will perform QPE using the real quantum device and follow 4 steps of Qiskit Patterns.
No output produced
No output produced
4.1 Step 1: Map problem to quantum circuits and operators
Output:
Output:
<IBMBackend('ibm_cusco')>
4.2 Step 2: Optimize for target hardware
Output:
4.3 Step 3: Execute on target hardware
Output:
job id: cxb5pzbrkac00089r7v0
Output:
'DONE'
Output:
PrimitiveResult([SamplerPubResult(data=DataBin(c=BitArray(<shape=(), num_shots=1024, num_bits=3>)), metadata={'circuit_metadata': {}})], metadata={'execution': {'execution_spans': ExecutionSpans([SliceSpan(<start='2024-12-09 02:52:48', stop='2024-12-09 02:52:58', size=1024>)])}, 'version': 2})
4.4 Step 4: Postprocess the results
Output:
Output:
'1.3.0'
Was this page helpful?