Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Synthesize Module 7: implement, simulate, and verify Shor’s period-finding core and Grover’s search in an end-to-end Python pipeline.
Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 7.6
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Executed iteration count | Number of Grover loop passes executed so far | |
| Angular rotation per Grover step | 2 arcsin(1/√N), the angle rotated toward the solution per step | |
| Database size | Total entries in the search space () | |
| Probability of measuring target item | Peaks near 100% when |
Calculating the success probability for N = 8 items (3 qubits) at k = 1 and k = 2 iterations:
Result: At k = 2 iterations, the success probability reaches 94.5%, finding the secret item among 8 choices with high confidence.
Apply Hadamard gates to initialize state |s>.
Apply phase oracle marking the target state.
Invert amplitudes across the mean.
Sample measurement distribution to extract the target.
Problem: Locating records across unsorted genomic gene banks.
Solution: Grover acceleration cuts database queries quadratically.
Interactive activity component
Construct and simulate a quantum period-finding circuit in Qiskit Aer to uncover periodic modular exponentiation frequencies.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install qiskit qiskit-aer numpy1 from qiskit import QuantumCircuit 2 from qiskit_aer import AerSimulator 3 import numpy as np
from qiskit import QuantumCircuit → Circuit module
from qiskit_aer import AerSimulator → Aer simulator
import numpy as np → Math utilities
1 # Simplified Quantum Period Finding Circuit for a=7, N=15 (Period r=4) 2 # Using 3 counting qubits and 2 work qubits 3 qc = QuantumCircuit(4, 2) 4 qc.h([0, 1]) # Superposition on counting register 5 qc.x(2) # Initialize work register to |1> 6 # Controlled modular multiplication gates 7 qc.cx(0, 3) # Controlled modular operation 1 8 qc.cx(1, 2) # Controlled modular operation 2 9 # Inverse QFT on counting register 10 qc.h(0) 11 qc.cp(-np.pi / 2, 1, 0) 12 qc.h(1) 13 qc.measure([0, 1], [0, 1]) 14 print('Quantum Period-Finding Circuit Diagram:') 15 print(qc.draw('text')) 16 17 # Simulate with AerSimulator 18 sim = AerSimulator() 19 counts = sim.run(qc, shots=1024).result().get_counts() 20 print('\nMeasured Frequencies on Counting Register (1024 shots):') 21 for state, freq in sorted(counts.items()): 22 print(f' State \'{state}\' : {freq} shots ({freq/1024*100:.1f}%)') 23 print('\nPeaks at specific bitstrings reveal the period r=4, cracking RSA key factors!')
# Simplified Quantum Period Finding Circuit for a=7, N=15 (Period r=4)
Setup
# Using 3 counting qubits and 2 work qubits
Register setup
qc = QuantumCircuit(4, 2)
4 qubits, 2 classical readout bits
qc.h([0, 1]) # Superposition on counting register
Counting superposition
qc.x(2) # Initialize work register to |1>
Work register to 1
# Controlled modular multiplication gates
Controlled gates
qc.cx(0, 3) # Controlled modular operation 1
Controlled op 1
qc.cx(1, 2) # Controlled modular operation 2
Controlled op 2
# Inverse QFT on counting register
Inverse QFT
qc.h(0)
Inverse H
qc.cp(-np.pi / 2, 1, 0)
Inverse CP
qc.h(1)
Inverse H
qc.measure([0, 1], [0, 1])
Measure counting register
print('Quantum Period-Finding Circuit Diagram:')
Label
print(qc.draw('text'))
Print diagram
# Simulate with AerSimulator
Simulation
sim = AerSimulator()
Backend
counts = sim.run(qc, shots=1024).result().get_counts()
Run 1024 shots
print('\nMeasured Frequencies on Counting Register (1024 shots):')
Counts label
for state, freq in sorted(counts.items()):
Iterate counts
print(f' State \'{state}\' : {freq} shots ({freq/1024*100:.1f}%)')
Print frequency
print('\nPeaks at specific bitstrings reveal the period r=4, cracking RSA key factors!')
Conclusion
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Simulating Shor's Period-Finding Circuit on AerSimulator in Qiskit 3 # Prepared for Google Colab (Run with Shift + Enter) 4 # ========================================================= 5 6 # Step 1: Install required packages 7 !pip install qiskit qiskit-aer numpy 8 9 # Step 2: Import libraries 10 from qiskit import QuantumCircuit 11 from qiskit_aer import AerSimulator 12 import numpy as np 13 14 # Step 3: Run Demonstration 15 # Simplified Quantum Period Finding Circuit for a=7, N=15 (Period r=4) 16 # Using 3 counting qubits and 2 work qubits 17 qc = QuantumCircuit(4, 2) 18 qc.h([0, 1]) # Superposition on counting register 19 qc.x(2) # Initialize work register to |1> 20 # Controlled modular multiplication gates 21 qc.cx(0, 3) # Controlled modular operation 1 22 qc.cx(1, 2) # Controlled modular operation 2 23 # Inverse QFT on counting register 24 qc.h(0) 25 qc.cp(-np.pi / 2, 1, 0) 26 qc.h(1) 27 qc.measure([0, 1], [0, 1]) 28 print('Quantum Period-Finding Circuit Diagram:') 29 print(qc.draw('text')) 30 31 # Simulate with AerSimulator 32 sim = AerSimulator() 33 counts = sim.run(qc, shots=1024).result().get_counts() 34 print('\nMeasured Frequencies on Counting Register (1024 shots):') 35 for state, freq in sorted(counts.items()): 36 print(f' State \'{state}\' : {freq} shots ({freq/1024*100:.1f}%)') 37 print('\nPeaks at specific bitstrings reveal the period r=4, cracking RSA key factors!')
Apply Hadamards to generate parallel query register.
Apply controlled operations that encode the periodic modular function f(x) = a^x mod N.
Extract period peaks from phase interference, enabling classical GCD factorization.
Quantum period-finding circuit evaluated over 1024 shots on AerSimulator.
Measured peaks at states '00' (~512 shots) and '10' (~512 shots). Identifies period r = 4 for modular base a=7 mod 15.
Shor's algorithm reduces integer factorization to period finding. Quantum interference isolates the period in polynomial time O((log N)^3), breaking RSA encryption which relies on the classical difficulty of factoring.
Oracle, diffusion operator, interference, and quadratic search speedup.
Test your understanding with these questions. Remember, this is for learning, not examination!