Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Understand the quantum analogue of the Discrete Fourier Transform: transforming computational basis states into phase frequencies in O(n^2) gates.
Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 7.5
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Input computational state | Integer encoded in binary | |
| Fourier phase factor | Complex root of unity rotating the phase proportional to frequency j · k | |
| Binary fraction notation | representing fractional phase angle rotations | |
| Quantum circuit gate scaling | Requires only n(n+1)/2 Hadamard and Controlled-Phase gates |
Applying QFT to a single qubit (n = 1):
Result: For 1 qubit, the QFT is exactly the Hadamard gate. For n qubits, it maps multi-qubit periodicity directly into readable peak frequencies.
Apply H to qubit 0.
Apply sequence of Controlled-R2, Controlled-R3, ... Controlled-Rn gates from subsequent qubits.
Repeat for qubit 1, qubit 2, through qubit n-1.
Reverse the order of qubits at the end to correct bit reversal.
Problem: Factoring 2048-bit RSA keys into prime factors p and q.
Solution: QFT extracts the period r of modular exponentiation a^x mod N, factoring N in polynomial time.
Interactive activity component
Build the Quantum Fourier Transform (QFT) circuit in Qiskit using Hadamard gates and controlled-phase rotations, and inspect the state evolution.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install qiskit numpy1 from qiskit import QuantumCircuit 2 from qiskit.quantum_info import Statevector 3 import numpy as np
from qiskit import QuantumCircuit → Circuit constructor
from qiskit.quantum_info import Statevector → Statevector analysis
import numpy as np → Trigonometric math
1 # Build 3-qubit QFT circuit: maps computational basis to Fourier basis 2 def build_qft_3qubit(): 3 qc = QuantumCircuit(3) 4 # Qubit 0 5 qc.h(0) 6 qc.cp(np.pi / 2, 1, 0) # Controlled-Phase pi/2 from q1 7 qc.cp(np.pi / 4, 2, 0) # Controlled-Phase pi/4 from q2 8 # Qubit 1 9 qc.h(1) 10 qc.cp(np.pi / 2, 2, 1) # Controlled-Phase pi/2 from q2 11 # Qubit 2 12 qc.h(2) 13 # Swap qubits 0 and 2 to reverse bit order 14 qc.swap(0, 2) 15 return qc 16 17 qft_circ = build_qft_3qubit() 18 print('=== 3-Qubit Quantum Fourier Transform Circuit ===') 19 print(qft_circ.draw('text')) 20 21 # Test QFT on input state |1> (|001>) 22 test_qc = QuantumCircuit(3) 23 test_qc.x(0) # Input |001> = decimal 1 24 test_qc.compose(qft_circ, inplace=True) 25 sv = Statevector.from_instruction(test_qc) 26 print('\nQFT Output Statevector on Input |1>:') 27 for i, amp in enumerate(sv.data): 28 phase_angle = np.angle(amp) * 180 / np.pi 29 print(f' |{i:03b}> : Magnitude={np.abs(amp):.3f}, Phase={phase_angle:6.1f} deg')
# Build 3-qubit QFT circuit: maps computational basis to Fourier basis
QFT definition
def build_qft_3qubit():
QFT builder function
qc = QuantumCircuit(3)
3 qubits
# Qubit 0
Wire 0
qc.h(0)
H on 0
qc.cp(np.pi / 2, 1, 0) # Controlled-Phase pi/2 from q1
CP pi/2
qc.cp(np.pi / 4, 2, 0) # Controlled-Phase pi/4 from q2
CP pi/4
# Qubit 1
Wire 1
qc.h(1)
H on 1
qc.cp(np.pi / 2, 2, 1) # Controlled-Phase pi/2 from q2
CP pi/2
# Qubit 2
Wire 2
qc.h(2)
H on 2
# Swap qubits 0 and 2 to reverse bit order
Bit swap
qc.swap(0, 2)
SWAP(0, 2)
return qc
Return circuit
qft_circ = build_qft_3qubit()
Instantiate
print('=== 3-Qubit Quantum Fourier Transform Circuit ===')
Header
print(qft_circ.draw('text'))
Print diagram
# Test QFT on input state |1> (|001>)
Test input
test_qc = QuantumCircuit(3)
Test circuit
test_qc.x(0) # Input |001> = decimal 1
Set input to 1
test_qc.compose(qft_circ, inplace=True)
Append QFT
sv = Statevector.from_instruction(test_qc)
Compute statevector
print('\nQFT Output Statevector on Input |1>:')
Output label
for i, amp in enumerate(sv.data):
Loop amplitudes
phase_angle = np.angle(amp) * 180 / np.pi
Calculate phase
print(f' |{i:03b}> : Magnitude={np.abs(amp):.3f}, Phase={phase_angle:6.1f} deg')
Display magnitude and phase
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Constructing the 3-Qubit Quantum Fourier Transform (QFT) in Qiskit 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install qiskit numpy 8 9 # Step 2: Import libraries 10 from qiskit import QuantumCircuit 11 from qiskit.quantum_info import Statevector 12 import numpy as np 13 14 # Step 3: Run Demonstration 15 # Build 3-qubit QFT circuit: maps computational basis to Fourier basis 16 def build_qft_3qubit(): 17 qc = QuantumCircuit(3) 18 # Qubit 0 19 qc.h(0) 20 qc.cp(np.pi / 2, 1, 0) # Controlled-Phase pi/2 from q1 21 qc.cp(np.pi / 4, 2, 0) # Controlled-Phase pi/4 from q2 22 # Qubit 1 23 qc.h(1) 24 qc.cp(np.pi / 2, 2, 1) # Controlled-Phase pi/2 from q2 25 # Qubit 2 26 qc.h(2) 27 # Swap qubits 0 and 2 to reverse bit order 28 qc.swap(0, 2) 29 return qc 30 31 qft_circ = build_qft_3qubit() 32 print('=== 3-Qubit Quantum Fourier Transform Circuit ===') 33 print(qft_circ.draw('text')) 34 35 # Test QFT on input state |1> (|001>) 36 test_qc = QuantumCircuit(3) 37 test_qc.x(0) # Input |001> = decimal 1 38 test_qc.compose(qft_circ, inplace=True) 39 sv = Statevector.from_instruction(test_qc) 40 print('\nQFT Output Statevector on Input |1>:') 41 for i, amp in enumerate(sv.data): 42 phase_angle = np.angle(amp) * 180 / np.pi 43 print(f' |{i:03b}> : Magnitude={np.abs(amp):.3f}, Phase={phase_angle:6.1f} deg')
Apply H gate followed by successive controlled-phase gates CP(pi/2^k).
Swap outermost qubits to align frequency register bit-significance.
Verify that all 8 basis states have equal magnitude 1/sqrt(8) with linear phase gradients.
Input state |001> processed through 3-qubit QFT circuit.
All 8 states have equal magnitude 0.354 (1/sqrt(8)) with distinct, linearly progressing phase rotations: 0, 45, 90, 135, 180, 225, 270, 315 degrees.
The QFT maps computational basis states into periodic phase patterns across all basis states in O(n^2) gates, compared to O(n * 2^n) operations for the classical Fast Fourier Transform (FFT). It is the mathematical engine of Shor's algorithm.
Oracle, diffusion operator, interference, and quadratic search speedup.
Test your understanding with these questions. Remember, this is for learning, not examination!