mqt.qecc.circuit_synthesis.state_prep

Synthesizing state preparation circuits for CSS codes.

Classes

FaultyStatePrepCircuit

Represents a state preparation circuit for a CSS code.

Functions

heuristic_prep_circuit(code[, optimize_depth, state, ...]) → FaultyStatePrepCircuit

Return a circuit that prepares the +1 eigenstate of the code w.r.t. the Z or X basis.

depth_optimal_prep_circuit(code[, zero_state, ...]) → FaultyStatePrepCircuit | None

Synthesize a state preparation circuit for a CSS code that minimizes the circuit depth.

gate_optimal_prep_circuit(code[, zero_state, ...]) → FaultyStatePrepCircuit | None

Synthesize a state preparation circuit for a CSS code that minimizes the number of gates.

gate_optimal_verification_stabilizers(fault_sets, stabs) → list[list[numpy.typing.NDArray[numpy.int8]]]

Return verification stabilizers for the given fault sets..

all_gate_optimal_verification_stabilizers(fault_sets, ...) → list[list[list[numpy.typing.NDArray[numpy.int8]]]]

Return all equivalent verification stabilizers for the given fault sets.

gate_optimal_verification_circuit(sp_circ[, ...]) → qiskit.circuit.QuantumCircuit

Return a verified state preparation circuit.

heuristic_verification_circuit(sp_circ[, ...]) → qiskit.circuit.QuantumCircuit

Return a verified state preparation circuit.

heuristic_verification_stabilizers(fault_sets, stabs) → list[list[numpy.typing.NDArray[numpy.int8]]]

Return verification stabilizers for the given fault sets.

verification_stabilizers(fault_set, stabs, num_anc, ...) → list[numpy.typing.NDArray[numpy.int8]] | None

Return a set of stabilizers detecting all errors in fault_set using at most num_anc ancillas and at most num_cnots cnots.

all_verification_stabilizers(fault_set, stabs, ...[, ...]) → list[list[numpy.typing.NDArray[numpy.int8]]] | None

Return a list of verification stabilizers for independent errors in the state preparation circuit using z3.

naive_verification_circuit(sp_circ[, flag_first_layer]) → qiskit.circuit.QuantumCircuit

Naive verification circuit for a state preparation circuit.

get_hook_errors(measurements) → mqt.qecc.circuit_synthesis.faults.PureFaultSet

Assuming CNOTs are executed in ascending order of qubit index, this function gives all the hook errors of the given stabilizer measurements.

Module Contents

class FaultyStatePrepCircuit(circ: CNOTCircuit, max_x_errors: int, max_z_errors: int)[source]

Represents a state preparation circuit for a CSS code.

compute_fault_sets(reduce: bool = True) → None[source]

Compute the fault sets for the state preparation circuit.

compute_fault_set(num_errors: int = 1, x_errors: bool = True, reduce: bool = True) → PureFaultSet[source]

Compute the fault set of the state.

Parameters:
  • num_errors – The number of independent errors to propagate through the circuit.

  • x_errors – If True, compute the fault set for X errors. If False, compute the fault set for Z errors.

  • reduce – If True, reduce the fault set by the stabilizers of the code to reduce weights.

Returns:

The fault set of the state.

set_max_errors(max_x_errors: int, max_z_errors: int) → None[source]

Set maximum errors. Also resets cached fault sets.

combine_faults(additional_faults: PureFaultSet, x_errors: bool = True, reduce: bool = False) → list[PureFaultSet][source]

Combine fault sets of circuit with additional independent faults.

Parameters:
  • additional_faults – The additional faults to combine with the fault set of the circuit.

  • x_errors – If True, combine the fault sets for X errors. If False, combine the fault sets for Z errors.

  • reduce – If True, stabilizer-equivalent errors will be removed after fault set construction.

heuristic_prep_circuit(code: CSSCode, optimize_depth: bool = True, state: str = 'all_zero', *, rollout: int = 0, rollout_candidates: int = 10) → FaultyStatePrepCircuit[source]

Return a circuit that prepares the +1 eigenstate of the code w.r.t. the Z or X basis.

Parameters:
  • code – The CSS code to prepare the state for.

  • state – k-length string representing the logical state to prepare. If “all_zero”, prepare the +1 eigenstate of the Z basis. If “all_plus”, prepare the +1 eigenstate of the X basis.

  • optimize_depth – If True, optimize the circuit for depth. If False, optimize for number of gates.

  • rollout – The number of rollout steps to use in the heuristic synthesis. Higher values can lead to better circuits but also increase runtime.

  • rollout_candidates – The number of candidates to consider in each rollout step. Higher values can lead to better circuits but also increase runtime.

