Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
4200ef1
Added main.py
emilkanic0909 May 9, 2026
5a700a0
added code
SalehAlsherif May 9, 2026
38aa1f8
added entrying points
emilkanic0909 May 9, 2026
df2affd
changed the name of the argument to encoding to match the project des…
SalehAlsherif May 13, 2026
e3295e6
Shorcode Transpiler excluding S gates
SalehAlsherif May 16, 2026
6e08c7e
✨ Adding Steane for Clifford set
emilkanic0909 May 22, 2026
ac7b9ea
♻️ Refactoring
emilkanic0909 May 23, 2026
b0e5c8c
Shor_Code_Transpiler completed with tests anf T gate to be tested
SalehAlsherif May 23, 2026
3e211cb
change to statevector
emilkanic0909 May 23, 2026
1fa57c3
used reduced density matrix
SalehAlsherif May 23, 2026
5cf108d
✨ Implementing T Gate as in exercise decription
emilkanic0909 May 27, 2026
e9cc159
updated encoding parameter to make main.py run
May 29, 2026
fba7a1f
added various testing utilities
May 29, 2026
0dec02a
Added test outputs to gitignore
Felix-Gundlach May 29, 2026
b6978c4
Merged Shor Transpiler into Verification
Felix-Gundlach May 29, 2026
8e189f1
added barrier to decoding
Felix-Gundlach May 29, 2026
e041878
first attempts at unification
Felix-Gundlach May 29, 2026
0410fed
✨ Add syndromes control flag
emilkanic0909 May 30, 2026
574db9a
More Ways to test :)
May 30, 2026
d80afea
Merge remote-tracking branch 'origin/feature/ErrorCorrection_SteaneCo…
May 30, 2026
569bc68
More changes
May 30, 2026
ba98eaf
improved circuit simulation and data processing
May 30, 2026
bd58ad5
✨ Adding Decode All
emilkanic0909 May 30, 2026
f3fbac1
small modifications to structure
May 30, 2026
73317f7
merged changes
May 30, 2026
997d7d1
streamlined testing utilities
May 30, 2026
1e3b44c
more changes
May 30, 2026
4a26c64
Improved testing methodologies
May 30, 2026
8bf47d6
+ Enabled Algorithmic Equality testing
Felix-Gundlach May 31, 2026
3832fe8
Refactored to OpenClose Principle
SalehAlsherif Jun 6, 2026
49bd55a
+ logging
Jun 6, 2026
a65972d
+ cx & cz gate testing
Jun 6, 2026
6f765f0
🚧 Working with tests
emilkanic0909 Jun 6, 2026
739084b
Merge branch 'feature/ErrorCorrection_Verification' of https://github…
emilkanic0909 Jun 6, 2026
69e98a7
Merge branch 'feature/ErrorCorrection_ShorCode' into feature/ErrorCor…
emilkanic0909 Jun 6, 2026
a470a35
Merge branch 'feature/ErrorCorrection_Verification' of github.com:emi…
Jun 6, 2026
1ace3c5
Merge branch 'feature/ErrorCorrection_Verification' into feature/Erro…
Jun 6, 2026
02d1ac2
Addind Steane transpiler
emilkanic0909 Jun 6, 2026
86d2c36
Merge branch 'feature/ErrorCorrection_SubMain' of https://github.com/…
emilkanic0909 Jun 6, 2026
b0c175e
removed wrong tests and unneccessay outputs
Jun 6, 2026
9c71e3a
correcting tests
SalehAlsherif Jun 6, 2026
735cebb
added measurement testcase
Jun 6, 2026
45a1721
Merge branch 'feature/ErrorCorrection_SubMain' of github.com:emilkani…
Jun 6, 2026
135d7b1
Refactoring
SalehAlsherif Jun 6, 2026
db68e10
added decode before measurements
SalehAlsherif Jun 6, 2026
b57e5cc
Merge branch 'feature/ErrorCorrection_SubMain' of github.com:emilkani…
Jun 6, 2026
bcb06ad
✅ Add Steane components
emilkanic0909 Jun 6, 2026
2265c5a
Movedcircuit running
Jun 11, 2026
624ed2a
Merge branch 'feature/ErrorCorrection_SubMain' of github.com:emilkani…
Jun 11, 2026
d3517db
+ Added funcionality to create gate_counts.json
Jun 11, 2026
6d79032
+ Added test for circuit structure
Jun 11, 2026
9700a88
✨ Adding QFT gate support
emilkanic0909 Jun 12, 2026
6c4b74b
Fixed logical Measurement on shor code transpiler
SalehAlsherif Jun 12, 2026
4866c88
new gate counts
Jun 13, 2026
78a8d6b
more qft :)
Jun 13, 2026
ba31cba
fixed measurement removal
Jun 13, 2026
5bfd6c2
more fixes
Jun 13, 2026
2b19794
Adding QFT gate to shor transpiler
SalehAlsherif Jun 13, 2026
9432119
Fix Measurements
emilkanic0909 Jun 13, 2026
2ef22f2
fixed circuit structure tests to work with dynamic numbers of classic…
Jun 13, 2026
2fa6380
added support for qft structural tests
Jun 13, 2026
31216cc
switched to custom measurement logic
Jun 13, 2026
5f29699
✨ Fixing Tests
emilkanic0909 Jun 13, 2026
21c9fd7
✨ Removing QFT Test
emilkanic0909 Jun 13, 2026
956006e
various improvements to code quality
Jun 13, 2026
d98c80a
Merge branch 'feature/ErrorCorrection_SubMain' of github.com:emilkani…
Jun 13, 2026
7853e8d
more fixes to resolve the bungled up merge conflict
Jun 13, 2026
b3e2c8b
automatic nox lint changes
Jun 13, 2026
22f71bf
added dependencies for testing
Jun 13, 2026
5553b37
removed finished TODOs
Jun 13, 2026
f5ba739
removed unused file
Jun 13, 2026
221eb86
more linting changes
Jun 13, 2026
bb53875
greatly improved readability of documentation
Jun 13, 2026
137fb83
Merge branch 'munich-quantum-toolkit:main' into main
Felix-Gundlach Jun 13, 2026
ceb55da
Merge remote-tracking branch 'origin/main' into feature/ErrorCorrecti…
Jun 13, 2026
08463e3
Added module docstring
Jun 13, 2026
33b24ce
updated uv.lock to reflect added dependencies
Jun 13, 2026
80f347f
fixed wrong import location
Jun 16, 2026
1d0e8de
Added explicit type checking to syndrome extraction
Jun 16, 2026
9576b21
Moved testing dependencies to appropriate pytest groups
Jun 16, 2026
5823f63
Varios little improvements to code quality
Jun 16, 2026
75df4d6
Corrected module docstring
Jun 16, 2026
bc6c18b
Corrected module docstring
Jun 16, 2026
fe66b60
Enabled Solovay-Kitaev synthesis on steanes qft decomposition
Jun 16, 2026
b1fc4c1
added debug message regarding qiskit version
Jun 16, 2026
af74ee5
Switched to 2-pass transpilation for Steane's
Jun 16, 2026
18a43d4
🚧 Turn off tests, that crashes mqt.qcec
emilkanic0909 Jun 20, 2026
2562ff8
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 20, 2026
93acb24
reverted to old transpilation for QFT gate
Jun 27, 2026
74dd17e
Increased minimum qiskit version to 2.1 to support T gate transpilation
Jun 27, 2026
4e8b873
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Jun 27, 2026
8df9184
Increased qiskit version to 2.4 to include grisynth for QFT transpila…
Jun 27, 2026
620602d
removed redundant qiskit-aer & mqt.qcec specifications from dependencies
Jun 27, 2026
5cac15f
moved mqt.qcec dependency
Jun 27, 2026
5e723c4
moved qiskit aer dependency
Jun 27, 2026
db0c14c
lowered required fidelity for transpiler_correctness to account for u…
Jun 27, 2026
bf24cbd
🚑️ Skiping tests for ARM Ubuntu build
emilkanic0909 Jun 27, 2026
7cc25d2
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 27, 2026
1fe9da5
removed unused ty suppression
Jun 27, 2026
5506f3b
unfeasable/unsupported testcases are now skipped
Jun 27, 2026
05f5251
🎨 Considering Rabbit AI
emilkanic0909 Jun 27, 2026
b7c2f2d
Updated Docstrings to indicate support for error correction encodings
Jun 27, 2026
4dd1e6e
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Jun 27, 2026
ee006cf
Documented missing aer builds
Jun 27, 2026
a216cb8
Merge branch 'main' into feature/ErrorCorrection_MergePrep
Felix-Gundlach Jun 27, 2026
9e4e864
🚨 Fixing Rabbit AI suggestions
emilkanic0909 Jun 27, 2026
aec7e61
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 27, 2026
440f2d2
Formatted docstrings to google style
Jun 27, 2026
d69d0d5
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Jun 27, 2026
b503a5d
🚧 Fixing RabbitAI
emilkanic0909 Jun 27, 2026
9b89ba4
Merge branch 'feature/ErrorCorrection_MergePrep' of https://github.co…
emilkanic0909 Jun 27, 2026
b86a385
Converted docstrigns to google-style
Jun 27, 2026
bc1738d
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 27, 2026
22421a2
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Jun 27, 2026
5a4b525
Removed Equvialence checking and respective dependencies
Jul 1, 2026
9b2b365
Removed gate_counts.json
Jul 1, 2026
6083250
Moved gatecounts into dedicated constants
Jul 1, 2026
ef3c9ac
Modified Shor_transpiler to global clifford+t reduction before transp…
SalehAlsherif Jul 3, 2026
0ea3d08
applied opeque magic state injection
SalehAlsherif Jul 3, 2026
fc209f3
delete old comments
emilkanic0909 Jul 4, 2026
266ac64
Moved structural tests to test_bench.py
Jul 6, 2026
ff3f129
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Jul 6, 2026
d90c6c0
Removed unnecessary qiskit-aer dependency
Jul 6, 2026
9232b8a
Merge branch 'main' into feature/ErrorCorrection_MergePrep
Felix-Gundlach Jul 6, 2026
c7fae61
🔥 Remove Barriers, Measures, Decoding, Fix transpilation
emilkanic0909 Jul 18, 2026
f4ddd3a
🎨 pre-commit fixes
pre-commit-ci[bot] Jul 18, 2026
7496aab
readded tests for transpiler WIP
Jul 18, 2026
974aab6
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Jul 18, 2026
125bb2e
added simple test to check if everything still works
Jul 18, 2026
dd53d05
added docstrings to transpilation tests
Jul 18, 2026
62c50ab
Added support for Id, Y, DCX, SWAP gates.
Jul 18, 2026
4fdfb7c
Removed now unused Gates H, S, CZ
Jul 18, 2026
65a99dc
✨ Adding New Gates and Reuse code
emilkanic0909 Jul 18, 2026
0b5d752
modified tests to check all algorithms for transpilation
Jul 18, 2026
d56f79b
Expanded target transpilation target basis and re-added H gate support
Jul 18, 2026
a6d4560
Moved transpilation step into transpile() for consistency between imp…
Jul 18, 2026
853bb54
fixed accessing the transpiled qc
Jul 18, 2026
c8e5a70
fixed addressing the transpiled qc in test_error_correction_transpile…
Jul 18, 2026
b766e03
Updated expected gate counts for test_error_correction_transpiler_cir…
Jul 18, 2026
1ac0972
added generating functionality for gate counts and updated to newest …
Jul 18, 2026
04e864d
removed dedicated qec testing again
Jul 18, 2026
aa7030f
Improved syndrome extraction documentation
Jul 18, 2026
d397ae5
Merge branch 'main' into feature/ErrorCorrection_MergePrep
Felix-Gundlach Jul 18, 2026
dd69ae2
updated uv venv
Jul 18, 2026
1647130
draft ec_transpiler
Aug 8, 2026
73190c5
updated ec_transpiler to automatically handle derived gates
Aug 13, 2026
e8b8352
amended shor & steane transpilers to utilize automatic derived gate a…
Aug 13, 2026
aaf4c08
Amended ec gate counts to fit with new constraints
Aug 13, 2026
810be22
Added Exception on usage of decoded qubits
Aug 13, 2026
7ddfaa0
Added raising errors on encountering control-flow or conditioned oper…
Aug 13, 2026
a735a55
removed unnecessary parameter from replace_gates
Aug 13, 2026
b851edf
Clarified unsupported control-flow operations in docstring
Aug 13, 2026
f6f7058
Fixed cy derivation
Aug 13, 2026
544d025
Removed our EC changes from .gitignore
Aug 13, 2026
87e48a8
Updated optimization_level to 0 in transpile()
Aug 13, 2026
71102ac
Removed unnecessary t-gate count
Aug 13, 2026
edcff21
Fixed typo
Aug 13, 2026
413c067
Updated gate counts to reflect new optimization level
Aug 13, 2026
ee3f235
Merge branch 'main' into feature/ErrorCorrection_MergePrep
Felix-Gundlach Aug 13, 2026
07df7b4
📝 Update Changelog
emilkanic0909 Aug 15, 2026
7c38d9f
🎨 pre-commit fixes
pre-commit-ci[bot] Aug 15, 2026
b3c250e
📝Adapt Changelog📝
emilkanic0909 Aug 15, 2026
ca29806
Merge branch 'feature/ErrorCorrection_MergePrep' of https://github.co…
emilkanic0909 Aug 15, 2026
ff98090
🔥 Remove old TODOs
emilkanic0909 Aug 15, 2026
9fe9ec8
🎨 pre-commit fixes
pre-commit-ci[bot] Aug 15, 2026
6620137
🎨 Rename MagicState
emilkanic0909 Aug 15, 2026
cc566c3
Merge branch 'feature/ErrorCorrection_MergePrep' of https://github.co…
emilkanic0909 Aug 15, 2026
165b0a8
Merge branch 'main' into feature/ErrorCorrection_MergePrep
emilkanic0909 Aug 22, 2026
9d1078a
🐛 Fix docstring and Opaque gadget name in dicts
emilkanic0909 Aug 22, 2026
b679c67
🚑️ Disabling counts for qft, only existence
emilkanic0909 Aug 22, 2026
6dccbb4
🎨 pre-commit fixes
pre-commit-ci[bot] Aug 22, 2026
d986774
Merge branch 'main' into feature/ErrorCorrection_MergePrep
emilkanic0909 Aug 22, 2026
25e5bad
Removed ec_transpiler add_syndrome functionality
Aug 29, 2026
821b84d
✨ Add New Tests for Y Z gates and delete Derived
emilkanic0909 Aug 29, 2026
6b31b1f
Merge branch 'feature/ErrorCorrection_MergePrep' of https://github.co…
emilkanic0909 Aug 29, 2026
549b58e
Merge branch 'main' into feature/ErrorCorrection_MergePrep
emilkanic0909 Aug 29, 2026
ab0ac4d
🎨 pre-commit fixes
pre-commit-ci[bot] Aug 29, 2026
feb9a15
🚑️ Fix Sys Usage according to Daniels Haag PR
emilkanic0909 Aug 29, 2026
5eba858
🎨 pre-commit fixes
pre-commit-ci[bot] Aug 29, 2026
c42826d
🚑️ Fix formatting in md
emilkanic0909 Aug 29, 2026
8bfba49
Merge branch 'feature/ErrorCorrection_MergePrep' of https://github.co…
emilkanic0909 Aug 29, 2026
9c8d6fa
Various small fixes to move to 100% coverage
Aug 29, 2026
6b25061
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Aug 29, 2026
a99e32f
Merge branch 'main' into feature/ErrorCorrection_MergePrep
Felix-Gundlach Sep 1, 2026
1dbff36
Fixed python version for lint to newest supported version
Sep 1, 2026
b1d0035
Fixed overloading issues with get_benchmark_alg()
Sep 1, 2026
2aa070f
Added tests for get_benchmark_alg() encoding parameters
Sep 1, 2026
2c168a2
Removed unused derived gates functionality
Sep 1, 2026
ab2f520
decrease circuit size in test_get_benchmark_alg_encoding_parameters()…
Sep 1, 2026
90b1161
Pedantic changes to test_error_correction_transpiler_circuit_structure()
Sep 1, 2026
04d4790
Removed unused physical_data_registers
Sep 1, 2026
203b33f
Merge branch 'main' into feature/ErrorCorrection_MergePrep
Felix-Gundlach Sep 5, 2026
58ad237
Documented qiskit version change
Sep 7, 2026
ee70ede
removed ket from tool.typos
Sep 7, 2026
3c62b85
reverted fixed python version for lint
Sep 7, 2026
b05e7f4
Added warning for use of encoding in unsupported benchmark gen levels
Sep 7, 2026
763a7f4
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Sep 7, 2026
221e205
Updated witch reduced set of gates
Sep 7, 2026
45f566a
Merge branch 'main' into feature/ErrorCorrection_MergePrep
Felix-Gundlach Sep 7, 2026
590229a
removed deprecated 'add_syndrome' distinctions from docstrings
Sep 7, 2026
d2c5d87
Fixed typo
Sep 7, 2026
b47dc12
Added __init__.py files for error_correction and components
Sep 7, 2026
e917cf3
Merge branch 'feature/ErrorCorrection_MergePrep' of github.com:emilka…
Sep 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,15 @@ that minor releases may include breaking changes.

### Added

- ✨ Add optional structured loops to Grover's algorithm and quantum walk
([#997]) ([**@flowerthrower**])
- ✨ Add Steane's and Shor's encoding for benchmarks ([#930])
([**@Felix-Gundlach**], [**@emilkanic0909**], [**@SalehAlsherif**])

### Changed

- ⬆️ Increase minimum Qiskit version to 2.4.0 ([#930]) ([**@Felix-Gundlach**],
Comment thread
Felix-Gundlach marked this conversation as resolved.
[**@emilkanic0909**], [**@SalehAlsherif**])
- ✨ Add optional structured loops to Grover's algorithm and quantum walk
([#997]) ([**@flowerthrower**])
- 🔥 Drop support for Python 3.10 ([#999]) ([**@denialhaag**])
- 🍎 Stop testing on x86 macOS systems ([#999]) ([**@denialhaag**])

Expand Down Expand Up @@ -245,6 +249,9 @@ _📚 Refer to the [GitHub Release Notes] for previous changelogs._
[**@TomasVF**]: https://github.com/TomasVF
[**@flowerthrower**]: https://github.com/flowerthrower
[**@johanneswittmann9**]: https://github.com/johanneswittmann9
[**@Felix-Gundlach**]: https://github.com/Felix-Gundlach
[**@emilkanic0909**]: https://github.com/emilkanic0909
[**@SalehAlsherif**]: https://github.com/SalehAlsherif
[**@cnYui**]: https://github.com/cnYui

<!-- General links -->
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ Starting with this release, MQT Bench no longer supports Python 3.10. As a
result, MQT Bench is no longer tested under Python 3.10 and requires Python 3.11
or later.

### Changed

- ⬆️ Increase minimum Qiskit version to 2.4.0 ([#930]) ([**@Felix-Gundlach**]),

## [2.2.0]

### Dynamic benchmarks and device support for control flow
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ dynamic = ["version"]
dependencies = [
# Qiskit 1.3.2 contains some fixes for exporting OpenQASM 3 files
# Qiskit 2.0.0 fixes the SolovayKitaev transpiler for mid-circuit measurements
"qiskit[qasm3-import]>=2.0.0",
# Qiskit 2.4.0 fixes the transpilation to Clifford+T basis
Comment thread
Felix-Gundlach marked this conversation as resolved.
"qiskit[qasm3-import]>=2.4.0",
"networkx>=2.8.8",
"numpy>=1.24",
"numpy>=1.26; python_version >= '3.12'",
Expand Down
40 changes: 39 additions & 1 deletion src/mqt/bench/benchmark_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from __future__ import annotations

import warnings
from enum import Enum, auto
from typing import TYPE_CHECKING, Unpack, assert_never, overload

Expand All @@ -21,6 +22,8 @@
from qiskit.transpiler import Layout, Target

from .benchmarks import create_circuit
from .error_correction.shor_transpiler import ShorTranspiler
from .error_correction.steane_transpiler import SteaneTranspiler
from .targets.gatesets import get_target_for_gateset, ionq, rigetti

if TYPE_CHECKING: # pragma: no cover
Expand Down Expand Up @@ -159,6 +162,7 @@ def _validate_opt_level(opt_level: int) -> None:
def get_benchmark_alg(
benchmark: str,
circuit_size: int,
encoding: str = "",
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -170,6 +174,7 @@ def get_benchmark_alg(
def get_benchmark_alg(
benchmark: QuantumCircuit,
circuit_size: None = None,
encoding: str = "",
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -181,6 +186,7 @@ def get_benchmark_alg(
def get_benchmark_alg(
benchmark: str | QuantumCircuit,
circuit_size: int | None = None,
encoding: str = "",
Comment thread
Felix-Gundlach marked this conversation as resolved.
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -191,6 +197,7 @@ def get_benchmark_alg(
def get_benchmark_alg(
benchmark: str | QuantumCircuit,
circuit_size: int | None = None,
encoding: str = "",
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -201,16 +208,33 @@ def get_benchmark_alg(
Arguments:
benchmark: QuantumCircuit or name of the benchmark to be generated
circuit_size: Input for the benchmark creation, in most cases this is equal to the qubit number
encoding: Error correction code to be used, can be any of {"", "steane", "shor"}.
generate_mirror_circuit: If True, generates the mirror version (U @ U.inverse()) of the benchmark.
random_parameters: If True, assigns random parameters to the circuit's parameters if they exist.
kwargs: Additional keyword arguments passed to the circuit creation.

Returns:
Qiskit::QuantumCircuit representing the raw benchmark circuit without any hardware-specific compilation or mapping.
"""
valid_encodings = {"", "shor", "steane"}
if encoding not in valid_encodings:
msg = f"Invalid `encoding` '{encoding}'. Must be one of {valid_encodings}."
raise ValueError(msg)

qc = _get_circuit(benchmark, circuit_size, random_parameters, **kwargs)

if generate_mirror_circuit:
return _create_mirror_circuit(qc, inplace=True)
qc = _create_mirror_circuit(qc, inplace=True)

if encoding == "shor":
transpiler = ShorTranspiler(qc)
transpiler.transpile()
qc = transpiler.transpiled_qc
if encoding == "steane":
transpiler = SteaneTranspiler(qc)
transpiler.transpile()
qc = transpiler.transpiled_qc

return qc
Comment thread
Felix-Gundlach marked this conversation as resolved.


Expand Down Expand Up @@ -471,6 +495,7 @@ def get_benchmark(
circuit_size: int,
target: Target | None = None,
opt_level: int = 2,
encoding: str = "",
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -485,6 +510,7 @@ def get_benchmark(
circuit_size: None,
target: Target | None = None,
opt_level: int = 2,
encoding: str = "",
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -499,6 +525,7 @@ def get_benchmark(
circuit_size: int | None = None,
target: Target | None = None,
opt_level: int = 2,
encoding: str = "",
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -512,6 +539,7 @@ def get_benchmark(
circuit_size: int | None = None,
target: Target | None = None,
opt_level: int = 2,
encoding: str = "",
*,
generate_mirror_circuit: bool = False,
random_parameters: bool = True,
Expand All @@ -526,19 +554,29 @@ def get_benchmark(
target: `~qiskit.transpiler.target.Target` for the benchmark generation
(only used for "nativegates" and "mapped" level)
opt_level: Optimization level to be used by the transpiler.
encoding: Error correction code to be used, can be any of {"", "steane", "shor"}.
Only supported for `BenchmarkLevel.ALG`; ignored (with a warning) for other levels.
generate_mirror_circuit: If True, generates the mirror version (U @ U.inverse()) of the benchmark.
random_parameters: If True, assigns random parameters to the circuit's parameters if they exist.
kwargs: Additional keyword arguments passed to the circuit creation.

Returns:
Qiskit::QuantumCircuit object representing the benchmark with the selected options
"""
if level is not BenchmarkLevel.ALG and encoding:
warnings.warn(
f"`encoding` is only supported for BenchmarkLevel.ALG and will be ignored for level={level.name}.",
UserWarning,
stacklevel=2,
)

if level is BenchmarkLevel.ALG:
return get_benchmark_alg(
benchmark=benchmark,
circuit_size=circuit_size,
generate_mirror_circuit=generate_mirror_circuit,
random_parameters=random_parameters,
encoding=encoding,
**kwargs,
)

Expand Down
135 changes: 11 additions & 124 deletions src/mqt/bench/benchmarks/seven_qubit_steane_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,127 +13,14 @@
from qiskit import ClassicalRegister
from qiskit.circuit import AncillaRegister, QuantumCircuit, QuantumRegister

from ._registry import register_benchmark


def _get_seven_qubit_steane_code_encoding_circuit() -> QuantumCircuit:
"""Create the 7-qubit Steane code encoding circuit.

Encodes qubit 0 into the 7-qubit Steane code logical state:
- |0> -> (|0000000> + |1010101> + |0110011> + |1100110> + |0001111> + |1011010> + |0111100> + |1101001>)
- |1> -> (|1111111> + |0101010> + |1001100> + |0011001> + |1110000> + |0100101> + |1000011> + |0010110>).

Returns:
QuantumCircuit: 7-qubit encoding circuit.
"""
out = QuantumCircuit(7)
# H
out.h(4)
out.h(5)
out.h(6)
# CNOT from 0
out.cx(0, 1)
out.cx(0, 2)
# CNOT from 6
out.cx(6, 3)
out.cx(6, 1)
out.cx(6, 0)
# CNOT from 5
out.cx(5, 3)
out.cx(5, 2)
out.cx(5, 0)
# CNOT from 4
out.cx(4, 3)
out.cx(4, 2)
out.cx(4, 1)
return out


def _get_seven_qubit_steane_code_decoding_circuit() -> QuantumCircuit:
"""Create the 7-qubit Steane code decoding circuit.

Reverses the encoding operation to extract the logical qubit back to qubit 0.

Returns:
QuantumCircuit: 7-qubit decoding circuit (qubit 0 is the output qubit).
"""
return _get_seven_qubit_steane_code_encoding_circuit().inverse()

from mqt.bench.components.steane_circuit_components import (
apply_seven_qubit_steane_code_correction,
get_seven_qubit_steane_code_decoding_circuit,
get_seven_qubit_steane_code_encoding_circuit,
get_seven_qubit_steane_code_syndrome_extraction_circuit,
)

def _get_seven_qubit_steane_code_syndrome_extraction_circuit() -> QuantumCircuit:
"""Create the syndrome extraction circuit for the 7-qubit Steane code.

Extracts bit-flip and phase-flip syndromes using 6 ancilla qubits (3 for each type).

Bit-flip syndrome extraction:
Syndrome bits measure the parity of specific qubit subsets corresponding to
the X-stabilizer generators.

Phase-flip syndrome extraction:
Uses Hadamard gates to convert from Z to X basis, and control/target swapped
CNOTs to extract the phase-flip syndrome

Syndrome mapping: The 3-bit syndrome value (1-7) directly identifies which
data qubit experienced an error. Syndrome 0 indicates no error.

Returns:
QuantumCircuit: 13-qubit circuit (qubits 0-6 are data, 7-9 are bit-flip
syndrome ancillas, 10-12 are phase-flip syndrome ancillas).
"""
logical_qubit, bit_flip_syndrome, phase_flip_syndrome = QuantumRegister(7), AncillaRegister(3), AncillaRegister(3)
out = QuantumCircuit(logical_qubit, bit_flip_syndrome, phase_flip_syndrome)
# Bit-flip
for ctrl in (0, 2, 4, 6):
out.cx(logical_qubit[ctrl], bit_flip_syndrome[0])
for ctrl in (1, 2, 5, 6):
out.cx(logical_qubit[ctrl], bit_flip_syndrome[1])
for ctrl in (3, 4, 5, 6):
out.cx(logical_qubit[ctrl], bit_flip_syndrome[2])
# Phase-flip
for i in range(3):
out.h(phase_flip_syndrome[i])
for targ in (0, 2, 4, 6):
out.cx(phase_flip_syndrome[0], logical_qubit[targ])
for targ in (1, 2, 5, 6):
out.cx(phase_flip_syndrome[1], logical_qubit[targ])
for targ in (3, 4, 5, 6):
out.cx(phase_flip_syndrome[2], logical_qubit[targ])
for i in range(3):
out.h(phase_flip_syndrome[i])
return out


def _apply_seven_qubit_steane_code_correction(
qc: QuantumCircuit,
logical_qubit: QuantumRegister,
bit_flip_syndrome: AncillaRegister,
phase_flip_syndrome: AncillaRegister,
bit_flip_syndrome_measurement: ClassicalRegister,
phase_flip_syndrome_measurement: ClassicalRegister,
) -> None:
"""Apply error correction based on syndrome measurements.

Measures the 6 syndrome qubits and conditionally applies X/Z gates to correct
single-qubit errors on any of the 7 data qubits.

Arguments:
qc: The quantum circuit to modify.
logical_qubit: Register containing the 7 data qubits.
bit_flip_syndrome: Register containing the 3 bit-flip syndrome qubits.
phase_flip_syndrome: Register containing the 3 phase-flip syndrome qubits.
bit_flip_syndrome_measurement: Classical register for bit-flip syndrome results.
phase_flip_syndrome_measurement: Classical register for phase-flip syndrome results.
"""
qc.measure(bit_flip_syndrome, bit_flip_syndrome_measurement)
qc.measure(phase_flip_syndrome, phase_flip_syndrome_measurement)
# Bit-flip correction: syndrome value directly indicates which qubit to correct
for i in range(7):
with qc.if_test((bit_flip_syndrome_measurement, i + 1)):
qc.x(logical_qubit[i])
# Phase-flip correction: syndrome value directly indicates which qubit to correct
for i in range(7):
with qc.if_test((phase_flip_syndrome_measurement, i + 1)):
qc.z(logical_qubit[i])
from ._registry import register_benchmark


def _create_single_logical_qubit_circuit(index: int) -> QuantumCircuit:
Expand Down Expand Up @@ -164,20 +51,20 @@ def _create_single_logical_qubit_circuit(index: int) -> QuantumCircuit:
)
# == Encoding ==
qc.compose(
_get_seven_qubit_steane_code_encoding_circuit(),
get_seven_qubit_steane_code_encoding_circuit(),
qubits=logical_qubit[:],
inplace=True,
)
qc.barrier()
# == Syndrome extraction ==
qc.compose(
_get_seven_qubit_steane_code_syndrome_extraction_circuit(),
get_seven_qubit_steane_code_syndrome_extraction_circuit(),
qubits=logical_qubit[:] + bit_flip_syndrome[:] + phase_flip_syndrome[:],
inplace=True,
)
qc.barrier()
# == Error correction ==
_apply_seven_qubit_steane_code_correction(
apply_seven_qubit_steane_code_correction(
qc,
logical_qubit,
bit_flip_syndrome,
Expand All @@ -188,7 +75,7 @@ def _create_single_logical_qubit_circuit(index: int) -> QuantumCircuit:
qc.barrier()
# == Decoding ==
qc.compose(
_get_seven_qubit_steane_code_decoding_circuit(),
get_seven_qubit_steane_code_decoding_circuit(),
qubits=logical_qubit[:],
inplace=True,
)
Expand Down
Loading
Loading