mqt.qecc.circuit_synthesis.faults

Functionality for handling collections of circuit faults.

Classes

PureFaultSet

Represents a collection of pure faults (X-type or Z-type) in a quantum circuit.

Functions

coset_leader(fault, generators) → numpy.typing.NDArray[numpy.int8]

Compute the coset leader of a fault given a set of stabilizer generators.

product_fault_set(lhs, rhs) → PureFaultSet

Generate fault set by forming the product of all faults of two fault sets.

stabilizer_equivalent(lhs, rhs, stabs) → bool

Check if two fault sets are equivalent with respect to a stabilizer group.

t_distinct(fs1, fs2, t[, stabs]) → bool

Check if two fault sets are t-distinct.

Module Contents

class PureFaultSet(num_qubits: int)[source]

Represents a collection of pure faults (X-type or Z-type) in a quantum circuit.

add_fault(fault: numpy.typing.NDArray[numpy.int8]) → None[source]

Add a fault to the fault set.

Parameters:

fault – A 1D numpy array representing the fault. The array must have length ~num_qubits~.

add_faults(faults: numpy.typing.NDArray[numpy.int8]) → None[source]

Add multiple faults to the fault set.

Parameters:

faults – A 2D numpy array representing a collection of faults.

combine(other: PureFaultSet, inplace: bool = False) → PureFaultSet[source]

Combine this fault set with another fault set.

Parameters:
  • other – Another PureFaultSet to combine with.

  • inplace – If True, modifies self.

Returns:

A new PureFaultSet representing the combined faults.

to_array() → numpy.typing.NDArray[numpy.int8][source]

Convert the fault set to a numpy array.

Returns:

A 2D numpy array where each row represents a fault.

classmethod from_fault_array(array: numpy.typing.NDArray[numpy.int8]) → PureFaultSet[source]

Create a PureFaultSet from a numpy array of faults.

Returns:

A PureFaultSet object containing the faults.

classmethod from_cnot_circuit(circ: CNOTCircuit, kind: str = 'X', reduce: bool = False) → PureFaultSet[source]

Generate a PureFaultSet from a CNOT circuit.

Parameters:
  • circ – The CNOT circuit to generate faults from.

  • kind – The type of faults to generate (‘X’ or ‘Z’).

  • reduce – Reduce faults by stabilizers induced by the circuit.

Returns:

A PureFaultSet containing the faults generated from the circuit.

normalize(stabs: numpy.typing.NDArray[numpy.int8]) → None[source]

Normalize the faults with respect to a stabilizer group.

A fault is considered normalized if its entries in the pivot columns of the RREF of the stabilizer matrix are zero.

Parameters:

stabs – A 2D numpy array where each row is a stabilizer generator.

remove_zero_rows() → None[source]

Remove all zero rows from the fault set.

This method modifies the fault set in place, removing any rows that are entirely zero.

remove_duplicates() → None[source]

Remove duplicate faults from the fault set.

This method modifies the fault set in place, ensuring that each fault is unique.

remove_equivalent(stabs: numpy.typing.NDArray[numpy.int8]) → None[source]

Remove faults belonging to the same coset with respect to the stabilizer group.

Parameters:

stabs – A 2D numpy array where each row is a stabilizer generator.

to_set() → set[tuple[int, ...]][source]

Convert the fault set to a set of tuples for easier comparison.

faults_to_coset_leaders(generators: numpy.typing.NDArray[numpy.int8]) → None[source]

Map all faults in the set to their coset leaders with respect to the stabilizer generators.

This method modifies the fault set in place, replacing each fault with its coset leader. Warning: This might take a while.

Parameters:

generators – A 2D numpy array where each row is a stabilizer generator.

filter_by_weight_at_least(w: int, stabs: numpy.typing.NDArray[numpy.int8]) → None[source]

Filter faults by weight with respect to a stabilizer group.

A fault is removed if its coset leader has weight lower than w. This operation also removes stabilizer equivalent errors and maps faults to their coset leaders.

Parameters:
  • w – Weight faults are filtered by.

  • stabs – A 2D numpy array where each row is a stabilizer generator.

