A complete, deterministic implementation of the GF(4)-symplectic framework for the Steane [[7,1,3]] quantum error-correcting code, with verification of all mathematical claims.
This repository provides a literature-backed implementation of the unified GF(4)-symplectic framework for quantum error correction, following:
A. H. Mir, "A Unified GF(4)-Symplectic Framework for Quantum Error Correction: A Constructive, Pedagogical Derivation of the Steane [[7,1,3]] Code," Preprints.org, doi:10.20944/preprints202512.0353.v1 (2025).
The implementation builds on foundational work by Gottesman (1997), Calderbank & Shor (1996), and Steane (1996).
Key features:
- Complete GF(4) arithmetic with explicit field tables
- Binary symplectic representation with conversion algorithms
- Classical Hamming [7,4,3] code construction
- CSS code construction for the Steane [[7,1,3]] code
- General CSS code constructor for arbitrary valid codes
- Verification of Shor [[9,1,3]] code
- Transversal Clifford gates (Hadamard, Phase, CNOT)
- Flagged circuit fault propagation simulation
- 12 independent verification checks - all pass
git clone https://github.com/sirraya-labs/stabilizer-framework.git
cd stabilizer-framework
python gf4.pyNo external dependencies required - pure Python standard library.
python gf4.pyThe implementation runs 12 independent verification checks:
==============================================================================
GF(4)-Symplectic Framework: Steane [[7,1,3]] Code
Following Mir, doi:10.20944/preprints202512.0353.v1
==============================================================================
[1] GF(4) field axioms (Sec. 2.1)
alpha^2 == beta : OK
alpha^3 == 1 : OK
alpha + alpha == 0 : OK
beta == alpha + 1 : OK
[2] Classical Hamming [7,4,3] code properties (Sec. 4)
H G^T == 0 : OK
all columns non-zero : OK
all columns distinct : OK
no pair of columns sums to zero (distance>=3) : OK
some triple of columns sums to zero (distance<=3) : OK
Hamming bound saturated (perfect code) : OK
[3] CSS condition H H^T = 0 (Sec. 4.8) : OK
[4] Stabilizer generators (Sec. 5.2)
S_X1: XIXIXIX
S_X2: IXXIIXX
S_X3: IIIXXXX
S_Z1: ZIZIZIZ
S_Z2: IZZIIZZ
S_Z3: IIIZZZZ
[5] Commutation checks (Theorem 1, Sec. 3.2)
All 6 stabilizers pairwise commute : True
Logical X, Z, all stabilizers commute : True
Logical X anti-commutes with logical Z : True
[6] Syndrome table (Sec. 8, Table 6)
All 21 single-qubit error syndromes unique: True
Worked example X on qubit index 2 (paper's qubit 3): sX=(0, 0, 0), sZ=(1, 1, 0)
[7] Code distance (Sec. 9)
All weight-1, weight-2 errors detected : True
Weight-3 undetectable witness error : XIIIIXX
=> code distance d = 3 ([[7,1,3]] confirmed)
[8] Transversal Clifford gates (Sec. 10)
H^(x7) maps logical X <-> logical Z : True
[9] General CSS constructor (App. A.5)
Steane-via-CSSCode: [[7,1,?]] rank(H_X)=3, rank(H_Z)=3
Matches SteaneCode's own stabilizers : True
[10] Shor [[9,1,3]] code (Nielsen & Chuang Sec. 10.2)
parameters (n, k) : (9, 1)
CSS condition holds : True
all 8 stabilizers pairwise commute : True
logical X_L, Z_L anti-commute : True
logicals commute with all stabilizers : True
logical_X weight : 9
logical_Z weight : 3
[11] Transversal CNOT across two Steane-code blocks (Sec. 10.3)
CNOT maps 12-generator stabilizer group to itself : True
X_A -> X_A X_B (control X propagates to target) : True
Z_B -> Z_A Z_B (target Z back-propagates) : True
Z_A -> Z_A (control Z untouched) : True
X_B -> X_B (target X untouched) : True
[12] Flagged X-stabilizer measurement circuit (Sec. 11)
Total single-fault scenarios tested : 24
...raw weight>=2 data errors (naive, overcounts) : 3
...truly uncorrectable (not reducible to wt<=1) : 1
...of which slip through UNFLAGGED (should be 0): 0
=> every genuinely dangerous fault is caught by the flag : True
==============================================================================
All checks derived directly and deterministically from the paper's
constructions -- no randomized search, matching literature-standard
stabilizer formalism (Gottesman 1997; Calderbank-Shor 1996; Steane 1996).
==============================================================================
gf4.py
├── GF(4) Arithmetic
│ ├── gf4_add(), gf4_mul(), gf4_conjugate()
│ ├── gf4_trace(), gf4_inverse()
│ └── gf4_to_pauli(), gf4_to_binary()
│
├── Binary Symplectic Representation
│ ├── gf4_vector_to_symplectic()
│ ├── symplectic_to_gf4_vector()
│ └── symplectic_inner_product()
│
├── Classical Hamming Code
│ ├── hamming_parity_check_matrix()
│ ├── hamming_generator_matrix()
│ └── verify_hamming_code()
│
├── Steane Code (SteaneCode class)
│ ├── Stabilizer generators (X and Z types)
│ ├── Logical operators (Xbar, Zbar)
│ ├── Symplectic stabilizer matrix
│ ├── Syndrome extraction
│ ├── Distance verification
│ └── Transversal gates
│
├── General CSS Code (CSSCode class)
│ ├── Constructor for arbitrary H_X, H_Z
│ ├── Commutation verification
│ └── Stabilizer group membership
│
├── Shor Code
│ └── shor_code() with verification
│
├── Flagged Circuits
│ ├── Fault propagation simulation
│ └── Stabilizer-equivalence criterion
│
└── Verification Suite
└── 12 independent checks
from gf4 import SteaneCode
code = SteaneCode()
print(code.stab_X_paulis) # ['XIXIXIX', 'IXXIIXX', 'IIIXXXX']
print(code.logical_X) # 'XXXXXXX'
print(code.logical_Z) # 'ZZZZZZZ'error = "IIXIIII" # X error on qubit 3
sX, sZ = code.syndrome(error)
print(f"sX={sX}, sZ={sZ}") # sX=(0,0,0), sZ=(1,1,0)from gf4 import CSSCode
import numpy as np
H_X = np.array([[1, 1, 0, 0], [0, 0, 1, 1]])
H_Z = np.array([[1, 0, 1, 0], [0, 1, 0, 1]])
code = CSSCode(H_X, H_Z)
print(code.summary())
print(f"Commutes: {code.verify_commute()}")from gf4 import shor_code, verify_shor_code
code = shor_code()
results = verify_shor_code()
for k, v in results.items():
print(f"{k}: {v}")The Steane code is degenerate (weight-4 stabilizers with distance 3). Raw error weight thresholds are misleading - a weight-2 error may be equivalent to a weight-1 error modulo the stabilizer group. The implementation uses the correct stabilizer-equivalence criterion for fault analysis.
Using the same Hamming matrix for both H_X and H_Z guarantees the CSS condition H H^T = 0 deterministically. Random search approaches have near-zero success rates.
While 3 out of 24 single-fault scenarios produce raw weight >= 2 data errors, only 1 is truly uncorrectable. The flag correctly catches this single dangerous fault, demonstrating the importance of proper fault-tolerance analysis.
The implementation follows the paper's structure:
| Section | Topic | Implementation |
|---|---|---|
| 2.1 | GF(4) field axioms | verify_gf4_field_axioms() |
| 3.2 | Symplectic inner product | symplectic_inner_product() |
| 3.3 | GF(4)-binary conversion | gf4_vector_to_symplectic() |
| 4.1 | Hamming parity-check matrix | hamming_parity_check_matrix() |
| 4.2-4.6 | Hamming code properties | verify_hamming_code() |
| 5.2 | Stabilizer generators | SteaneCode._build_stabilizers() |
| 6 | Symplectic stabilizer matrix | SteaneCode.symplectic_stabilizer_matrix() |
| 7.2 | Logical operators | SteaneCode.logical_X/Z |
| 8 | Syndrome extraction | SteaneCode.syndrome() |
| 9 | Code distance | SteaneCode.distance() |
| 10 | Transversal gates | SteaneCode.transversal_*() |
| 11 | Flagged circuits | simulate_single_fault_propagation() |
- Python 3.8 or higher
- No external dependencies (uses only standard library)
- NumPy (optional, for array operations)
Contributions are welcome. Please feel free to submit issues and pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this implementation in your research, please cite:
@article{mir2025unifying,
title={Unifying Theory and Practice: GF(4)-Symplectic Framework for Quantum Error Correction with Complete Implementation and Verification of the Steane [[7,1,3]] Code},
author={Mir, Amir Hameed},
journal={Preprints.org},
doi={10.20944/preprints202512.0353.v1},
year={2025}
}- D. Gottesman, "Stabilizer Codes and Quantum Error Correction," Caltech Ph.D. thesis, 1997.
- A. R. Calderbank and P. W. Shor, "Good quantum error-correcting codes exist," Phys. Rev. A 54, 1098 (1996).
- A. M. Steane, "Error correcting codes in quantum theory," Phys. Rev. Lett. 77, 793 (1996).
- C. Chamberland and M. E. Beverland, "Flag fault-tolerant error correction with arbitrary distance codes," Quantum 4, 256 (2020).
- M. A. Nielsen and I. L. Chuang, "Quantum Computation and Quantum Information," Cambridge University Press (2000).
Amir Hameed Mir - amir@sirraya.org