Launch the interactive walkthrough to discover each component, including the 3D Q-Sphere Lab & Python in Colab.
Synthesize Module 6: build a complete state-vector simulator in Python that evolves multi-qubit states and computes measurement histograms.
Interactive 3D state vector exploration, unitary transformation gates, and Born rule collapse for Topic 6.12
| Symbol / Term | Meaning | Beginner Interpretation |
|---|---|---|
| Greenberger-Horne-Zeilinger state | 3-qubit maximally entangled state | |
| Hadamard on qubit 0 | Opens qubit 0 into superposition while qubits 1 and 2 remain in ground state | |
| CNOT from qubit 0 to 1 | Entangles qubit 1 with qubit 0 | |
| CNOT from qubit 1 to 2 | Entangles qubit 2 with qubit 1 |
Simulating 1,000 shots on AerSimulator vs exact Statevector:
Result: Measurement outcomes converge to theoretical 50/50 distribution with zero occurrences of mixed states (like 001, 010, etc.).
Initialize length-8 vector |000>.
Creates (|000> + |100>)/sqrt(2).
Flips Q1 if Q0 is 1: (|000> + |110>)/sqrt(2).
Flips Q2 if Q1 is 1: (|000> + |111>)/sqrt(2).
Problem: Sharing an encryption key among 3 intelligence officials such that no two can decrypt without the third.
Solution: GHZ state correlations require all 3 parties to collaborate to reconstruct the key.
Interactive activity component
Compare ideal analytical statevector simulation against stochastic shot-based sampling with AerSimulator in Qiskit.
For Google Colab or Jupyter notebooks, run this shell command to install the required dependencies:
!pip install qiskit qiskit-aer1 from qiskit import QuantumCircuit 2 from qiskit.quantum_info import Statevector 3 from qiskit_aer import AerSimulator
from qiskit import QuantumCircuit → Circuit constructor
from qiskit.quantum_info import Statevector → Analytical statevector simulator
from qiskit_aer import AerSimulator → Stochastic shot-based simulator
1 # 1. Define quantum circuit 2 qc = QuantumCircuit(2, 2) 3 qc.h(0) 4 qc.cx(0, 1) 5 6 # 2. Analytical Simulation: Statevector (Exact Probabilities) 7 sv = Statevector.from_instruction(qc) 8 print('--- Method 1: Statevector Simulation (Exact) ---') 9 print('Exact Probabilities:', sv.probabilities_dict()) 10 11 # 3. Stochastic Simulation: AerSimulator (Shot-based Sampling) 12 qc.measure([0, 1], [0, 1]) 13 sim = AerSimulator() 14 counts_100 = sim.run(qc, shots=100).result().get_counts() 15 counts_10000 = sim.run(qc, shots=10000).result().get_counts() 16 print('\n--- Method 2: AerSimulator (Statistical Sampling) ---') 17 print('100 Shots Counts :', counts_100) 18 print('10,000 Shots Counts:', counts_10000) 19 print('\nNotice: As shots increase, empirical frequencies converge to exact Born rule probabilities!')
# 1. Define quantum circuit
Circuit setup
qc = QuantumCircuit(2, 2)
2 qubits
qc.h(0)
Superposition
qc.cx(0, 1)
CNOT
# 2. Analytical Simulation: Statevector (Exact Probabilities)
Method 1
sv = Statevector.from_instruction(qc)
Compute exact amplitudes
print('--- Method 1: Statevector Simulation (Exact) ---')
Header 1
print('Exact Probabilities:', sv.probabilities_dict())
{'00': 0.5, '11': 0.5}
# 3. Stochastic Simulation: AerSimulator (Shot-based Sampling)
Method 2
qc.measure([0, 1], [0, 1])
Add measurements
sim = AerSimulator()
Initialize simulator
counts_100 = sim.run(qc, shots=100).result().get_counts()
Run 100 shots
counts_10000 = sim.run(qc, shots=10000).result().get_counts()
Run 10,000 shots
print('\n--- Method 2: AerSimulator (Statistical Sampling) ---')
Header 2
print('100 Shots Counts :', counts_100)
Show statistical noise at low shots
print('10,000 Shots Counts:', counts_10000)
Show convergence to 50/50 at high shots
print('\nNotice: As shots increase, empirical frequencies converge to exact Born rule probabilities!')
Law of large numbers
Click "Copy for Colab", open Google Colab, paste into a single cell, and run.
1 # ========================================================= 2 # Statevector vs Shot-Based Simulation 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 8 9 # Step 2: Import libraries 10 from qiskit import QuantumCircuit 11 from qiskit.quantum_info import Statevector 12 from qiskit_aer import AerSimulator 13 14 # Step 3: Run Demonstration 15 # 1. Define quantum circuit 16 qc = QuantumCircuit(2, 2) 17 qc.h(0) 18 qc.cx(0, 1) 19 20 # 2. Analytical Simulation: Statevector (Exact Probabilities) 21 sv = Statevector.from_instruction(qc) 22 print('--- Method 1: Statevector Simulation (Exact) ---') 23 print('Exact Probabilities:', sv.probabilities_dict()) 24 25 # 3. Stochastic Simulation: AerSimulator (Shot-based Sampling) 26 qc.measure([0, 1], [0, 1]) 27 sim = AerSimulator() 28 counts_100 = sim.run(qc, shots=100).result().get_counts() 29 counts_10000 = sim.run(qc, shots=10000).result().get_counts() 30 print('\n--- Method 2: AerSimulator (Statistical Sampling) ---') 31 print('100 Shots Counts :', counts_100) 32 print('10,000 Shots Counts:', counts_10000) 33 print('\nNotice: As shots increase, empirical frequencies converge to exact Born rule probabilities!')
Compute exact 2^n complex amplitudes analytically without measurement collapse.
Simulate physical quantum hardware shots, observing statistical sampling variance.
Observe how 10,000 shots approaches the exact 50.0% theoretical probability.
Bell state circuit evaluated with Statevector and AerSimulator (100 vs 10,000 shots).
Exact: {'00': 0.5, '11': 0.5}
100 Shots: {'00': ~48, '11': ~52}
10,000 Shots: {'00': ~5004, '11': ~4996}Statevector simulation computes the mathematical wave function directly (useful for small circuits up to 30 qubits). AerSimulator models physical quantum hardware sampling, where multiple shots are required to reconstruct probability distributions.
Hadamard gate, quantum registers, simulation, and histogram measurement.
Test your understanding with these questions. Remember, this is for learning, not examination!