Skip to content

RahulBailur/IQFT-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Inverse Quantum Fourier Transform (IQFT) Implementation

Abstract

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.

Platform & Language

The Inverse Quantum Fourier Transform is implemented in Python (3.9+) using the Qiskit SDK.

Implementation Details

  • 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

Project Structure

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

Test Cases

Case 1: Exact Binary Phase

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.


Case 2: Exact Binary Phase (k = 5)

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.


Case 3: Non-Exact Phase

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.


Case 4: Superposition of Eigenstates

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|².

Installation

Prerequisites

  • Python 3.9 or higher
  • pip package manager

Setup

  1. Clone or download this repository

  2. (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
  1. Install required dependencies:
pip install -r requirements.txt

Usage

Run All Test Cases

To execute all four test cases sequentially:

python main.py

This will run all test cases and provide a comprehensive summary of results.

Run Individual Cases

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.py

Understanding the Output

Bitstring Notation

Qiskit 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

Phase Estimation

Given a measured bitstring representing integer k:

θ_estimated = k / 2^n

where n is the number of qubits.

Mathematical Background

Quantum Fourier Transform (QFT)

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⟩

Inverse Quantum Fourier Transform (IQFT)

The IQFT reverses this transformation:

IQFT|k⟩ = (1/√2^n) Σ_{j=0}^{2^n-1} e^(-2πijk/2^n) |j⟩

Implementation

The IQFT is implemented using:

  1. Swap gates to reverse qubit order
  2. Hadamard gates (H) for basis transformation
  3. Controlled phase gates (CP) with angles θ = -2π/2^k

The circuit structure:

Swap → (H → CP₁ → CP₂ → ... → CPₙ₋₁) → ... → H

Results Validation

Each test case validates results by:

  1. Comparing measured bitstrings with theoretical expectations
  2. Computing estimated θ from measurement outcomes
  3. Calculating error between estimated and actual θ
  4. Analyzing probability distributions for non-exact cases

Key Observations

  1. Exact phases: When θ can be exactly represented in binary with n qubits, IQFT produces a single bitstring with ~100% probability

  2. Non-exact phases: IQFT produces a distribution peaked at the closest representable value

  3. Superposition: Multiple phases in superposition produce multiple peaks in the measurement distribution

  4. Accuracy: The precision of phase estimation depends on the number of qubits: Δθ ≈ 1/2^n

References

License

This project is created for educational purposes.

Author

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.

About

Inverse Quantum Fourier Transform (IQFT) implementation in Qiskit with experimental validation across exact, non-exact, and superposition phase scenarios, highlighting quantum approximation behavior and circuit-level insights.

Topics

Resources

Stars

Watchers

Forks

Contributors