Skip to content

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

Open
Felix-Gundlach wants to merge 203 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 203 commits into
munich-quantum-toolkit:mainfrom
emilkanic0909:feature/ErrorCorrection_MergePrep

Conversation

@Felix-Gundlach

@Felix-Gundlach Felix-Gundlach commented Jun 13, 2026

Copy link
Copy Markdown

Description

Adds an error correction module that encodes benchmark circuits into logical circuits using the 7-qubit Steane code or the 9-qubit Shor code. Encoding is exposed via a new encoding parameter on get_benchmark() and get_benchmark_alg(), accepting "", "steane", or "shor":

qc = get_benchmark(benchmark="ghz", level=BenchmarkLevel.ALG, circuit_size=3, encoding="steane")

error_correction/ec_transpiler.py holds the code-agnostic ECTranspiler base class. It decomposes the circuit into the code's basis, replaces every logical qubit with a data register plus syndrome ancillas, substitutes each gate by its logical equivalent, and appends a syndrome extraction and correction cycle after every logical operation. SteaneTranspiler and ShorTranspiler only declare their code parameters and supply the encoding, decoding, and syndrome circuits.

Since MQT Bench targets circuit structure rather than exact behaviour, gates without a fault-tolerant transversal realization (t/tdg for both codes, plus h for Shor) are emitted as opaque placeholder instructions named {code}_ideal_logical_{gate} rather than as full magic-state constructions.

The encoding, decoding, syndrome, and correction circuits shared with the existing seven_qubit_steane_code and shors_nine_qubit_code benchmarks moved into a new components module.

Dependencies: requires Qiskit >= 2.4.0 (up from 2.0.0) for the transpilation to the Clifford+T basis. Noted in the changelog and the upgrade guide.

Limitations: encoding is only applied at BenchmarkLevel.ALG (a UserWarning is raised otherwise), control-flow operations are rejected with a ValueError, and basis decomposition uses approximation_degree=0.95, so encoded circuits are approximations.

AI assistance: this description was drafted by an LLM from the current diff and reviewed by us. Various docstrings were generated by an LLM and reviewed & edited by us.

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:

  • Any agent that created, edited, or submitted GitHub content was explicitly authorized for that scope, as required by our [AI Usage Guidelines](https://github.com/munich-quantum-toolkit/bench/blob/main/docs/ai_usage.md).
  • Every agent-authored or agent-edited public text body begins with the visible disclosure 🤖 *AI text below* 🤖 (titles are exempt).
  • We have disclosed AI assistance in the PR description.
  • We confirm that we have personally reviewed and understood all AI-generated content, and accept full responsibility for it.

Felix Gundlach added 2 commits August 29, 2026 13:23
…nic0909/MQT_Bench_ErrorCorrectionCodes into feature/ErrorCorrection_MergePrep
@emilkanic0909

Copy link
Copy Markdown

@flowerthrower Hi Patrick, info to our status. We have added some new tests for edge cases and Y Z gates. Also we have deleted derived gates and possibility to disable syndromes. Now we are getting 96,4% of coverage. We are still working on getting more.

@Felix-Gundlach

Copy link
Copy Markdown
Author

I ran into an issue with my local installation when using nox to lint. Nox stubbornly continued to use python 3.10 as interpreter (faulty install from my part, most likely). To fix this, I pinned the python version of the lint sessions to the newest supported version (see noxfile.py:51).
@flowerthrower I pushed the fix in 1dbff36 to help others avoid the same problem, should I rather leave the noxfile untouched and just keep it locally?

@flowerthrower flowerthrower left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi everyone, I really like how this is comming together. I left a few (this time really) minor requests. After adressing them and updating the PR description (can be done by LLM with disclaimer), feel free to request the final review from our chief-maintainer @burgholzer.

Comment thread src/mqt/bench/benchmark_generation.py
Comment thread src/mqt/bench/error_correction/steane_transpiler.py Outdated
Comment thread noxfile.py Outdated
Comment thread CHANGELOG.md
Comment thread pyproject.toml Outdated
Comment thread src/mqt/bench/error_correction/steane_transpiler.py Outdated
@Felix-Gundlach

Copy link
Copy Markdown
Author

@flowerthrower two last questions:

  1. We have not prepared any update to the documentation under https://mqt.readthedocs.io/en/stable/. Should we?
  2. Our PR adds a new warning when using encoding on unsupported levels. As this is mentioned by the checklist, do we need to explicitly document it somewhere?

@Felix-Gundlach

Copy link
Copy Markdown
Author

@burgholzer could you take a look at our changes when you get a chance?

@burgholzer

Copy link
Copy Markdown
Member

@burgholzer could you take a look at our changes when you get a chance?

Will do. May take me a bit to get to this though 😌

@Felix-Gundlach

Copy link
Copy Markdown
Author

@burgholzer could you take a look at our changes when you get a chance?

Will do. May take me a bit to get to this though 😌

No worries, this isn't time sensitive for us either 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants