Depolarizing Noise in Aer
Compare a Bell state on an ideal simulator and on one with depolarizing noise on H and CNOT; 01 and 10 appear at about 5% with noise.
The Depolarizing Channel is $\rho\to(1-\lambda)\rho+\lambda I/d$. In depolarizing_error(λ, n) from Qiskit Aer the parameter is $\lambda$. With $\lambda=0.1$ on the CNOT, a fraction $\lambda$ of the state goes to the uniform mixture, which gives 01 or 10 with probability $1/2$; so the theoretical expectation is $P(01)+P(10)=0.05$. An error on H before the CNOT does not produce 01 or 10. The run gave $0.045$, within statistical fluctuation. The values are for teaching and do not represent any particular device.
Requirements: pip install qiskit qiskit-aer. The code runs on your machine or in Colab, not inside WordPress.
Code
from qiskit import QuantumCircuit, transpile
from qiskit_aer import AerSimulator
from qiskit_aer.noise import NoiseModel, depolarizing_error
qc = QuantumCircuit(2, 2)
qc.h(0)
qc.cx(0, 1)
qc.measure([0, 1], [0, 1])
noise = NoiseModel()
noise.add_all_qubit_quantum_error(depolarizing_error(0.01, 1), ["h"])
noise.add_all_qubit_quantum_error(depolarizing_error(0.10, 2), ["cx"])
ideal = AerSimulator()
noisy = AerSimulator(noise_model=noise)
for name, sim in [("ideal", ideal), ("noisy", noisy)]:
tqc = transpile(qc, sim)
counts = sim.run(tqc, shots=4000, seed_simulator=17).result().get_counts()
good = (counts.get("00", 0) + counts.get("11", 0)) / 4000
print(name, dict(sorted(counts.items())), "| P(00 or 11) =", good)
Line-by-line code explanation
| Line | Explanation |
|---|---|
| 1-3 | Imports: the circuit, the simulator and the noise tools. |
| 5-8 | A Bell circuit with measurement. |
| 10 | An empty noise model. |
| 11 | Depolarisation λ = 0.01 on every H gate. |
| 12 | Two-qubit depolarisation λ = 0.1 on every CNOT. |
| 14-15 | An ideal simulator and a noisy one. |
| 16 | Loop over the two simulators. |
| 17 | Transpile the circuit. |
| 18 | 4000 shots with seed 17. |
| 19 | Fraction of correct outcomes 00 or 11. |
| 20 | Print. |
Expected output (from an actual run)
ideal {'00': 2009, '11': 1991} | P(00 or 11) = 1.0
noisy {'00': 1864, '01': 91, '10': 90, '11': 1955} | P(00 or 11) = 0.95475
Counts from AerSimulator with seed_simulator=17; the theoretical value with noise is P(00 or 11) = 0.95.
Try it yourself
Related topics
References
- Qiskit contributors (2025). Qiskit Aer documentation. GitHub Pages qiskit.github.io
- Michael A. Nielsen; Isaac L. Chuang (2010). Quantum Computation and Quantum Information (10th Anniversary Edition). Cambridge University Press doi:10.1017/CBO9780511976667The standard reference for quantum computing; the Crossref record gives 2012 for the Cambridge Core online edition.
- John Preskill (2018). Quantum Computing in the NISQ era and beyond. Quantum 2:79 doi:10.22331/q-2018-08-06-79