Returns:

A state preparation circuit for the given code.

depth_optimal_prep_circuit(code: CSSCode, zero_state: bool = True, min_depth: int = 1, max_depth: int = 10, min_timeout: int = 1, max_timeout: int = 3600) → FaultyStatePrepCircuit | None[source]

Synthesize a state preparation circuit for a CSS code that minimizes the circuit depth.

Parameters:
  • code – The CSS code to prepare the state for.

  • zero_state – If True, prepare the +1 eigenstate of the Z basis. If False, prepare the +1 eigenstate of the X basis.

  • min_depth – minimum depth to start with

  • max_depth – maximum depth to reach

  • min_timeout – minimum timeout to start with

  • max_timeout – maximum timeout to reach

gate_optimal_prep_circuit(code: CSSCode, zero_state: bool = True, min_gates: int = 1, max_gates: int = 10, min_timeout: int = 1, max_timeout: int = 3600) → FaultyStatePrepCircuit | None[source]

Synthesize a state preparation circuit for a CSS code that minimizes the number of gates.

Parameters:
  • code – The CSS code to prepare the state for.

  • zero_state – If True, prepare the +1 eigenstate of the Z basis. If False, prepare the +1 eigenstate of the X basis.

  • min_gates – minimum number of gates to start with

  • max_gates – maximum number of gates to reach

  • min_timeout – minimum timeout to start with

  • max_timeout – maximum timeout to reach

gate_optimal_verification_stabilizers(fault_sets: list[PureFaultSet], stabs: numpy.typing.NDArray[numpy.int8], min_timeout: int = 1, max_timeout: int = 3600, max_ancillas: int | None = None) → list[list[numpy.typing.NDArray[numpy.int8]]][source]

Return verification stabilizers for the given fault sets..

The method uses an iterative search to find the optimal set of stabilizers by repeatedly computing the optimal circuit for each number of ancillas and cnots. This is repeated for each number of independent correctable errors in the state preparation circuit. Thus the verification circuit is constructed of multiple “layers” of stabilizers, each layer corresponding to a fault set it verifies.

Parameters:
  • fault_sets – List of fault sets to verify.

  • stabs – The stabilizer generators to verify the fault sets.

  • min_timeout – The minimum time to allow each search to run for.

  • max_timeout – The maximum time to allow each search to run for.

  • max_ancillas – The maximum number of ancillas to allow in each layer verification circuit.

Returns:

A list of stabilizers for each number of errors to verify the state preparation circuit.

all_gate_optimal_verification_stabilizers(fault_sets: list[PureFaultSet], stabs: numpy.typing.NDArray[numpy.int8], min_timeout: int = 1, max_timeout: int = 3600, max_ancillas: int | None = None, return_all_solutions: bool = False) → list[list[list[numpy.typing.NDArray[numpy.int8]]]][source]

Return all equivalent verification stabilizers for the given fault sets.

The method uses an iterative search to find the optimal set of stabilizers by repeatedly computing the optimal circuit for each number of ancillas and cnots. This is repeated for each number of independent correctable errors in the state preparation circuit. Thus the verification circuit is constructed of multiple “layers” of stabilizers, each layer corresponding to a fault set it verifies.

Parameters:
  • fault_sets – List of fault sets to verify.

  • stabs – The stabilizer generators to verify the fault sets.

  • min_timeout – The minimum time to allow each search to run for.

  • max_timeout – The maximum time to allow each search to run for.

  • max_ancillas – The maximum number of ancillas to allow in each layer verification circuit.

  • additional_faults – Faults to verify in addition to the faults propagating in the state preparation circuit.

  • return_all_solutions – If False only the first solution for each number of errors is returned. If True all solutions are returned.

Returns:

A list of all equivalent stabilizers for each number of errors to verify the state preparation circuit.

gate_optimal_verification_circuit(sp_circ: FaultyStatePrepCircuit, min_timeout: int = 1, max_timeout: int = 3600, max_ancillas: int | None = None, only_first_layer: bool = False, verify_x_first: bool = True, flag_first_layer: bool = False) → QuantumCircuit[source]

Return a verified state preparation circuit.

The verification circuit is a set of stabilizers such that each propagated error in sp_circ anticommutes with some verification stabilizer.

