Steane's 7-Qubit Code
Overview
Steane's code is a [[7,1,3]] CSS code — it encodes 1 logical qubit into 7 physical qubits with distance 3, correcting any single-qubit error. Built from the classical Hamming [7,4,3] code, it is more efficient than Shor's 9-qubit code (rate 1/7 vs 1/9) and has the remarkable property that H, CX, and S gates can be applied transversally (bitwise), making them automatically fault-tolerant.
CSS Code Construction
Steane's code is a Calderbank-Shor-Steane (CSS) code, meaning its X and Z stabilizers come from independent classical codes:
- Start with the Hamming [7,4,3] code (classical, corrects 1 bit error)
- The Hamming parity check matrix defines Z stabilizers (detect X errors)
- The same parity check matrix defines X stabilizers (detect Z errors)
- Because the Hamming [7,4,3] code contains its own dual (C-perp is a subset of C), this works!
Because the X and Z stabilizers come from the same check matrix, applying H to all 7 qubits swaps them and maps the code to itself. This is what makes transversal H possible.
Stabilizers
X Stabilizers (detect Z errors)
| Stabilizer | Qubits | Operator |
|---|---|---|
| g1 | 3, 4, 5, 6 | X_3 X_4 X_5 X_6 |
| g2 | 1, 2, 5, 6 | X_1 X_2 X_5 X_6 |
| g3 | 0, 2, 4, 6 | X_0 X_2 X_4 X_6 |
Z Stabilizers (detect X errors)
| Stabilizer | Qubits | Operator |
|---|---|---|
| g4 | 3, 4, 5, 6 | Z_3 Z_4 Z_5 Z_6 |
| g5 | 1, 2, 5, 6 | Z_1 Z_2 Z_5 Z_6 |
| g6 | 0, 2, 4, 6 | Z_0 Z_2 Z_4 Z_6 |
Logical Operators
- X_L = X_0 X_1 X_2 X_3 X_4 X_5 X_6 (X on all qubits)
- Z_L = Z_0 Z_1 Z_2 Z_3 Z_4 Z_5 Z_6 (Z on all qubits)
Syndrome Table
The syndrome, written g1 g2 g3 for X stabilizers or g4 g5 g6 for Z stabilizers (first stabilizer on the left), equals (qubit_index + 1) in binary. Qiskit prints the ancilla bits in the reverse order (last ancilla on the left), so read a printed syndrome string right to left: an X error on qubit 0 prints as 100. The correction step in circuit.py reverses the bits before it looks up this table (decode_syndrome does the same for a printed string), so each correction lands on the flagged qubit.
| Syndrome | Error Location |
|---|---|
| 000 | No error |
| 001 | Qubit 0 |
| 010 | Qubit 1 |
| 011 | Qubit 2 |
| 100 | Qubit 3 |
| 101 | Qubit 4 |
| 110 | Qubit 5 |
| 111 | Qubit 6 |
The Z syndrome identifies X errors; the X syndrome identifies Z errors. For a Y error, both syndromes are non-trivial (same location).
The Encoding Circuit
Encoding |0⟩_L: apply H to q0, q1 and q3, then CX from q3 to q4, q5, q6; from q1 to q2, q5, q6; and from q0 to q2, q4, q6. Each H qubit appears in exactly one stabilizer support ({3,4,5,6}, {1,2,5,6}, {0,2,4,6}), so the result is the equal superposition of the 8 even-weight Hamming codewords: all six stabilizers read +1 and Z_L reads +1. For |1⟩_L, apply X to all seven qubits afterwards (X_L = X on all qubits), which gives the 8 odd-weight codewords.
create_steane_encoder() builds this circuit, and because its default is logical_state=1 it ends with the X layer on all seven qubits: 19 gates (3 H, 9 CX, 7 X), depth 7. This is the circuit a Run executes. Measured on all seven qubits (simulator, 1,024 shots) it returns only the 8 odd-weight codewords (the seven weight-3 codewords and 1111111), each in 10% to 15% of shots across 20 runs (ideal: 12.5%).
CODE┌───┐ q_0: ┤ H ├───────■──────────────■─────────■── ├───┤ │ │ │ q_1: ┤ H ├──■────┼─────────■────┼────■────┼── └───┘┌─┴─┐┌─┴─┐ │ │ │ │ q_2: ─────┤ X ├┤ X ├───────┼────┼────┼────┼── ┌───┐└───┘└───┘ │ │ │ │ q_3: ┤ H ├──■────■────■────┼────┼────┼────┼── └───┘┌─┴─┐ │ │ │ ┌─┴─┐ │ │ q_4: ─────┤ X ├──┼────┼────┼──┤ X ├──┼────┼── └───┘┌─┴─┐ │ ┌─┴─┐└───┘ │ │ q_5: ──────────┤ X ├──┼──┤ X ├───────┼────┼── └───┘┌─┴─┐└───┘ ┌─┴─┐┌─┴─┐ q_6: ───────────────┤ X ├──────────┤ X ├┤ X ├ └───┘ └───┘└───┘
Transversal Gates — The Key Advantage
Steane's code supports transversal (bitwise) application of several gates:
| Gate | Application | Fault-Tolerant? |
|---|---|---|
| H | Apply H to all 7 qubits | Yes (swaps X <-> Z stabilizers) |
| CX | Apply CX bitwise between two code blocks | Yes |
| S | Apply S† to all 7 qubits (S on all 7 gives logical S†) | Yes |
| X, Y, Z | Apply bitwise | Yes |
| T | NOT transversal | No (needs magic state distillation) |
Why this matters: Transversal gates cannot spread errors between qubits within a code block. A single-qubit error stays a single-qubit error, so the code can still correct it. This is the simplest route to fault tolerance.
Running the Circuit
PYTHONfrom circuit import run_circuit, verify_steane_code # No error result = run_circuit() print(f"Success: {result['success_rate']:.2%}") # X error on qubit 3: the Z syndrome flags qubit 3 and an X there undoes it result = run_circuit(error_type='X', error_qubit=3) print(f"After correction: {result['success_rate']:.2%}") # Z error on qubit 5: a Z error cannot change a Z-basis readout, so run it # on |->_L (basis='X', prepared with transversal H) to see the correction result = run_circuit(error_type='Z', error_qubit=5, basis='X') print(f"After correction: {result['success_rate']:.2%}") # Full verification: no error and every single X, Y and Z error on q0 to q6, # for |0>_L, |1>_L, |+>_L and |->_L (88 cases), checking the corrected # logical value and that the syndrome flags the right qubit v = verify_steane_code() for check in v["checks"]: print(f"[{'PASS' if check['passed'] else 'FAIL'}] {check['name']}")
On the noiseless Aer simulator each success rate above prints 100.00%, and verify_steane_code() passes all 88 cases (4,096 shots each): every single X, Y and Z error on every qubit is corrected for all four logical states. The X-basis cases matter: in the default Z basis a Z error that went uncorrected would still score 100%. These are simulator results; on hardware, noise in the gates and in the syndrome measurement itself lowers them.
Code Properties
| Property | Value |
|---|---|
| Notation | [[7, 1, 3]] |
| Physical qubits | 7 |
| Logical qubits | 1 |
| Code distance | 3 |
| Correctable errors | t = 1 (any type) |
| Rate | 1/7 ~ 0.143 |
| Syndrome qubits | 6 (3 for X, 3 for Z) |
| Total qubits | 13 |
| Code family | CSS (dual-containing Hamming code) |
Comparison with Shor Code
| Feature | Shor [[9,1,3]] | Steane [[7,1,3]] |
|---|---|---|
| Physical qubits | 9 | 7 |
| Rate | 1/9 | 1/7 |
| Structure | Concatenated | CSS (algebraic) |
| Syndrome qubits | 8 | 6 |
| Transversal H | No | Yes |
| Transversal CX | Yes (it is also a CSS code) | Yes |
| Total qubits | 17 | 13 |