The Inverse Quantum Fourier Transform (IQFT) is a key component in many quantum algorithms, most notably in Quantum Phase Estimation (QPE), where it converts encoded phase information from the quantum state into a measurable binary representation.
This project focuses on implementing and analyzing the IQFT for different cases using Qiskit (Python 3.9+). The study explores how the IQFT behaves for:
- Exact binary phases
- Non-exact phase values
- Superpositions of eigenstates
The objective is to verify that the IQFT correctly decodes the encoded phase information, demonstrating its accuracy in quantum algorithms.
The Inverse Quantum Fourier Transform is implemented in Python (3.9+) using the Qiskit SDK.
- Custom circuit for IQFT built manually using:
- Hadamard gates (H)
- Controlled phase rotation gates (CP) with negative rotation angles
- Each circuit is simulated using the Aer Simulator
- Results are validated by comparing measured bitstrings with theoretical expectations
IQFT/
├── iqft_core.py # Core QFT and IQFT implementation
├── case1_exact_binary.py # Case 1: Exact binary phase (θ = 1/8)
├── case2_exact_binary_k5.py # Case 2: Exact binary phase (θ = 5/16)
├── case3_non_exact.py # Case 3: Non-exact phase (θ = 0.3)
├── case4_superposition.py # Case 4: Superposition of eigenstates
├── main.py # Main execution script
├── requirements.txt # Python dependencies
└── README.md # This file
Input Parameters:
- Eigenstate: |1⟩
- Number of qubits: n = 3
- Phase: θ = 1/8
Expected Output:
- Bitstring:
'100'(Qiskit's little-endian) =001(big-endian) - Estimated θ = 0.125 (Exact)
Theory: Since θ = 1/8 = 1/2³, it can be exactly represented with 3 qubits as 0.001 in binary.
Input Parameters:
- Eigenstate: |4⟩
- Number of qubits: n = 4
- Phase: θ = 5/16
Expected Output:
- Bitstring:
'1010'(little-endian) =0101(big-endian) - Estimated θ = 0.3125 (Exact)
Theory: Since θ = 5/16 = 5/2⁴, it can be exactly represented with 4 qubits as 0.0101 in binary.
Input Parameters:
- Eigenstate: |1⟩
- Number of qubits: n = 3
- Phase: θ = 0.3
Expected Output:
- Most frequent bitstring:
'010'(little-endian) =010(big-endian) - Estimated θ ≈ 0.25 (Approximate)
Theory: θ = 0.3 cannot be exactly represented with 3 qubits. The closest representable value is 2/8 = 0.25 = 0.010 in binary. The IQFT will output a probabilistic distribution peaked around this approximation.
Input Parameters:
- Number of qubits: n = 3
- Phases: θ ∈ {3/8, 7/8}
- Input state: √0.75 |φ₁⟩ + √0.25 |φ₂⟩
Expected Output: Mixed output with peaks at:
- Bitstring
'110'(representing θ ≈ 0.375 = 3/8) - Bitstring
'111'(representing θ ≈ 0.875 = 7/8)
Theory: When the input is a superposition of eigenstates with different phases, the IQFT produces a superposition of the corresponding binary representations. The measurement outcomes will show both phases with probabilities proportional to |amplitude|².
- Python 3.9 or higher
- pip package manager
-
Clone or download this repository
-
(Optional) Create and activate a virtual environment:
# Windows
python -m venv venv
venv\Scripts\activate
# Linux/Mac
python3 -m venv venv
source venv/bin/activate- Install required dependencies:
pip install -r requirements.txtTo execute all four test cases sequentially:
python main.pyThis will run all test cases and provide a comprehensive summary of results.
To run specific test cases:
# Case 1: Exact binary phase (θ = 1/8)
python case1_exact_binary.py
# Case 2: Exact binary phase (θ = 5/16)
python case2_exact_binary_k5.py
# Case 3: Non-exact phase (θ = 0.3)
python case3_non_exact.py
# Case 4: Superposition of eigenstates
python case4_superposition.pyQiskit uses little-endian notation for measurement results:
- Qubit 0 (rightmost in diagrams) appears on the left of the bitstring
- To convert to standard binary (big-endian), reverse the string
Example:
- Measured:
'100'(little-endian) - Big-endian:
'001' - Decimal value: 1
- Estimated θ = 1/8 = 0.125
Given a measured bitstring representing integer k:
θ_estimated = k / 2^n
where n is the number of qubits.
The QFT on n qubits transforms a computational basis state |j⟩ to:
QFT|j⟩ = (1/√2^n) Σ_{k=0}^{2^n-1} e^(2πijk/2^n) |k⟩
The IQFT reverses this transformation:
IQFT|k⟩ = (1/√2^n) Σ_{j=0}^{2^n-1} e^(-2πijk/2^n) |j⟩
The IQFT is implemented using:
- Swap gates to reverse qubit order
- Hadamard gates (H) for basis transformation
- Controlled phase gates (CP) with angles θ = -2π/2^k
The circuit structure:
Swap → (H → CP₁ → CP₂ → ... → CPₙ₋₁) → ... → H
Each test case validates results by:
- Comparing measured bitstrings with theoretical expectations
- Computing estimated θ from measurement outcomes
- Calculating error between estimated and actual θ
- Analyzing probability distributions for non-exact cases
-
Exact phases: When θ can be exactly represented in binary with n qubits, IQFT produces a single bitstring with ~100% probability
-
Non-exact phases: IQFT produces a distribution peaked at the closest representable value
-
Superposition: Multiple phases in superposition produce multiple peaks in the measurement distribution
-
Accuracy: The precision of phase estimation depends on the number of qubits: Δθ ≈ 1/2^n
- Nielsen & Chuang, "Quantum Computation and Quantum Information"
- Qiskit Documentation: https://qiskit.org/documentation/
- Quantum Phase Estimation Algorithm
This project is created for educational purposes.
IQFT Implementation Project Date: 2025
Note: This implementation uses the Aer simulator for demonstration purposes. For real quantum hardware execution, additional error mitigation techniques may be required.