Skip to content
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
26abfcd
create permutation file
inctechs Nov 25, 2024
2b74027
add function to create steane state prep circuit
inctechs Nov 26, 2024
010df06
add function preparing Steane code CSS object
inctechs Nov 27, 2024
714e8f7
Correct wrong stabilizer generators
inctechs Nov 28, 2024
af56986
add option to check for logical 0
inctechs Jan 28, 2025
a8b5e47
add set up for Simulation circuit
inctechs Jan 28, 2025
112c777
disable print statement removement
inctechs Jan 28, 2025
15ef182
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
inctechs Jan 28, 2025
4d49bef
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
inctechs Feb 7, 2025
e832caf
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
inctechs Feb 10, 2025
28de0e3
add utility function to get automorphism subgroup from generators
inctechs Feb 10, 2025
0bed263
add function to evaluate fault set overlap based on permutations
inctechs Feb 20, 2025
3e249b8
mandatory format changes (return -> Return)
inctechs Feb 20, 2025
2cb6521
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
inctechs Feb 20, 2025
27569f1
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
inctechs Mar 3, 2025
1d64f19
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 3, 2025
acbabdb
guide heuristic gauss based on penalty columns/ CNOTs
inctechs Mar 3, 2025
1359027
move overlap search out and turn it into a standalone function
inctechs Mar 3, 2025
3d7529a
update heuristic SPC function to allow guiding information
inctechs Mar 3, 2025
9bac3af
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 3, 2025
a15c6e1
add method to permute qubits of StatePreparationCircuit
inctechs Mar 5, 2025
3beda63
Ignore missing library stubs sympy.
pehamTom Mar 5, 2025
2481cbb
add method that checks overlap of fault sets to SPC class
inctechs Mar 5, 2025
79c60e3
add function to check mutual disjunctness
inctechs Mar 7, 2025
924b1d2
add automorphism as optional property to CSSCode class
inctechs Mar 7, 2025
277d946
Merge branch 'main' into ft-stateprep-qubit-perm
pehamTom Mar 14, 2025
92143b3
Simulation steane ftsp (#383)
pehamTom Mar 14, 2025
1e97ab1
Allow steane-type FTSP with only two circuits.
pehamTom Mar 14, 2025
c18c07e
Synthesis of state prep circuits in standard form.
pehamTom Mar 14, 2025
ef66114
Checks in simulation dependent on state.
pehamTom Mar 15, 2025
a09f00f
Merge branch 'ft-stateprep-qubit-perm' into standard-form-commutations
pehamTom Mar 15, 2025
52d2095
remove debug prints
inctechs Mar 17, 2025
288132c
Merge branch 'ft-stateprep-qubit-perm' of https://github.com/cda-tum/…
inctechs Mar 17, 2025
1d6e0dd
set up eval directory structure
inctechs Mar 18, 2025
705876b
add z_observable flag for z errors
inctechs Mar 18, 2025
fff679e
🎨 pre-commit fixes
pre-commit-ci[bot] Mar 18, 2025
a04dd7c
missing comma
inctechs Mar 18, 2025
ae7a1dd
Merge remote-tracking branch 'refs/remotes/origin/ft-stateprep-qubit-…
inctechs Mar 18, 2025
31cc107
Revert "add z_observable flag for z errors"
inctechs Mar 18, 2025
e08521d
Canonical form circuits for Steane-type FTSP.
pehamTom Mar 18, 2025
d9f72f4
add binomial error calulation for SteaneNDFTStatePrepSimulator
inctechs Mar 19, 2025
03bba84
prepare simulation
inctechs Mar 19, 2025
48e484d
update cc_4_8_8 circuits
inctechs Mar 19, 2025
1094955
change cc_6_6_6 from qasm3 to qasm2
inctechs Mar 19, 2025
a5e4877
Bugged implementation.
pehamTom Mar 19, 2025
e05ba10
add new headers for binomial errors in csv
inctechs Mar 19, 2025
a8ae963
remove falsly tracked files
inctechs Mar 19, 2025
0450ed5
Second attempt.
pehamTom Mar 19, 2025
f97238b
Fix bug in Steane Type measurement regarding measurement order.
pehamTom Mar 19, 2025
c27efc5
Merge remote-tracking branch 'origin/ft-stateprep-qubit-perm' into ft…
pehamTom Mar 19, 2025
7d61efc
Random CNOT Permutation.
pehamTom Mar 20, 2025
5de6e3c
add circuits for cc_488 of distance 7
inctechs Mar 21, 2025
c57903a
update sim file to include distance 7 cc488
inctechs Mar 21, 2025
65679e9
Merge branch 'ft-stateprep-qubit-perm' of https://github.com/cda-tum/…
inctechs Mar 21, 2025
9c6587f
correct crucial typo
inctechs Mar 24, 2025
e0aa0be
Speed up LUT creation.
pehamTom Mar 24, 2025
eda6704
Merge remote-tracking branch 'origin/ft-stateprep-qubit-perm' into ft…
pehamTom Mar 24, 2025
52f6b09
Remove old function.
pehamTom Mar 24, 2025
b4e07ec
Remove another old function.
pehamTom Mar 24, 2025
5e7f906
Merge branch 'ft-stateprep-qubit-perm' into standard-form-commutations
pehamTom Mar 24, 2025
b6ec765
Fix index error in permutation generation.
pehamTom Mar 25, 2025
fef08e7
Steane-type check for Z errors.
pehamTom Mar 25, 2025
6540dc2
Remove pheno noise.
pehamTom Mar 25, 2025
663c7a4
Merge branch 'ft-stateprep-qubit-perm' into standard-form-commutations
pehamTom Mar 25, 2025
5c70209
Noise on ancilla.
pehamTom Mar 26, 2025
78e8594
Eval scripts for canonical Steane State Prep.
pehamTom Mar 26, 2025
1ac2a39
edit heuristic_gauss
inctechs Mar 26, 2025
d8cb475
add function to find next error
inctechs Mar 26, 2025
e34ae29
change check mutual disjunctness function
inctechs Mar 26, 2025
0d86484
change distance based fault set calculation
inctechs Mar 26, 2025
9471f0d
change build funciton for cnot circuit
inctechs Mar 26, 2025
017a640
Merge remote-tracking branch 'origin/ft-stateprep-qubit-perm' into ft…
inctechs Mar 26, 2025
90357d6
reference based heuristic changed to reference fault sets and speed ups
inctechs Mar 28, 2025
06ed523
define default for faulst set overlap check
inctechs Mar 28, 2025
77b4155
Fix canonical permutation.
pehamTom Mar 31, 2025
4a4688d
Merge remote-tracking branch 'origin/ft-stateprep-qubit-perm' into ft…
pehamTom Mar 31, 2025
33970ba
Removed old variable.
pehamTom Apr 1, 2025
945449a
Improve memory usage.
pehamTom Apr 2, 2025
4f1dba3
Remove unnecessary stabilizer measurements in simulation.
pehamTom Apr 3, 2025
599d0af
Indent
pehamTom Apr 7, 2025
925ea2e
Merge branch 'standard-form-commutations' into ft-stateprep-qubit-perm
pehamTom Apr 7, 2025
f18def0
🎨 pre-commit fixes
pre-commit-ci[bot] Apr 7, 2025
ff4ac1d
update octagon distance 7 simulation circuits
inctechs Apr 7, 2025
f67bdb4
add scripts for distance 7 and private mac simulation
inctechs Apr 7, 2025
3a4f838
new circuit folder structure and add hexagonal d7 circuits
inctechs Apr 8, 2025
210ed96
correct simulation script and expand it to include hexagonal d7 circuits
inctechs Apr 8, 2025
d2901f4
change C3 and C4 of hexd7 code to be reproduceable
inctechs Apr 8, 2025
18b6805
heuristic indep of SPC (only code) add 2 error check
inctechs Apr 8, 2025
c817945
clean up StatePreparationCircuit Class add variables to heuristic
inctechs Apr 8, 2025
461ea1b
add variable descriptions
inctechs Apr 8, 2025
e3bb849
add fs overlap check to circuit and add Z logical to equivalence check
inctechs Apr 8, 2025
a8be98c
improve CNOT count of C4 for the distance 7 octagon code
inctechs Apr 8, 2025
168fb96
remove unwanted csv files and change propabilities
inctechs Apr 11, 2025
7d18b2f
add functionality to start z error sim
inctechs Apr 11, 2025
a1ceeb7
remove print statements when constructing heuristic circuit
inctechs Apr 11, 2025
6e95f6c
Fix bug in simulator circuit construction.
pehamTom Apr 14, 2025
588316a
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
pehamTom May 13, 2025
6d28a6b
reinstate gaussian elimination, copy advanced logic
inctechs May 27, 2025
f07d5f4
clean up unused files and functions
inctechs May 27, 2025
95b3ffa
set up GaussianElimination Class
inctechs May 28, 2025
cd8ab5e
Merge remote-tracking branch 'origin' into ft-stateprep-qubit-perm
inctechs Jun 23, 2025
9c12af1
refactor heuristic elimination
inctechs Jun 23, 2025
8d04cdf
add test file for gaussian elimination and first test
inctechs Jun 24, 2025
5841154
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 24, 2025
cf67d3d
remove Sympy from synthesis utils
inctechs Jun 24, 2025
73c97bd
Merge remote-tracking branch 'origin' into ft-stateprep-qubit-perm
inctechs Jun 24, 2025
0d97505
Merge branch 'ft-stateprep-qubit-perm' of https://github.com/cda-tum/…
inctechs Jun 24, 2025
ca943c4
solving mypy issues with sympy
inctechs Jun 25, 2025
ecfaa36
solve issue with qsample and pytest
inctechs Jun 25, 2025
de0580a
add integration test for basic elimination
inctechs Jun 26, 2025
89022a9
fix typo
inctechs Jun 26, 2025
3ea4ccb
add more tests
inctechs Jun 26, 2025
93d78a7
add docstrings and typehints
inctechs Jun 26, 2025
fbab28e
fix first mypy issues
inctechs Jun 26, 2025
ab0172f
add to API functions for both reference based and regular SP
inctechs Jun 27, 2025
f2c06e1
🎨 pre-commit fixes
pre-commit-ci[bot] Jun 27, 2025
0b84a10
Merge remote-tracking branch 'origin' into ft-stateprep-qubit-perm
inctechs Jun 27, 2025
cc68d86
Merge branch 'ft-stateprep-qubit-perm' of https://github.com/cda-tum/…
inctechs Jun 27, 2025
8e2a37e
solve more mypy issues
inctechs Jun 27, 2025
3262db8
fix final mypy issues in synthesis utils
inctechs Jun 27, 2025
c01e2a1
remove old legacy function after refactoring
inctechs Jun 30, 2025
5427d4c
change name of penalty columns to penalty cnots
inctechs Jun 30, 2025
31d37c7
change name from penalty cols to penalty cnots on state_prep.py
inctechs Jun 30, 2025
0c9a4b6
remove mypy issues in synthesis_utils.py
inctechs Jun 30, 2025
bd463a9
remove legacy entry points to legacy function
inctechs Jun 30, 2025
8c0e481
remove legacy function form encoding.py and swap it with class structure
inctechs Jun 30, 2025
321d687
add pytest.ini to git ignore to keep locally neotest working
inctechs Jun 30, 2025
d7a5206
add required positional argument 'code' to GaussianElimination
inctechs Jun 30, 2025
5d84f7a
Some minor refactoring.
pehamTom Jul 4, 2025
e05bf34
Removed unused method.
pehamTom Jul 24, 2025
6f63f96
Merge branch 'main' into ft-stateprep-qubit-perm
pehamTom Jul 28, 2025
70f5316
Add ideal qubits to noise model.
pehamTom Jul 28, 2025
fec9f2b
Added method to get unmeasured qubits of stim circuit.
pehamTom Jul 28, 2025
0764a88
Start refactoring noisy simulation.
pehamTom Jul 28, 2025
7734528
remove linter flag T201 for avoiding print removal
inctechs Jul 28, 2025
597e51e
remove automorphism functionality from CSSCode class
inctechs Jul 28, 2025
c2efbd9
remove sympy dependency from pyproject.toml
inctechs Jul 28, 2025
31a9c8d
delete stateprep docs (previously removed on the master)
inctechs Jul 28, 2025
971c6ff
Refactor Simulation functionality.
pehamTom Jul 29, 2025
c15ddc7
Merge branch 'ft-stateprep-qubit-perm' of https://github.com/cda-tum/…
inctechs Jul 29, 2025
3478a68
remove commented out code
inctechs Jul 29, 2025
8cf2622
rename EliminationCNOTSynthesizer and API functions
inctechs Jul 29, 2025
693867f
improve docstring of EliminationCNOTSynthesizer class
inctechs Jul 30, 2025
d699a12
rename _handle_stagnation to _reset_if_stuck
inctechs Jul 30, 2025
2966b4c
update docstring of _is_reduced() method
inctechs Jul 30, 2025
95de5b1
fix logical error in validate_inputs() method
inctechs Jul 30, 2025
f219dd2
fix type cast
inctechs Jul 30, 2025
3ec3bf7
remove _modify_matrix_structure() method
inctechs Jul 30, 2025
9e5d02a
separate greedy initialisation from fault set guided init
inctechs Jul 30, 2025
41a6a23
Merge branch 'main' into ft-stateprep-qubit-perm
inctechs Aug 13, 2025
6a9ed32
Merge branch 'main' into ft-stateprep-qubit-perm
inctechs Aug 13, 2025
0f1ad6f
🎨 pre-commit fixes
pre-commit-ci[bot] Aug 13, 2025
0b4696a
clean up repository and add personal playground directory
inctechs Aug 14, 2025
1b6df83
correct false initialization of fault set arrays
inctechs Aug 20, 2025
902d76c
TEMPORARILY remove standard form features to pass CI
inctechs Aug 20, 2025
c95e30f
fix double initialisation due to wrong order
inctechs Aug 20, 2025
871655e
temp add unused code instance to pass test
inctechs Aug 20, 2025
690dde1
adapt fault set handling to new PureFaultSet class structure
inctechs Aug 20, 2025
82edb70
adapt method to new indexing of fault sets
inctechs Aug 20, 2025
e9b1a1a
Merge branch 'main' into ft-stateprep-qubit-perm
inctechs Aug 20, 2025
ea8382f
Delete ecc_qiskit_wrapper.py
inctechs Aug 20, 2025
f2714cf
fix mypy issues
inctechs Aug 20, 2025
0f92bb8
add .qasm postfix to all circuit files to pass license hook
inctechs Aug 20, 2025
0fa238d
allow pickle despite security warnings
inctechs Aug 20, 2025
6ec2d45
temporarily allow testing of private methods
inctechs Aug 20, 2025
35679d9
Merge branch 'ft-stateprep-qubit-perm' of https://github.com/cda-tum/…
inctechs Aug 20, 2025
5d1ca34
fix error using variable prior to initialization
inctechs Aug 21, 2025
873d805
remove commented out code
inctechs Aug 21, 2025
59743f6
fix edge case of wrong error type parsed
inctechs Aug 21, 2025
6fefe7a
fix bug that propagation matrix does not get updated
inctechs Sep 12, 2025
81ff592
add plus state simulation capability
inctechs Sep 12, 2025
6520ef2
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
inctechs Sep 16, 2025
d677437
prepare simulations
inctechs Sep 17, 2025
c1fafa2
change probabilities
inctechs Sep 17, 2025
74a524f
add simulation results for 20,2,6 and rot surface code d5
inctechs Oct 8, 2025
983903b
Merge remote-tracking branch 'origin' into ft-stateprep-qubit-perm
inctechs Oct 8, 2025
cfe031a
change simulation propability
inctechs Oct 8, 2025
df89fbf
Merge branch 'main' of https://github.com/munich-quantum-toolkit/qecc…
inctechs Oct 27, 2025
c1d78ae
add (repaired) stim circuit and check matrices of QECCs
inctechs Oct 28, 2025
8d6746c
prepare simulation files for flag at origin sims
inctechs Oct 28, 2025
bf08cc3
update mac bash script for 0.001 sims
inctechs Oct 28, 2025
ea8ac5e
add 0.001 results for square octagon distance 7 code
inctechs Oct 28, 2025
139cb75
Merge remote-tracking branch 'origin/main' into ft-stateprep-qubit-perm
inctechs Nov 23, 2025
d001d50
rename circuit and check matrix files for consitency
inctechs Nov 23, 2025
3013bff
update fao simulation scripts to do remap of qubits
inctechs Nov 23, 2025
5020d48
fix CSV files (comma was missing)
inctechs Jan 15, 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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ ignore = [
"PLR2004", # Magic value used in comparison
"PLC0415", # Import should be at top of file
"S101", # Use of assert detected
"T201", # avoid removing print statements
]
isort.required-imports = ["from __future__ import annotations"]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def run(self, samples: int) -> dict[str, Any]:
self.code_params,
self.eb_precision,
):
print("Result has converged.") # noqa: T201
print("Result has converged.")
break

x_ler, x_ler_eb, x_wer, x_wer_eb = calculate_error_rates(x_success_cnt, runs, self.code_params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,6 @@ def run(self, samples: int = 1) -> dict[str, Any]:
if run % self.save_interval == 1:
self._save_results(success_cnt, run)
if _check_convergence(success_cnt, run, self.code_params, self.eb_precision):
print("Converged") # noqa: T201
print("Converged")
break
return self._save_results(success_cnt, run)
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ def run(self, samples: int) -> dict[str, Any]:
self.code_params,
self.eb_precision,
):
print("Result has converged.") # noqa: T201
print("Result has converged.")
break

x_ler, x_ler_eb, x_wer, x_wer_eb = calculate_error_rates(x_success_cnt, runs, self.code_params)
Expand Down
69 changes: 69 additions & 0 deletions src/mqt/qecc/circuit_synthesis/permutation_st.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""This module implements the features of state preparation with qubit permutation."""

from __future__ import annotations

import logging
from typing import TYPE_CHECKING

import numpy as np
from qiskit import QuantumCircuit

from mqt.qecc.codes.css_code import CSSCode

if TYPE_CHECKING: # pragma: no cover
import numpy.typing as npt

logger = logging.getLogger(__name__)


def get_steane_prep_circ() -> QuantumCircuit:
"""Function that builds up a state preparation circuit for the Steane code."""
circ = QuantumCircuit(7)
circ.h(0)
circ.h(1)
circ.h(3)
circ.cx(0, 6)
circ.cx(1, 2)
circ.cx(3, 5)
circ.cx(0, 4)
circ.cx(1, 5)
circ.cx(0, 2)
circ.cx(3, 4)
circ.cx(5, 6)
return circ


def get_steane_prep_circ_twice() -> QuantumCircuit:
"""Function that builds up a state preparation circuit for the Steane code."""
circ = QuantumCircuit(14)
circ.h(0)
circ.h(1)
circ.h(3)
circ.cx(0, 6)
circ.cx(1, 2)
circ.cx(3, 5)
circ.cx(0, 4)
circ.cx(1, 5)
circ.cx(0, 2)
circ.cx(3, 4)
circ.cx(5, 6)
circ.h(7)
circ.h(8)
circ.h(10)
circ.cx(7, 13)
circ.cx(8, 9)
circ.cx(10, 12)
circ.cx(7, 11)
circ.cx(8, 12)
circ.cx(7, 9)
circ.cx(10, 11)
circ.cx(12, 13)
return circ


def get_steane_css_object() -> CSSCode:
"""Return the Steane Code as CSS object."""
distance: int = 3
hx: npt.NDArray[np.int8] = np.array([[0, 0, 0, 1, 1, 1, 1], [0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1]])
hz: npt.NDArray[np.int8] = np.array([[0, 0, 0, 1, 1, 1, 1], [0, 1, 1, 0, 0, 1, 1], [1, 0, 1, 0, 1, 0, 1]])
return CSSCode(distance, hx, hz, distance, distance)
12 changes: 11 additions & 1 deletion src/mqt/qecc/circuit_synthesis/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(
p: float,
zero_state: bool = True,
parallel_gates: bool = True,
check_logical_0: bool = False,
) -> None:
"""Initialize the simulator.

Expand All @@ -41,6 +42,7 @@ def __init__(
p: The error rate.
zero_state: Whether thezero state is prepared or nor.
parallel_gates: Whether to allow for parallel execution of gates.
check_logical_0: Whether to check flag measurements or the logical state
"""
if code.Hx is None or code.Hz is None:
msg = "The code must have both X and Z checks."
Expand All @@ -62,6 +64,7 @@ def __init__(
self.n_measurements = 0
self.stim_circ = stim.Circuit()
self.decoder = LutDecoder(code)
self.check_logical_0 = check_logical_0
self.set_p(p)

def set_p(self, p: float) -> None:
Expand Down Expand Up @@ -271,7 +274,14 @@ def _simulate_batch(self, shots: int = 1024) -> tuple[int, int]:

# Filter events where the verification circuit flagged
verification_measurements = self.x_verification_measurements + self.z_verification_measurements
index_array = np.where(np.all(detection_events[:, verification_measurements] == 0, axis=1))[0]
if self.check_logical_0:
# Compute dot products for all rows
dot_products = np.dot(detection_events[:, verification_measurements], self.code.Hx.T) % 2

# Find rows where all dot products are zero
index_array = np.where(np.all(dot_products == 0, axis=1))[0]
else:
index_array = np.where(np.all(detection_events[:, verification_measurements] == 0, axis=1))[0]
filtered_events = detection_events[index_array].astype(np.int8)

if len(filtered_events) == 0: # All events were discarded
Expand Down
67 changes: 67 additions & 0 deletions src/mqt/qecc/circuit_synthesis/state_prep.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from ..codes import InvalidCSSCodeError
from .synthesis_utils import (
build_css_circuit_from_cnot_list,
get_permutation_group,
heuristic_gaussian_elimination,
iterative_search_with_timeout,
measure_flagged,
Expand All @@ -34,6 +35,7 @@
import numpy.typing as npt
from qiskit import DAGNode
from qiskit.quantum_info import PauliList
from sympy.combinatorics import Permutation

from ..codes import CSSCode

Expand Down Expand Up @@ -239,6 +241,71 @@
return StatePrepCircuit(circ, code, zero_state)


def fs_disjunct_spc(
code: CSSCode, automorph_generators: list[list[int]], optimize_depth: bool = True, zero_state: bool = True
) -> None:
"""Returns dictionary of permutations for the given QEC.
This function takes a QEC and the corresponding strong automorphism group. It then checks every permutation and
returns a dictionary with all permutations as keys and the overlapping propagated errors in the fault set.
Args:
code: The CSS code to prepare the state for.
optimize_depth: If True, optimize the depth of the circuit. This may lead to a higher number of CNOTs.
zero_state: If True, prepare the +1 eigenstate of the Z basis. If False, prepare the +1 eigenstate of the X basis.
automorph_generators: foobar
"""
logger.info("Starting heuristic state preparation.")
if code.Hx is None or code.Hz is None:
msg = "The code must have both X and Z stabilizers defined."
raise InvalidCSSCodeError(msg)

checks = code.Hx if zero_state else code.Hz
assert checks is not None
checks, cnots = heuristic_gaussian_elimination(checks, parallel_elimination=optimize_depth)
# NOTE: everything above is code duplication from heuristic_prep_circuit()

permutation_group = get_permutation_group(group_generators=automorph_generators)
# BUG: I have those prints since the stateprep circuit below gives another fault set than the one
# returned all the way at the bottom without this if section and I do not understand why
circ = _build_state_prep_circuit_from_back(checks.copy(), cnots.copy(), zero_state)
stateprepcirc = StatePrepCircuit(circ, code, zero_state)

# NOTE: get fault sets based on code distance
stateprepcirc.compute_fault_set()
fault_set_1 = stateprepcirc.x_fault_sets[1]
if stateprepcirc.code.distance == 5:
fault_set_1 = fault_set_1[np.where(fault_set_1.sum(axis=1) > 2)]
if stateprepcirc.code.distance == 7:
stateprepcirc.compute_fault_set(2)
fault_set_2 = stateprepcirc.x_fault_sets[2]
fault_set_1 = fault_set_1[np.where(fault_set_1.sum(axis=1) > 3)]
fault_set_2 = fault_set_2[np.where(fault_set_2.sum(axis=1) > 3)]

# HACK: Overlap search has 3 nested for loops, check for improvement
overlapping_faults: list[npt.NDArray[np.int8]] = []
perm_overlap: dict[Permutation, list[npt.NDArray[np.int8]]] = {}
original_faults = fault_set_1
print(f"fault set 1: \n{fault_set_1}")
if stateprepcirc.code.distance == 7:
original_faults = np.vstack(fault_set_1, fault_set_2)
print(f"fault set 2: \n{fault_set_2}")
print(f"comparison fault set: \n{original_faults}")
for perm in permutation_group:
perm_fs = fault_set_1[:, perm.array_form]
for pf in perm_fs:
for ff in original_faults:
if code.stabilizer_eq_x_error(pf, ff):
# FIX: without this print statement append gets changed to extend on save
print(f"permutation: {perm}")
print(f"stabilizer equivalent error: \n{pf}(permuted) and \n{ff}(not permuted)")
overlapping_faults.append(pf)
perm_overlap[perm] = overlapping_faults
overlapping_faults = []

return perm_overlap


def depth_optimal_prep_circuit(
code: CSSCode,
zero_state: bool = True,
Expand Down
21 changes: 18 additions & 3 deletions src/mqt/qecc/circuit_synthesis/synthesis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from ldpc import mod2
from qiskit import AncillaRegister, ClassicalRegister, QuantumCircuit
from stim import Circuit
from sympy.combinatorics import Permutation, PermutationGroup

if TYPE_CHECKING: # pragma: no cover
from collections.abc import Callable
Expand Down Expand Up @@ -96,7 +97,7 @@ def heuristic_gaussian_elimination(
matrix: The matrix to perform Gaussian elimination on.
parallel_elimination: Whether to prioritize elimination steps that act on disjoint columns.

returns:
Returns:
The reduced matrix and a list of the elimination steps taken. The elimination steps are represented as tuples of the form (i, j) where i is the column being eliminated with and j is the column being eliminated.
"""
matrix = matrix.copy()
Expand Down Expand Up @@ -152,6 +153,20 @@ def is_reduced() -> bool:
return matrix, eliminations


def get_permutation_group(group_generators: list[list[int]]) -> list[Permutation]:
"""Based on the generators of the permutation group find the whole permutation group.

Args:
group_generators: A list of generators of the permutation group. Each generator is given as a list of integers describing the permutation. E.g. for a S7 generator: [0, 3, 2, 1, 6, 5, 4]

Returns:
Returns a list of Permutation object coming form sympy.combinatorics.
"""
group_generators = [Permutation(generator) for generator in group_generators]
g = PermutationGroup(group_generators)
return list(g.generate())


def gaussian_elimination_min_column_ops(
matrix: npt.NDArray[np.int8],
termination_criteria: Callable[[Any], z3.BoolRef],
Expand All @@ -166,7 +181,7 @@ def gaussian_elimination_min_column_ops(
termination_criteria: A function that takes a boolean matrix as input and returns a Z3 boolean expression that is true if the matrix is considered reduced.
max_eliminations: The maximum number of eliminations to perform.

returns:
Returns:
The reduced matrix and a list of the elimination steps taken. The elimination steps are represented as tuples of the form (i, j) where i is the column being eliminated with and j is the column being eliminated.
"""
n = matrix.shape[1]
Expand Down Expand Up @@ -235,7 +250,7 @@ def gaussian_elimination_min_parallel_eliminations(
termination_criteria: A function that takes a boolean matrix as input and returns a Z3 boolean expression that is true if the matrix is considered reduced.
max_parallel_steps: The maximum number of parallel elimination steps to perform.

returns:
Returns:
The reduced matrix and a list of the elimination steps taken. The elimination steps are represented as tuples of the form (i, j) where i is the column being eliminated with and j is the column being eliminated.
"""
columns = np.array([
Expand Down
10 changes: 5 additions & 5 deletions src/mqt/qecc/ecc_qiskit_wrapper.py
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file has been removed from QECC. Please remove it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should this file be deleted? I read it somewhere else in a comment from you @pehamTom

Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def print_simulation_results(result: Result, n_shots: int, threshold_probability
# Print all results > threshold_probability
if summarized_counts[result_id] / n_shots > threshold_probability or printed_results == 0:
result_string = str(result_id)
print("State |" + result_string + "> probability " + str(summarized_counts[result_id] / n_shots)) # noqa: T201
print("State |" + result_string + "> probability " + str(summarized_counts[result_id] / n_shots))
printed_results += 1
if printed_results == 1000:
break
Expand Down Expand Up @@ -154,7 +154,7 @@ def main() -> None:
ecc_frequency = args.fq
ecc_export_filename = args.e
if forced_simulator is not None and "stabilizer" in forced_simulator and "A" in error_channels:
print( # noqa: T201
print(
'Warning: Non-unitary errors (such as for example amplitude damping ("A")) are not suitable for simulation '
"with a stabilizer based simulator and may cause an error during the simulation."
)
Expand All @@ -168,7 +168,7 @@ def main() -> None:
circ = load(open_qasm_file)

if not any(gate.operation.name == "measure" for gate in circ.data):
print("Warning: No measurement gates found in the circuit. Adding measurement gates to all qubits.") # noqa: T201
print("Warning: No measurement gates found in the circuit. Adding measurement gates to all qubits.")
circ.measure_all()

# Initializing the quantum circuit
Expand All @@ -178,13 +178,13 @@ def main() -> None:
circ = loads(result["circ"])

if ecc_export_filename is not None:
print("Exporting circuit to: " + str(ecc_export_filename)) # noqa: T201
print("Exporting circuit to: " + str(ecc_export_filename))
with pathlib.Path(ecc_export_filename).open("w", encoding=locale.getpreferredencoding(False)) as f:
dump(circ, f)
return

size = circ.num_qubits
print( # noqa: T201
print(
"_____Trying to simulate with "
+ str(error_channels)
+ " (prob="
Expand Down
Loading