Quantum Error Mitigation โ Noise Channels, Readout Calibration, and Zero-Noise Extrapolation (Linear + Richardson), plus Shor Circuit-Prep โ by Darion Kellar
Educational quantum error mitigation lab in ONE pure-Python file: it simulates four noise channels (depolarizing, bit-flip, phase-flip, amplitude damping) acting on qubit expectation values, calibrates readout error with a measured confusion matrix and removes it by matrix inversion, and recovers noiseless expectation values from deliberately noise-scaled runs by zero-noise extrapolation. The headline numbers, all printed by the program itself: readout total-variation error falls from 0.015000 to 0.000000 after calibration mitigation, and for the ZNE circuit (ideal โจZโฉ = +0.891207) the raw noisy value at scale 1.0 is +0.774513, linear extrapolation recovers +0.846836, and Richardson extrapolation recovers +0.891162 โ within 0.000045 of ideal. A Shor circuit-prep section finds the period classically (N = 15, a = 7 โ period 4 โ factors 3 and 5; N = 21, a = 2 โ period 6 โ factors 3 and 7) and is labelled, in its own output, as a classical simulation of the quantum subroutine โ no quantum hardware is claimed anywhere.
Pure Python standard library. Zero dependencies. Zero network. Honest scope: every number here comes from simulated math on a laptop CPU โ no real device was run, no hardware error rate is certified, and the Shor section prepares and factors by classical period finding, not by executing a quantum circuit.
โ ๐งฐ Tech Stack Badges & Full Architecture Tech Stack
๐ Python 3.12, pure standard library (math, json, sys) โ zero dependencies, zero network, deterministic (double-run byte-identical)
๐ฒ Noise model from config.json: depolarizing 0.02, bit-flip 0.01, phase-flip 0.01, amplitude damping 0.03, each channel applied as its exact expectation-value map
๐งฎ Readout calibration: per-qubit error rates (e0 = [0.03, 0.04], e1 = [0.05, 0.06]) build the 2-qubit confusion matrix; mitigation is the matrix inverse applied to the measured distribution
๐ Zero-noise extrapolation: expectation values at scale factors [1.0, 1.5, 2.0, 2.5, 3.0] (ฮธ = 1.1), fitted back to zero noise two ways โ linear fit and full Richardson extrapolation
๐ข Shor circuit-prep: modular-exponentiation period finding feeding the standard gcd factor extraction, labelled classical simulation in its own output
๐ซ Not applicable โ honestly. No blockchain, no Web3, no tokens: the "infrastructure" in this lab is noise arithmetic and matrix inversion inside one offline file. No fake badges here.
โ โ๏ธ Platform Support & Hardware Architecture
๐ฅ๏ธ Pure Python โ runs anywhere Python 3.12+ runs (Linux, macOS, Windows), plus the python:3.12-slim Docker image
๐ No quantum hardware is controlled, ever: this is a simulation of mitigation mathematics, not a device driver
๐ซ No low-level code โ honestly. No C, no C++, no GPU, no compiled extensions, and no qiskit: this is one interpreted Python file on purpose, so every channel map, every matrix entry, and every extrapolation weight can be read, checked, and diffed. Performance here means exact arithmetic instead of sampling โ the mitigated values are computed, not estimated from shots.
๐ซ None โ honestly. No cloud provider is used or needed: the lab runs fully offline on your own machine or in a local Docker container. Docker Hub appears only as the registry the publish workflow pushes the image to.
Four noise channels, exact maps โ depolarizing, bit-flip, phase-flip, and amplitude damping, each applied as the closed-form map it induces on expectation values, with rates read from config.json so the whole noise model is one editable file.
Readout calibration that actually inverts โ the confusion matrix is built from measured per-qubit error rates, checked for invertibility by the built-in checks, and its inverse takes the measured distribution [0.4866, 0.2484, 0.1614, 0.1036] back to the true [0.5, 0.25, 0.15, 0.1] exactly: TV error 0.015000 โ 0.000000.
ZNE at five scale factors โ โจZโฉ decays +0.774513 โ +0.726906 โ +0.685443 โ +0.649461 โ +0.618361 as noise scales 1.0 โ 3.0, and both extrapolations are graded against the known ideal +0.891207 in the same output.
Linear vs Richardson, side by side โ the linear fit recovers +0.846836 (error 0.044371); Richardson recovers +0.891162 (error 0.000045), roughly a thousand times closer, and the program prints both so the difference is a number, not a claim.
Shor circuit-prep, honestly labelled โ period finding over the modular-exponentiation sequence: N = 15, a = 7 gives period 4 and factors 3 ร 5; the built-in checks also grade N = 21 = 3 ร 7. The output itself states the period was found by classical simulation of the quantum subroutine.
A referee suite, not just tests โ the built-in CHECKS verify the confusion matrix is invertible, that mitigation recovers the true distribution and beats raw readout, that Richardson beats linear, and that a CNOT builds a Bell state โ 20/20, alongside 35 pytest tests.