Shor's code is the first quantum error correcting code capable of correcting any single-qubit error (X, Y, or Z). It achieves this by combining bit-flip and phase-flip codes.
Logical qubit → [Phase-flip code] → [Bit-flip code] → 9 physical qubits
(3 blocks) (3 qubits each)
| Logical | Encoded State |
|---|
| |0⟩_L | ( |
| |1⟩_L | ( |
┌───┐ ┌───┐
q_0: ──┤ ├──■──┤ H ├──■────■──
│ │ │ └───┘┌─┴─┐ │
q_1: ──┤ ├──┼───────┤ X ├──┼──
│ │ │ └───┘┌─┴─┐
q_2: ──┤ ├──┼────────────┤ X ├
│ CX│┌─┴─┐┌───┐
q_3: ──┤ ├┤ X ├┤ H ├──■────■──
│ │└───┘└───┘┌─┴─┐ │
q_4: ──┤ ├──────────┤ X ├──┼──
│ │ └───┘┌─┴─┐
q_5: ──┤ ├───────────────┤ X ├
│ │┌───┐┌───┐
q_6: ──┤ ├┤ X ├┤ H ├──■────■──
└───┘└───┘└───┘┌─┴─┐ │
q_7: ─────────────────┤ X ├──┼──
└───┘┌─┴─┐
q_8: ──────────────────────┤ X ├
└───┘
- Detected within each 3-qubit block
- Same as 3-qubit repetition code
- Majority vote determines correction
- Detected across the three blocks
- Check relative phases between blocks
- Sign majority determines correction
- Y = iXZ (both bit and phase flip)
- Corrected by detecting both X and Z components
from circuit import run_circuit
# No error
result = run_circuit()
print(f"Success: {result['success_rate']:.2%}")
# X error on qubit 4
result = run_circuit(error_type='X', error_qubit=4)
print(f"After X correction: {result['success_rate']:.2%}")
# Y error (both X and Z)
result = run_circuit(error_type='Y', error_qubit=2)
print(f"After Y correction: {result['success_rate']:.2%}")
| Property | Value |
|---|
| Physical qubits | 9 |
| Logical qubits | 1 |
| Distance | 3 |
| Correctable errors | t = 1 |
| Rate | 1/9 |
- First complete QEC code (1995)
- Proved quantum error correction is possible
- Showed quantum computers can be fault-tolerant
- Foundation for all subsequent codes
| Code | Qubits | Corrects |
|---|
| Bit-flip | 3 | X only |
| Phase-flip | 3 | Z only |
| Shor | 9 | X, Y, Z |
| Steane | 7 | X, Y, Z |
| Surface | O(d²) | X, Y, Z |