The Quantum Fourier Transform (QFT) is the quantum analog of the classical Discrete Fourier Transform (DFT). It is a linear transformation on qubits that maps a quantum state
The QFT is not used directly for speedups on classical data processing (since measuring the output collapses the state, and reading all amplitudes would take exponential time). Instead, it serves as a crucial building block in many advanced quantum algorithms:
- Shor's Algorithm (for integer factorization)
- Quantum Phase Estimation (QPE) (for finding eigenvalues of unitaries)
- Quantum Simulation and solving systems of linear equations (HHL)
-
Classical DFT Complexity:
$O(N \log N)$ using Fast Fourier Transform (FFT) where$N = 2^n$ . -
Quantum QFT Complexity:
$O(n^2)$ gate operations, providing an exponential speedup in circuit complexity.
For an
Applying a product representation, this can be written as:
where
The QFT circuit is constructed using two types of gates:
-
Hadamard Gates (
$H$ ): Creates equal superposition and introduces basic phase terms. -
Controlled-Phase Rotations (
$R_k$ ): Introduces the precise phase shifts, where: $$R_k = \begin{pmatrix} 1 & 0 \ 0 & e^{2\pi i / 2^k} \end{pmatrix}$$
For each qubit
- Apply
$H$ to qubit$i$ . - For each subsequent qubit
$j > i$ , apply a controlled-$R_{j-i+1}$ gate with qubit$j$ as control and qubit$i$ as target. - After processing all qubits, apply a series of SWAP gates to reverse the order of the qubits (since the product representation naturally outputs the binary fractions in reverse order).
In modern Qiskit (2.x / 3.0), the Quantum Fourier Transform is constructed using the QFTGate class inside the qiskit.circuit.library module.
from qiskit import QuantumCircuit
from qiskit.circuit.library import QFTGate
n_qubits = 4
# Create a circuit and append the standard QFT gate
qc = QuantumCircuit(n_qubits)
qft_gate = QFTGate(num_qubits=n_qubits)
qc.append(qft_gate, range(n_qubits))
print(qc.draw())To reverse the QFT (which is necessary in Shor's algorithm and QPE to map phase values back to the computational basis), call the .inverse() method of the QFTGate instance:
from qiskit.circuit.library import QFTGate
iqft_gate = QFTGate(num_qubits=n_qubits).inverse()-
Integrated Usage: The Inverse QFT is a core building block inside our Shor's Algorithm implementation to retrieve the period
$r$ , and in QPE to decode the phase$\phi$ .-
Shor Module:
src/algorithms/shor.py -
QPE Module:
src/algorithms/qpe.py -
Specification:
docs/system/specs/08-shor_algorithm.md
-
Shor Module: