Project 10 · Ladder 3 · Advanced
Quantum Error Correction: beat the noise
How it works
- One logical qubit, stored in three. Noise flips one of them (red).
- Two syndrome qubits find the flip without reading the data, and it's undone.
Real qubits make mistakes. Tonight you build the fix: spread one qubit over three, catch errors without ever looking at the data, and repair them live, halfway through the circuit. Then you measure exactly how much noise your code can beat.
- Level
- Advanced
- Hours
- 5 to 7
- Automated tests
- 23
- Ships to
- GitHub
What you build
Quantum Error Correction in Python and Qiskit
In 1995 Peter Shor published the first quantum error-correcting code, and showed that a qubit can be protected even though you can't copy it and you can't look at it. In December 2024 Google's Willow chip showed bigger codes finally winning: each step up in code size cut the logical error rate by a factor of 2.14.
You build where all of that starts: a classical repetition code, then the 3-qubit bit-flip code with ancilla qubits that measure the syndrome and live corrections that fix the qubit it points at, all under a seeded noise model. You watch a 5% error rate drop below 1%, find the code's blind spot, beat it with the phase-flip code, chart logical against physical error rate, and find the break-even point.
The quantum ideas inside
- Syndrome measurement
- Ancilla qubits
- Bit-flip and phase-flip codes
- Logical error rate
- Fault tolerance
New to Qiskit? Run your first circuit free, or warm up with the free Qiskit tutorials.
Real output · Project 10Qiskit Aer simulator
python error_correction.py --seed 7 --plot qec_results.png
== Classical baseline: 3-bit repetition code, majority vote (100,000 trials each) ==
p = 0.05: simulated 0.0071, theory 3p^2 - 2p^3 = 0.0073
p = 0.10: simulated 0.0283, theory 3p^2 - 2p^3 = 0.0280
p = 0.20: simulated 0.1049, theory 3p^2 - 2p^3 = 0.1040
== Your bit-flip code ==
Peek (exact statevector): encoding + gives +0.707|000> +0.707|111>
Syndrome table, bit-flip code (no random noise, 100 shots per row):
injected syndrome decoder flips stored 0, read back
nothing 00 nothing 0 correct
X on q0 01 q0 0 correct
X on q1 11 q1 0 correct
X on q2 10 q2 0 correct
X on q0 and q1 10 q2 1 WRONG: two errors look like one
== Beat the noise at p = 0.05 (4,000 shots each) ==
Unencoded qubit, X noise 0.0553
Bit-flip code, X noise 0.0080 theory 0.0073 6.2x fewer errors
Bit-flip code storing +, Z noise 0.1310 theory 0.1355 the blind spot: 2.6x MORE errors
Phase-flip code, Z noise 0.0080 theory 0.0073 6.2x fewer errors
== The sweep, distance 3 (4,000 shots per point) ==
p unencoded bit-flip(X) phase-flip(Z) blind spot theory
0.05 0.0553 0.0080 0.0080 0.1310 0.0073
0.10 0.0998 0.0293 0.0293 0.2360 0.0280
0.15 0.1525 0.0585 0.0585 0.3252 0.0607
0.20 0.2127 0.1000 0.1000 0.3875 0.1040
0.30 0.3065 0.2162 0.2162 0.4597 0.2160
0.40 0.4025 0.3510 0.3510 0.4880 0.3520
0.50 0.5118 0.4968 0.4968 0.4880 0.5000
0.60 0.5905 0.6458 0.6458 0.4845 0.6480
Break-even, bit-flip code: beats an unencoded qubit for every p below 0.51 (theory: exactly 0.5)
Chart saved to qec_results.png
By the end
What you walk away with
- a classical repetition code whose error rate matches the formula 3p² − 2p³
- a 3-qubit bit-flip code with ancilla syndrome measurement and live correction (mid-circuit measurement plus
if_test) - a phase-flip code that catches the errors the bit-flip code can't even see
- a seeded noise model, a sweep of logical against physical error rate, and the break-even point
qec_results.png: where the code wins, and how fast its advantage grows as the noise falls- the noisy-gates experiment (Section 11) that shows why toy codes aren't enough
- 23 tests, plus 5 challenge tests for Shor's 9-qubit code and a distance-5 code
- a public GitHub repo, a portfolio paragraph and a LinkedIn post
Where it sits
Ladder 3: Advanced
AdvancedLadder 3
Shor's Algorithm
Break RSA in miniature.
Quantum Teleportation
Teleport a qubit, then send two bits by moving one.
Quantum Error Correction
Take a 5% error rate below 1%.
Your first circuit is 10 minutes away
Stop watching quantum. Start shipping it.
$0 today. 7 days free, then $7.99 a week or $190 a year. Cancel any time.