Simulating a Surface Code QEC Cycle with Qiskit
Quantum error correction (QEC) is the key ingredient that turns noisy physical qubits into reliable logical qubits. The surface code is currently the leading QEC scheme for superconducting processors: it arranges data qubits on a 2D lattice interleaved with ancilla qubits that repeatedly measure stabilizers — parity checks that reveal errors without disturbing the encoded information.
Rather than only describing the idea, I embedded a runnable Jupyter notebook below. It builds a single QEC cycle of the 3×3 surface code (9 data qubits, 4 Z-type ancillas, 4 X-type ancillas) in Qiskit — including a unitary encoding step that prepares the logical $\lvert 0\rangle_L$ state — injects a deliberate error, and reads out the syndrome. Feel free to download the notebook and run it yourself — the required packages are qiskit, qiskit-aer, and pylatexenc.
Try it yourself: syndrome lookup
The notebook is fully deterministic, so here is an interactive replica that runs entirely in your browser. Pick a data qubit and an error type; the widget computes the resulting 8-bit syndrome ($Z_1 Z_2 Z_3 Z_4 X_1 X_2 X_3 X_4$) and shows which stabilizers are violated. These results match the simulations above exactly.
What to look for
- No error: the syndrome is clean — all stabilizer parities read +1 (
00000000modulo measurement noise from the ancilla preparation scheme used in the demo). - X error on a data qubit: flips the surrounding Z stabilizers, so the first four syndrome bits light up.
- Z error on a data qubit: flips the surrounding X stabilizers, lighting up the last four syndrome bits.
- A data qubit in the middle of the lattice (D5) is adjacent to all four stabilizers of each type, so a single error there produces a maximal-weight syndrome — this is exactly the kind of pattern the decoder must disambiguate in real experiments.
Decoding these patterns back to the most likely physical error is the job of a classical decoder running in real time — the subject of the landmark experiment cited below.
References
[1] S. Krinner et al, Realizing repeated quantum error correction in a distance-three surface code, Nature 605, 669–674 (2022). doi:10.1038/s41586-022-04566-1 \
Enjoy Reading This Article?
Here are some more articles you might like to read next: