A hands-on, beginner-friendly demo of quantum error correction with the Steane [[7,1,3]] code. No previous knowledge of error correction is needed: each new idea is explained the first time it appears.
- Why can't we just copy the qubit and compare?
- Then how do we find an error without looking?
- How do we put one qubit into seven?
- How do we ask the checks without measuring the data?
- Does it really fix any single error?
- And if two errors happen?
- How much does it help with random noise?
- Is there a point where the code stops helping?
- Can we compute on the encoded qubit?
- So why don't we have error-free quantum computers yet?
- The 4 + 1 = 5 trick: three parity checks name the broken qubit.
- A dynamic circuit (Qiskit) that finds and fixes all 21 single-qubit errors, tested from both |0_L⟩ and |+_L⟩.
- A stim simulation checked against an exact count: about 16 p² failures, helping below about 8 % noise (perfect checks).
- Noisy checks in a small memory experiment, with two decoders: the code still helps below about 5 %, and at low noise the decoder that reads the rounds together fails about half as often.
- Transversal H, S and CNOT, and why the T gate needs magic states.
The models are deliberately simple (noise on data qubits, noisy check answers). Errors spreading inside the check circuits are explained but not simulated; see the notebook for the details.
pip install -r requirements.txt
jupyter notebook steane_demo.ipynb
In Colab, the first code cell installs the missing packages automatically. The notebook was tested with qiskit 2.2.3, qiskit-aer 0.17.2 and stim 1.14.0 (Python 3.9), and with qiskit 2.6.2, qiskit-aer 0.18.2 and stim 1.16.0 (Python 3.11); all cells run in about 10 seconds. Newer stim versions draw different random samples, so the simulated points move slightly; the exact curve and the conclusions do not.
| File | What it is |
|---|---|
steane_demo.ipynb |
The notebook (executed, with outputs). |
build_demo.py |
Generates the notebook; python3 build_demo.py --execute rebuilds and runs it. |
steane_sim.py |
Stand-alone simulation (stim + exact count) that writes steane.json. |
steane.json |
Data behind the social-media figure: failure rate versus noise and break-even point. |
figures/ |
The social-media figures (figures/images/) and their scripts, e.g. python3 figures/make_steane_steps.py out. |
Three open tasks, from a first run to research:
- #1 (good first issue): run 3 rounds of noisy checks and compare the two decoders. No code changes needed.
- #2 (good first issue): compare the Steane code with the 3-qubit repetition code.
- #3 (help wanted): circuit-level noise, with errors inside the check circuits and flag qubits.
Edit build_demo.py (it generates the notebook) and run python3 build_demo.py --execute. Questions, results
and corrections are welcome as issues; if you share a plot, tag @qalycat.
- shor-resource-estimate: how many physical qubits Shor's algorithm needs, and why almost all of them go to error correction.
- A. M. Steane, Phys. Rev. Lett. 77, 793 (1996).
- R. W. Hamming, Bell Syst. Tech. J. 29, 147 (1950).
- L. Postler et al., Nature 605, 675 (2022).
- Google Quantum AI and collaborators, Nature 638, 920 (2025).
- C. Gidney, Quantum 5, 497 (2021).
MIT. Created by Alberto Maldonado Romo (@qalycat).