The method uses an iterative search to find the optimal set of stabilizers by repeatedly computing the optimal circuit for each number of ancillas and cnots. This is repeated for each number of independent correctable errors in the state preparation circuit. Thus the verification circuit is constructed of multiple “layers” of stabilizers, each layer corresponding to a fault set it verifies.

Parameters:
  • sp_circ – The state preparation circuit to verify.

  • min_timeout – The minimum time to allow each search to run for.

  • max_timeout – The maximum time to allow each search to run for.

  • max_ancillas – The maximum number of ancillas to allow in each layer verification circuit.

  • only_first_layer – If True, only the first error type will be verified. The type depends on the verify_x_first argument.

  • verify_x_first – If True, X-errors are verified first.

  • flag_first_layer – If True, the first verification layer (verifying X or Z errors) will also be flagged. If False, the potential hook errors introduced by the first layer will be caught by the second layer. This is only relevant if full_fault_tolerance is True.

Returns:

QuantumCircuit combining the state preparation and verification circuit.

heuristic_verification_circuit(sp_circ: FaultyStatePrepCircuit, max_covering_sets: int = 10000, find_coset_leaders: bool = True, only_first_layer: bool = False, verify_x_first: bool = True, flag_first_layer: bool = False) → QuantumCircuit[source]

Return a verified state preparation circuit.

The method uses a greedy set covering heuristic to find a small set of stabilizers that verifies the state preparation circuit. The heuristic is not guaranteed to find the optimal set of stabilizers.

Parameters:
  • sp_circ – The state preparation circuit to verify.

  • max_covering_sets – The maximum number of covering sets to consider.

  • find_coset_leaders – Whether to find coset leaders for the found measurements. This is done using SAT solvers so it can be slow.

  • only_first_layer – If True, only the first error type will be verified. The type depends on the verify_x_first argument.

  • verify_x_first – If True, X-errors are verified first.

  • flag_first_layer – If True, the first verification layer (verifying X or Z errors) will also be flagged. If False, the potential hook errors introduced by the first layer will be caught by the second layer. This is only relevant if full_fault_tolerance is True.

Returns:

QuantumCircuit combining the state preparation and verification circuit.

heuristic_verification_stabilizers(fault_sets: list[PureFaultSet], stabs: numpy.typing.NDArray[numpy.int8], max_covering_sets: int = 10000, find_coset_leaders: bool = True) → list[list[numpy.typing.NDArray[numpy.int8]]][source]

Return verification stabilizers for the given fault sets.

Parameters:
  • fault_sets – List of fault sets to verify.

  • stabs – The stabilizer generators to verify the fault sets.

  • max_covering_sets – The maximum number of covering sets to consider.

  • find_coset_leaders – Whether to find coset leaders for the found measurements. This is done using SAT solvers so it can be slow.

verification_stabilizers(fault_set: PureFaultSet, stabs: numpy.typing.NDArray[numpy.int8], num_anc: int, num_cnots: int) → list[numpy.typing.NDArray[numpy.int8]] | None[source]

Return a set of stabilizers detecting all errors in fault_set using at most num_anc ancillas and at most num_cnots cnots.

Parameters:
  • fault_set – The fault set to verify.

  • stabs – The stabilizer generators to verify the fault set.

  • num_anc – The maximum number of ancilla qubits to use.

  • num_cnots – The maximum number of CNOT gates to use.

Returns:

List of stabilizers.

all_verification_stabilizers(fault_set: PureFaultSet, stabs: numpy.typing.NDArray[numpy.int8], num_anc: int, num_cnots: int, return_all_solutions: bool = False) → list[list[numpy.typing.NDArray[numpy.int8]]] | None[source]

Return a list of verification stabilizers for independent errors in the state preparation circuit using z3.

Parameters:
  • fault_set – The set of errors to verify.

  • stabs – Stabilizer generators of the stabilizers measured.

  • num_anc – The maximum number of ancilla qubits to use.

  • num_cnots – The maximum number of CNOT gates to use.

  • return_all_solutions – If True, return all solutions. Otherwise, return the first solution found.

naive_verification_circuit(sp_circ: FaultyStatePrepCircuit, flag_first_layer: bool = True) → QuantumCircuit[source]

Naive verification circuit for a state preparation circuit.

get_hook_errors(measurements: list[numpy.typing.NDArray[numpy.int8]]) → PureFaultSet[source]

Assuming CNOTs are executed in ascending order of qubit index, this function gives all the hook errors of the given stabilizer measurements.