mqt.qecc.circuit_synthesis.circuits

Circuit representations.

Classes

CliffordIsometry

Circuit representation of a Clifford encoding isometry.

CNOTCircuit

Represents a restricted quantum circuit composed of CNOT gates with optional qubit initialization.

Functions

compose_cnot_circuits(circ1, circ2[, wiring]) → tuple[CNOTCircuit, dict[int, int], dict[int, int]]

Compose two CNOT circuits.

compose(enc1, enc2[, wiring]) → CliffordIsometry

Compose two isometries to construct new isometry.

Module Contents

class CliffordIsometry[source]

Circuit representation of a Clifford encoding isometry.

get_logical_x(idx: int) → Pauli[source]

Get logical X operator of logical input at index.

Parameters:

idx – Index of the logical operator.

Returns:

Logical X operator.

get_logical_z(idx: int) → Pauli[source]

Get logical Z operator of logical input at index.

Parameters:

idx – Index of the logical operator.

Returns:

Logical Z operator.

get_logical(idx: int) → tuple[Pauli, Pauli][source]

Get logical operators of logical input at index.

Parameters:

idx – Index of the logical qubit.

Returns:

Logical X and Z operators.

get_all_logicals() → list[tuple[Pauli, Pauli]][source]

Get logical X- and Z-operators of all logical qubits.

logical_to_input_mapping(code: mqt.qecc.codes.StabilizerCode) → list[int] | None[source]

Get mapping from logical qubits of the code to input qubits of the isometry.

Parameters:

code – Stabilizer code.

Returns:

A list mapping logical qubits of the code to input qubits of the isometry, or None if no such mapping exists, i.e. the code does not match the code represented by the isometry.

get_code() → mqt.qecc.codes.StabilizerCode[source]

Get the stabilizer code defined by the isometry.

Returns:

Stabilizer code.

classmethod from_stim_circuit(circ: stim.Circuit) → CliffordIsometry[source]

Construct Clifford isometry from stim Circuit.

Parameters:

circ – Stim Circuit representing the isometry.

Returns:

Clifford isometry.

to_stim_circuit(with_resets: bool = True) → stim.Circuit[source]

Get the stim Circuit implementing the isometry.

Parameters:

with_resets – If set to True, includes resets in the |0> and |+> states for initialized qubits in the stim circuit.

Returns:

A stim.Circuit representation of the isometry.

outputs() → list[int][source]

Get output qubits.

inputs() → list[int][source]

Get input qubits.

draw(*args, **kwargs)[source]

Draw the circuit using Qiskit visualization tools.

Parameters:
  • *args – Positional arguments for the Qiskit draw method.

  • **kwargs – Keyword arguments for the Qiskit draw method.

to_qiskit_circuit(remove_resets: bool = True) → qiskit.QuantumCircuit[source]

Convert the isometry to a qiskit.QuantumCircuit.

Parameters:

remove_resets – If set to True, removes resets in the |0> state from the circuit.

Returns:

A qiskit.QuantumCircuit representation of the isometry.

num_inputs() → int[source]

Get number of logical inputs.

num_outputs() → int[source]

Get number of physical outputs.

initialize_qubit(qubit: int, basis: str) → None[source]

Initialize a qubit in the specified basis.

Parameters:
  • qubit – The qubit index to initialize.

  • basis – The basis for initialization (‘Z’ or ‘X’).

initialize_qubits(qubits: Iterable[int], basis: str) → None[source]

Initialize multiple qubits in the specified basis.

Parameters:
  • qubits – An iterable of qubit indices to initialize.

  • basis – The basis for initialization (‘Z’ or ‘X’).

get_plus_initialized() → list[int][source]

Get the list of qubits initialized in the |+> state.

Returns:

A list of qubit indices initialized in the |+> state.

get_zero_initialized() → list[int][source]

Get the list of qubits initialized in the |0> state.

Returns:

A list of qubit indices initialized in the |0> state.

get_uninitialized() → list[int][source]

Get the list of uninitialized qubits.

Returns:

A list of uninitialized qubits.

num_qubits() → int[source]

Get the total number of qubits in the isometry.

Returns:

The total number of qubits.

is_state() → bool[source]

Check if all qubits used in the circuit are initialized.

Returns:

True if all qubits are initialized, False otherwise.

num_two_qubit_gates() → int[source]

Get the number of two-qubit gates in the circuit.

Returns:

The number of two-qubit gates.

depth() → int[source]

Get the depth of the circuit.

Returns:

The depth of the circuit.

get_initialized() → dict[int, str][source]

Get the initialized qubits and their initialization basis.

Returns:

A dictionary mapping qubit indices to their initialization basis (‘Z’ or ‘X’).

is_initialized(qubit: int) → bool[source]

Check if a qubit is initialized.

Parameters:

qubit – The qubit index to check.

Returns:

True if the qubit is initialized, False otherwise.

class CNOTCircuit[source]

Bases: CliffordIsometry

Represents a restricted quantum circuit composed of CNOT gates with optional qubit initialization.

add_cnot(control: int, target: int) → None[source]

Add a single CNOT gate to the circuit.

Parameters:
  • control – The control qubit index.

  • target – The target qubit index.

add_cnots(cnot_pairs: Iterable[tuple[int, int]]) → None[source]

Add multiple CNOT gates to the circuit.

Parameters:

cnot_pairs – An iterable of (control, target) pairs.

to_stim_circuit(with_resets: bool = True) → stim.Circuit[source]

Convert the CNOT circuit to a stim.Circuit.

Parameters:

with_resets – If set to True, includes resets in the |0> and |+> states for initialized qubits in the stim circuit.

Returns:

A stim.Circuit representation of the CNOT circuit.

to_qiskit_circuit(remove_resets: bool = True) → qiskit.QuantumCircuit[source]

Convert the CNOT circuit to a qiskit.QuantumCircuit.

Parameters:

remove_resets – If set to True, removes resets in the |0> state from the circuit.

Returns:

A qiskit.QuantumCircuit representation of the CNOT circuit.

classmethod from_qiskit_circuit(circ: qiskit.QuantumCircuit, init_all: bool = False, initialized_qubits: Iterable[int] | None = None) → CNOTCircuit[source]

Construct a CNOT circuit from a qiskit QuantumCircuit object.

Generally, circ must contain only CNOT gates. The only exception to this is if initialized_qubits is given and the first gate on a qubit is a Hadamard gate. Then the qubit is initialized in |+>.

Parameters:
  • circ – The QuantumCircuit to construct the CNOT circuit from.

  • init_all – If set to True, all qubits are initialized.

  • initialized_qubits – Qubits to initialized.

Returns:

CNOTCircuit representation of the input circuit.

classmethod from_stim_circuit(circ: stim.Circuit) → CNOTCircuit[source]

Construct a CNOT circuit from a stim.Circuit object.

Generally, circ must contain only CNOT gates and initializations in the Z- or X-basis.

Parameters:

circ – The stim.Circuit to construct the CNOT circuit from.

Returns:

CNOTCircuit representation of the input circuit.

classmethod from_cnot_list(cnots: Iterable[tuple[int, int]], initialize_z: Iterable[int], initialize_x: Iterable[int], inputs: Iterable[int] | None = None) → CNOTCircuit[source]

Construct CNOT circuit from list of CNOTs.

Parameters:
  • cnots – Control, target pairs defining CNOT interactions.

  • initialize_z – Qubits that should be initialized in the Z-basis

  • initialize_x – Qubits that should be initialized in the X-basis

  • inputs – Explicit list of input qubits. If provided, these qubits will be marked as inputs even if they don’t appear in any CNOT gate.

Returns:

CNOT circuit

num_qubits() → int[source]

Return the number of qubits used in the circuit.

The number of qubits is determined by the highest index of any CNOT control or target qubit,

outputs() → list[int][source]

Get output qubits.

Returns:

List of output qubit indices (all qubits used in the circuit).

num_outputs() → int[source]

Get number of physical outputs.

Returns:

Number of output qubits.

draw(*args, **kwargs)[source]

Draw the circuit using Qiskit visualization tools.

Parameters:
  • *args – Positional arguments for the Qiskit draw method.

  • **kwargs – Keyword arguments for the Qiskit draw method.

get_code() → mqt.qecc.codes.CSSCode[source]

Get CSS code defined by the circuit.

A CNOT circuit with |0> and |+> initializations is the encoding isometry of some CSS code. The code is obtained by propagating the stabilizers of the initialized qubits to the end of the circuit. Qubits initialized in |+> define X-type stabilizers, while qubits initialized in |0> define Z-type stabilizers.

Returns:

A CSSCode object representing the code defined by the circuit.

num_cnots() → int[source]

Get number of CNOT gates in the circuit.

depth() → int[source]

Get the depth of the circuit.

Returns:

The depth of the circuit.

get_logical_xs_css() → dict[int, numpy.typing.NDArray[numpy.int8]][source]

Get logical X operators of the isometry.

Returns:

A dictionary mapping input qubits to their X-logicals.

get_logical_zs_css() → dict[int, numpy.typing.NDArray[numpy.int8]][source]

Get logical Z operators of the isometry.

Returns:

A dictionary mapping input qubits to their Z-logicals.

get_logicals_css() → dict[int, tuple[numpy.typing.NDArray[numpy.int8], numpy.typing.NDArray[numpy.int8]]][source]

Get logical operators of the isomety.

Returns:

A dictionary mapping input qubits to their X-logicals and Z-logicals.

copy() → CNOTCircuit[source]

Create a copy of the CNOT circuit.

Returns:

A new CNOTCircuit instance with the same CNOT gates and initializations.

relabel_qubits(mapping: dict[int, int]) → None[source]

Relabel the qubits in the circuit according to a given mapping.

Parameters:

mapping – A dictionary mapping old qubit indices to new qubit indices.

compose_cnot_circuits(circ1: CNOTCircuit, circ2: CNOTCircuit, wiring: dict[int, int] | None = None) → tuple[CNOTCircuit, dict[int, int], dict[int, int]][source]

Compose two CNOT circuits.

The circuits are composed only along the qubits that are connected by the wiring dict. All other qubits are assumed to be unconnected. If wire is None, then the circuits are simply vertically stacked.

Parameters:
  • circ1 – The first CNOT circuit.

  • circ2 – The second CNOT circuit.

  • wiring – Optional dict mapping outputs of circ1 to inputs of circ2.

Returns:

  • mapping1: Maps qubits of circ1 to the composed circuit.

  • mapping2: Maps qubits of circ2 to the composed circuit.

Return type:

A tuple containing the composed CNOT circuit and two mappings

compose(enc1: CliffordIsometry, enc2: CliffordIsometry, wiring: dict[int, int] | None = None) → CliffordIsometry[source]

Compose two isometries to construct new isometry.

Parameters:
  • enc1 – Left isometry (outputs serve as inputs to enc2)

  • enc2 – Right isometry

  • wiring – Optional dict mapping outputs of enc1 to inputs of enc2. If None, the inputs and outputs are connected in ascending order.

Returns:

Composed isometry.