copy() → PureFaultSet[source]

Create a copy of the PureFaultSet.

Returns:

A new PureFaultSet object with the same faults and number of qubits.

all_faults_detected(stabs: numpy.typing.NDArray[numpy.int8]) → bool[source]

Check whether all faults in the set are detected by the given stabilizers.

Parameters:

stabs – A 2D numpy array where each row is a stabilizer generator.

Returns:

True if every fault anticommutes with at least one generator, False otherwise

get_undetectable_faults_idx(stabs: numpy.typing.NDArray[numpy.int8]) → numpy.typing.NDArray[numpy.int8][source]

Return indices of faults that are not detectable by the given stabilizers.

Parameters:

stabs – A 2D numpy array where each row is a stabilizer generator.

Returns:

Indices of faults that commute with all generators.

get_undetectable_faults(stabs: numpy.typing.NDArray[numpy.int8]) → numpy.typing.NDArray[numpy.int8][source]

Return faults that are not detectable by the given stabilizers.

Parameters:

stabs – A 2D numpy array where each row is a stabilizer generator.

Returns:

A 2D numpy array where each row is a fault that commutes with all generators.

remove_undetectable_faults(stabs: numpy.typing.NDArray[numpy.int8]) → None[source]

Remove all faults that are not detectable by the given stabilizers.

Parameters:

stabs – A 2D numpy array where each row is a stabilizer generator.

filter_faults(pred: Callable[[numpy.typing.NDArray[numpy.int8]], bool], inplace: bool = True) → PureFaultSet[source]

Filter faults by removing faults for which the given predicate is False.

This method modifies the fault set in place, removing faults that do not satisfy the predicate.

Parameters:
  • pred – A callable that takes a fault (1D numpy array) and returns True if the fault should be kept.

  • inplace – If True, modifies the current fault set. If False, returns a new PureFaultSet with filtered faults.

permute_qubits(permutation: numpy.typing.NDArray[numpy.int8] | list[int], inplace: bool = True) → PureFaultSet[source]

Permute the qubits in the fault set according to a given permutation.

Parameters:
  • permutation – A 1D numpy array or list representing the new order of qubits.

  • inplace – If True, modifies the current fault set. If False, returns a new PureFaultSet with permuted faults.

Returns:

A new PureFaultSet with permuted faults if inplace is False.

coset_leader(fault: numpy.typing.NDArray[numpy.int8], generators: numpy.typing.NDArray[numpy.int8]) → numpy.typing.NDArray[numpy.int8][source]

Compute the coset leader of a fault given a set of stabilizer generators.

product_fault_set(lhs: PureFaultSet, rhs: PureFaultSet) → PureFaultSet[source]

Generate fault set by forming the product of all faults of two fault sets.

Parameters:
  • lhs – The first fault set.

  • rhs – The second fault set.

Returns:

Fault set containing all products of faults of lhs and rhs.

stabilizer_equivalent(lhs: PureFaultSet, rhs: PureFaultSet, stabs: numpy.typing.NDArray[numpy.int8] | None) → bool[source]

Check if two fault sets are equivalent with respect to a stabilizer group.

Parameters:
  • lhs – The first fault set.

  • rhs – The second fault set.

  • stabs (optional) – A 2D numpy array where each row is a stabilizer generator.

Returns:

True if the two fault sets are equivalent with respect to the stabilizer group, False otherwise.

t_distinct(fs1: PureFaultSet, fs2: PureFaultSet, t: int, stabs: numpy.typing.NDArray[numpy.int8] | None = None) → bool[source]

Check if two fault sets are t-distinct.

Two fault sets are t-distinct if there is no product of at most i faults from fs1 that is equivalent to a product of at most j faults in fs2 sucht that i+j<=t and the weight of either product is greater than i+j. If stabilizers are given the minimal weight is computed with respect to the stabilizer group generated by stabs.

Parameters:
  • fs1 – The first fault set.

  • fs2 – The second fault set.

  • t – The maximum number of faults to consider in the product.

  • stabs – The stabilizer generators used to determine the minimal weight of a fault.

Returns:

True if the fault sets are t-distinct, False otherwise.