Skip to content

✨ Add error correction module with Shor and Steane logical circuit transpilers#930

Open
Felix-Gundlach wants to merge 144 commits into
munich-quantum-toolkit:mainfrom
emilkanic0909:feature/ErrorCorrection_MergePrep
Open

✨ Add error correction module with Shor and Steane logical circuit transpilers#930
Felix-Gundlach wants to merge 144 commits into
munich-quantum-toolkit:mainfrom
emilkanic0909:feature/ErrorCorrection_MergePrep

Conversation

@Felix-Gundlach

Copy link
Copy Markdown

Summary

This PR introduces a dedicated Error Correction Module for MQT Bench. It adds two high-level transpilers that encode standard benchmark circuits into fault-tolerant logical circuits using the 7-qubit Steane code and the 9-qubit Shor code, respectively. The module is designed to integrate cleanly with the existing benchmark_generation API.

Changes

New files

  • src/mqt/bench/error_correction/steane_transpiler.pySteaneTranspiler class: encodes logical qubits into 7-qubit Steane blocks, applies transversal Clifford gates (H, X, Z, S, CX, CZ), and handles T-gates via magic state injection with ancilla teleportation.
  • src/mqt/bench/error_correction/shor_transpiler.pyShorTranspiler class: encodes logical qubits into 9-qubit Shor blocks, implements the full logical Clifford gate set (including the non-transversal H via bit-swap), and supports S- and T-gates via magic state teleportation gadgets.
  • tests/test_error_correction.py — pytest suite covering gate-level equivalence (via MQT QCEC), correctness under injected bit- and phase-flip errors (via Hellinger fidelity with Aer), and circuit structure validation against pre-computed gate counts for GHZ, Bernstein–Vazirani, graph state, and QFT benchmarks.

How it works

Both transpilers follow the same three-phase pipeline:

  1. Encode — each logical qubit is replaced by a physical register (7 or 9 qubits) and initialized using the respective encoding circuit.
  2. Replace gates — the original circuit is scanned instruction by instruction and each gate is replaced with its logical equivalent. High-level gates (e.g. QFTGate) are first decomposed into the supported basis set {H, X, Z, S, T, CX, CZ}.
  3. Insert syndromes — after each logical operation, syndrome extraction and conditional correction cycles are appended using Qiskit's dynamic circuit if_test feature.

T-gates, which are non-transversal, are handled via a teleportation gadget: a magic state ancilla block is prepared, a logical CNOT is applied from the data qubit to the ancilla, the ancilla is decoded and measured, and a conditional logical S correction is applied on outcome 1.

Testing

  • Gate equivalence is verified using mqt.qcec for all single- and two-qubit Clifford gates.
  • Correctness under noise is verified by injecting a physical X or Z error after encoding and checking that the Hellinger fidelity between the corrected and uncorrected logical distributions is ≥ 0.99.
  • Circuit structure is validated against a reference gate_counts.json for qubit counts ranging from 3 to 9 across all supported algorithms.

Notes

  • QFT is currently excluded from the correctness simulation tests due to circuit depth making simulation infeasible.
  • Syndrome insertion can be toggled off via add_syndromes=False for lightweight structural or equivalence checks.

Checklist

  • The pull request only contains commits that are focused and relevant to this change.
  • We have added appropriate tests that cover the new/changed functionality.
  • We have updated the documentation to reflect these changes.
  • We have added entries to the changelog for any noteworthy additions, changes, fixes, or removals.
  • We have added migration instructions to the upgrade guide (if needed).
  • The changes follow the project's style guidelines and introduce no new warnings.
  • The changes are fully tested and pass the CI checks.
  • We have reviewed our own code changes.

If PR contains AI-assisted content:

  • We have disclosed the use of AI tools in the PR description as per our AI Usage Guidelines.
  • AI-assisted commits include an Assisted-by: [Model Name] via [Tool Name] footer.
  • We confirm that We have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

Felix Gundlach and others added 30 commits July 1, 2026 10:14
Changed circuit structure tests to use hardcoded gate data, only for 3 qubits
structural tests now manually transpile circuits
…ilation of gates without modifying the error correction tests
Removed other tests and test_error_correction.py
…nic0909/MQT_Bench_ErrorCorrectionCodes into feature/ErrorCorrection_MergePrep
…nic0909/MQT_Bench_ErrorCorrectionCodes into feature/ErrorCorrection_MergePrep
Changed pre-processed transpilation to new target ["id", "x", "y", "z", "cx", "swap", "dcx", "t", "tdg"]
Signed-off-by: Felix Gundlach <67263641+Felix-Gundlach@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants