mqt.qecc.circuit_synthesis.cat_states

Methods for preparing cat states and running experiments on them.

Classes

CatStatePreparationExperiment

Cat-state prep with post-selection, allowing ancilla size w2 ≤ data size w1.

Functions

cat_state_balanced_tree(w) → stim.Circuit

Build preparation circuit as perfect, balanced binary tree. Only works if w is a power of two.

cat_state_line(w) → stim.Circuit

Build preparation circuit only using cnots along a line.

append_transversal_cnot_pairs(circ, pairs) → None

Append a layer of CX using disjoint pairs.

build_transversal_pairs(controls, perm_targets, w1, w2) → list[tuple[int, int]]

Return list of (control, target) indices for a single parallel CX layer (controls[i], w1 + perm_targets[i]) for i=0..w2-1.

cat_state_pruned_balanced_circuit(w) → stim.Circuit

Prepare GHZ_w in log-depth with a balanced tree circuit.

fault_gens_from_circuit(circ) → list[int]

Propagated single-qubit errors in a cat state preparation circuit.

recursive_fuse_cat_state(w, t) → tuple[stim.Circuit, list[tuple[list[int], list[int]]]]

Construct t-FT cat state prep circuit from arXiv:2506.17181.

simulate_recursive_cat_construction(w, t, p[, ...]) → tuple[float, float, numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]]

Simulate the recursive fusion scheme returned by recursive_fuse_cat_state(w,t).

propagate_and_permute_error(error, controls, perm) → int

Propagate error through the controls of a partial transversal CNOT and permute according to target permutation.

propagate_error_transversal(error, controls) → int

Propagate error through the controls of a partial transversal CNOT.

permute_error(error, perm, w) → int

Permute error according to the given permutation.

check_ft_partial_cnot(gens1, w1, gens2, w2, controls, ...) → tuple[bool, dict[str, int | list[int]] | None]

Check whether the CNOT defined by the given selection of control qubits and permutation is FT-t for the given fault set generators.

search_ft_cnot_cegar(c1, c2, t[, max_rounds]) → tuple[list[int] | None, list[int] | None, dict[str, str | int]]

Use CEGAR approach to find an ft-t partial transversal CNOT.

search_ft_cnot_local_search(c1, c2, t[, seed, ctrls, ...]) → tuple[list[int] | None, list[int] | None, dict[str, str | int]]

Use local search approach to find an ft-t partial transversal CNOT.

search_ft_cnot_smt(c1, c2, t[, seed, ctrls]) → tuple[list[int] | None, list[int] | None, dict[str, str | int]]

Use direct smt solving approach to find an ft-t partial transversal CNOT.

construct_bad_error_sets(gens1, w1, gens2, w2, t, controls) → tuple[dict[int, set[int]], list[int]]

Construct sets of "bad" ancilla errors that can cause FT violations for given controls.

Module Contents

cat_state_balanced_tree(w: int) → stim.Circuit[source]

Build preparation circuit as perfect, balanced binary tree. Only works if w is a power of two.

Circuit will be built over qubits start_idx, …, start_idx+w :param w: number of qubits of the cat state, assumed to be a power of two :param p: noise parameter :param start_idx: lowest index of qubit appearing in the circuit.

Returns:

noisy stim circuit preparing the cat state.

cat_state_line(w: int) → stim.Circuit[source]

Build preparation circuit only using cnots along a line.

Circuit will be built over qubits start_idx, …, start_idx+w :param w: number of qubits of the cat state :param p: noise parameter :param start_idx: lowest index of qubit appearing in the circuit.

Returns:

noisy stim circuit preparing the cat state

class CatStatePreparationExperiment(circ1: stim.Circuit, circ2: stim.Circuit, permutation: Sequence[int] | None = None, controls: Sequence[int] | None = None)[source]

Cat-state prep with post-selection, allowing ancilla size w2 ≤ data size w1.

Layout:

data: 0 .. w1-1 ancilla: w1 .. w1+w2-1

Wiring (one parallel layer):

pairs: (controls[i], w1 + permutation[i]) for i=0..w2-1

sample_cat_state(p: float, n_samples: int = 1024, batch_size: int | None = None) → tuple[float, float, numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]][source]

Run with circuit-level noise, post-select on ancilla ∈ {0^w2, 1^w2}, and histogram the symmetric error weight on data.

Returns:

acceptance_rate, acceptance_rate_error, error_rates (length floor(w1/2)+1), error_rates_error

plot_one_p(p: float, n_samples: int = 1024, batch_size: int | None = None, ax: matplotlib.pyplot.Axes | None = None) → None[source]

Plot the distribution of residual error weights on the data cat state for the given physical error rate.

cat_prep_experiment(ps: list[float], shots_per_p: int | list[int]) → tuple[list[float], list[float], numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]][source]

Simulate post-selection based cat state preparation for various physical error rates using a circuit-level depolarizing noise.

Parameters:
  • ps – list of physical error rates.

  • shots_per_p – number of shots for each simulation or list if number of shots should depend on the simulated physical error rate.

Returns:

A tuple containing - List of acceptance rates - List of estimated error bars of the acceptance rate - List of lists of error rates of length w/2. The i-th entry is the fraction of shots with a residual error of weight i on the data. - List of lists of error bars for the residual errors

append_transversal_cnot_pairs(circ: stim.Circuit, pairs: Sequence[tuple[int, int]]) → None[source]

Append a layer of CX using disjoint pairs.

This function assumes that circ1 acts on the first w qubits and circ2 on the second w qubits

build_transversal_pairs(controls: Sequence[int], perm_targets: Sequence[int], w1: int, w2: int) → list[tuple[int, int]][source]

Return list of (control, target) indices for a single parallel CX layer (controls[i], w1 + perm_targets[i]) for i=0..w2-1.

cat_state_pruned_balanced_circuit(w: int) → stim.Circuit[source]

Prepare GHZ_w in log-depth with a balanced tree circuit.

If w is not a power of two, CNOTs are pruned from the full balanced tree until the circuit acts on w qubits.

Parameters:

w – number of qubits of the cat state

Returns:

stim circuit preparing the cat state

fault_gens_from_circuit(circ: stim.Circuit) → list[int][source]

Propagated single-qubit errors in a cat state preparation circuit.

Includes all singletons , For each CX pair (c,t) in sequence, inject X on c just before that CX and propagate through the remaining pairs.

Parameters:
  • circ – stim circuit consisting of CX gates only

  • include_full – whether to include the full-weight generator

Returns:

sorted list of int bit strings representing the propagated errors

recursive_fuse_cat_state(w: int, t: int) → tuple[stim.Circuit, list[tuple[list[int], list[int]]]][source]

Construct t-FT cat state prep circuit from arXiv:2506.17181.

simulate_recursive_cat_construction(w: int, t: int, p: float, n_samples: int = 1024, batch_size: int | None = None) → tuple[float, float, numpy.typing.NDArray[numpy.float64], numpy.typing.NDArray[numpy.float64]][source]

Simulate the recursive fusion scheme returned by recursive_fuse_cat_state(w,t).

Post-selection per step:
  • If the step has exactly one ancilla prepared with RX -> accept iff corrected ancilla == 1.

  • Otherwise -> accept iff all corrected ancillas agree (all 0s or all 1s).

If accepted, apply a UNIFORM X frame update to every qubit in data_qubits for that step IFF the (single or common) corrected ancilla bit is 1.

Parameters:
  • w – cat state size

  • t – fault distance

  • p – physical error rate

  • n_samples – number of shots

  • batch_size – number of shots per batch

Returns:

A tuple containing - Acceptance rate - Estimated error bars of the acceptance rate - A list of error rates of length w/2. The i-th entry is the fraction of shots with a residual error of weight i on the data. - A list of error bars for the residual errors

propagate_and_permute_error(error: int, controls: list[int], perm: list[int]) → int[source]

Propagate error through the controls of a partial transversal CNOT and permute according to target permutation.

Parameters:
  • error – int bit string encoding the error

  • controls – controls of the transversal CNOT

  • perm – permutation of the targets

Returns:

int bit string representing the error that actually propagates

propagate_error_transversal(error: int, controls: list[int]) → int[source]

Propagate error through the controls of a partial transversal CNOT.

Parameters:
  • error – int bit string encoding the error

  • controls – controls of the transversal CNOT

Returns:

int bit string representing the error that actually propagates

permute_error(error: int, perm: list[int], w: int) → int[source]

Permute error according to the given permutation.

Parameters:
  • error – int bit string representing the error

  • perm – permutation on [0..w-1] qubits

  • w – number of qubits

Returns:

the permuted error

check_ft_partial_cnot(gens1: list[int], w1: int, gens2: list[int], w2: int, controls: list[int], perm: list[int], t: int) → tuple[bool, dict[str, int | list[int]] | None][source]

Check whether the CNOT defined by the given selection of control qubits and permutation is FT-t for the given fault set generators.

Parameters:
  • gens1 – fault set generators of data cat state

  • w1 – number of qubits of data cat state

  • gens2 – fault set generators of ancilla cat state

  • w2 – number of qubits of ancilla cat state

  • controls – list of integers denoting qubits acting as controls in the data cat state

  • perm – permutation of [0..w2-1] defining how targets are permuted

  • t – fault distance

Returns:

Boolean indicating whether the given CNOT is FT-t, along with a counterexample if False

search_ft_cnot_cegar(c1: stim.Circuit, c2: stim.Circuit, t: int, max_rounds: int = 10000) → tuple[list[int] | None, list[int] | None, dict[str, str | int]][source]

Use CEGAR approach to find an ft-t partial transversal CNOT.

Parameters:
  • c1 – circuit preparing data cat state

  • c2 – circuit preparing ancilla cat state

  • t – target fault distance

  • add_symmetry_breakers (default True) – whether to encode symmetry breakers

  • max_rounds (default 10000) – number of CEGAR iterations to try

Returns:

…, "rounds"}

Return type:

list of controls, list of permutation and search information dict {“sat”

Use local search approach to find an ft-t partial transversal CNOT.

Search proceeds by randomly selecting control qubits and locally modifying permutations until no conflict occurs. This is not guaranteed to converge.

Parameters:
  • c1 – circuit preparing data cat state

  • c2 – circuit preparing ancilla cat state

  • t – target fault distance

  • seed – seed for random number generator

  • ctrls – Either a list of different controls to try, a single choice of controls to try, or an integer number of random control selections to try.

  • ctrl_moves (default 200) – number of local control modifications to try per restart

  • perm_iters (default 200000) – number of permutation repair iterations to try per control selection

Returns:

…, "rounds"}

Return type:

list of controls, list of permutation and search information dict {“sat”

search_ft_cnot_smt(c1: stim.Circuit, c2: stim.Circuit, t: int, seed: int = 1, ctrls: list[list[int]] | list[int] | int = 100) → tuple[list[int] | None, list[int] | None, dict[str, str | int]][source]

Use direct smt solving approach to find an ft-t partial transversal CNOT.

Parameters:
  • c1 – circuit preparing data cat state

  • c2 – circuit preparing ancilla cat state

  • t – target fault distance

  • seed – seed for random number generator

  • ctrls – Either a list of different controls to try, a single choice of controls to try, or an integer number of random control selections to try.

Returns:

…, "rounds"}

Return type:

list of controls, list of permutation and search information dict {“sat”

construct_bad_error_sets(gens1: list[int], w1: int, gens2: list[int], w2: int, t: int, controls: list[int]) → tuple[dict[int, set[int]], list[int]][source]

Construct sets of “bad” ancilla errors that can cause FT violations for given controls.

For each possible propagated error, we store the set of ancilla errors that can cancel it out.

Returns:

set of errors that can cause violations, indexed by projected error e err_list: list of possible errors

Return type:

bad_errors