Curriculum / Real-World Quantum Python / Noise Modeling in Python
Noise Modeling in Python
Build a noisy quantum simulator and learn how to characterize and model real hardware noise.
Noise Modeling in Python
Real quantum hardware is imperfect. To write quantum programs that work on real devices, you must model and account for noise. Python gives us the tools to build realistic noise models and test circuits against them before submitting to hardware.
Types of Quantum Noise
Coherent Errors Systematic rotation errors, e.g., a gate that should apply RX(π) actually applies RX(π + 0.01). Coherent errors add up across a circuit (they don't average out).
Modeling: Add a small random rotation after each gate.
Depolarizing Noise The most commonly used simplified model. After a gate, with probability p, apply a uniformly random Pauli error (X, Y, or Z).
def depolarizing_channel(density_matrix, p):
rho = density_matrix
X = [[0,1],[1,0]]; Y = [[0,-1j],[1j,0]]; Z = [[1,0],[0,-1]]
rho_new = (1-p)*rho + (p/3)*(X@rho@X + Y@rho@Y + Z@rho@Z)
return rho_newIn state vector simulation, depolarizing is equivalent to: with probability p, sample and apply X, Y, or Z.
Typical values:
- •Single-qubit gate error: p ≈ 0.001 (0.1%)
- •Two-qubit gate (CNOT) error: p ≈ 0.01 (1%)
- •Measurement error: p_meas ≈ 0.01–0.05
T1 Relaxation (Energy Decay) |1⟩ spontaneously decays to |0⟩ with characteristic time T1. The amplitude damping channel:
A₀ = [[1, 0], [0, √(1-γ)]], A₁ = [[0, √γ], [0, 0]]
where is the decay probability for gate time t.
Typical values: T1 ≈ 100 μs to 1 ms (superconducting qubits in 2024).
T2 Dephasing (Phase Decay) Random phase kicks accumulate, destroying phase coherence. The dephasing channel adds Z noise:
Characteristic time T2 ≤ 2T1 (T2 cannot exceed 2T1 by quantum mechanics).
For a gate of duration t, dephasing probability: .
This is the opening of the lesson. The full walkthrough, the interactive circuit, and the graded challenge continue inside myqubit.
How this lesson works
A guided reading lesson with interactive knowledge checks. Concepts are explained step by step with circuit diagrams and runnable examples, and you confirm understanding before moving on.
Part of: Real-World Quantum Python
Write production-quality quantum Python, circuit optimization, hybrid algorithms, cloud backends, noise modeling, and software engineering patterns.
This lesson is part of Pro
Unlock Real-World Quantum Python and all 10 tracks with Pro: $12.99/month, $79/year, or $97 lifetime. Start with the free track first if you are new.