mqt.qecc.circuit_synthesis.exact.gate_operations

Gate operation abstractions for exact synthesis encoding.

Classes

SymbolicGateOperation

Abstract base class for gate operations in symbolic encoding.

HGate

Hadamard gate operation.

SGate

S (phase) gate operation.

SqrtXGate

√X gate (SX = HSH) operation.

CNOTGate

CNOT gate operation.

CZGate

CZ gate operation.

IdentityGate

Identity (no-op) gate operation.

GateRegistry

Registry of available gate operations for synthesis.

Functions

get_standard_clifford_gate_set() → dict[str, type[SymbolicGateOperation]]

Get the standard Clifford gate set {H, S, CX, ID}.

get_clifford_sx_gate_set() → dict[str, type[SymbolicGateOperation]]

Get the Clifford gate set {H, SX, CX, ID}.

get_clifford_cz_gate_set() → dict[str, type[SymbolicGateOperation]]

Get the extended Clifford gate set {H, S, CX, CZ, ID}.

get_clifford_extended_gate_set() → dict[str, type[SymbolicGateOperation]]

Get the full extended Clifford gate set {H, S, SX, CX, CZ, ID}.

get_standard_css_gate_set() → dict[str, type[SymbolicGateOperation]]

Get the standard CSS gate set {CX, ID}.

Module Contents

class SymbolicGateOperation[source]

Bases: abc.ABC

Abstract base class for gate operations in symbolic encoding.

Class attributes (must be set on every concrete subclass):

IS_TWO_QUBIT: True for two-qubit gates (CX, CZ, …). IS_SYMMETRIC: True when the gate treats both qubits symmetrically so

that only unordered pairs need to be enumerated (e.g. CZ). Ignored for single-qubit gates.

IS_SELF_INVERSE: True when applying the gate twice yields the identity

in the binary stabilizer tableau (ignoring global phases). This holds for H, CX, CZ, and also for S and SX: although S and SX have order 4 as unitaries, their binary tableau actions square to the identity (S: z↦x⊕z twice gives z; SX: x↦x⊕z twice gives x). Used by symmetry-breaking to prune adjacent identical gates.

classmethod from_qubits(q1: int, q2: int, /) → SymbolicGateOperation[source]
Abstractmethod:

Instantiate the gate from up to two qubit indices.

Single-qubit gates use q1 and ignore q2. Two-qubit gates use both. This uniform interface allows extraction code to create gate instances without knowing the concrete arity.

Parameters:
  • q1 – First (or only) qubit index.

  • q2 – Second qubit index (ignored for single-qubit gates).

Returns:

A concrete gate instance.

abstractmethod clifford_tableau_effect(tableau_x_curr: numpy.typing.NDArray[object_], tableau_z_curr: numpy.typing.NDArray[object_], tableau_x_next: numpy.typing.NDArray[object_], tableau_z_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

Return the constraint relating the next Clifford tableau to the current one.

The returned expression fixes only the columns this gate acts on; the caller guards it with the gate-selection condition, e.g. solver.add(Implies(selected, effect)). This is the single place a gate’s tableau action is defined — encoders and tests both consume it, so adding a new gate means implementing only this class.

Parameters:
  • tableau_x_curr – Current X part of tableau.

  • tableau_z_curr – Current Z part of tableau.

  • tableau_x_next – Next X part of tableau.

  • tableau_z_next – Next Z part of tableau.

Returns:

A Boolean expression constraining tableau_*_next given tableau_*_curr.

abstractmethod css_matrix_effect(matrix_curr: numpy.typing.NDArray[object_], matrix_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

Return the constraint relating the next CSS check matrix to the current one.

Parameters:
  • matrix_curr – Current CSS matrix.

  • matrix_next – Next CSS matrix.

Returns:

A Boolean expression constraining matrix_next given matrix_curr.

abstractmethod to_stim_gate() → tuple[str, list[int]][source]

Convert to Stim gate representation.

Returns:

Tuple of (gate_name, qubit_targets).

abstractmethod inverse_stim_gate() → tuple[str, list[int]][source]

Get the inverse gate in Stim representation.

Returns:

Tuple of (gate_name, qubit_targets) for the inverse.

abstractmethod qubits() → set[int][source]

Get qubits involved in this operation.

Returns:

Set of qubit indices.

class HGate(qubit: int)[source]

Bases: SymbolicGateOperation

Hadamard gate operation.

classmethod from_qubits(q1: int, _q2: int) → HGate[source]

Instantiate H gate from qubit indices (_q2 ignored).

clifford_tableau_effect(tableau_x_curr: numpy.typing.NDArray[object_], tableau_z_curr: numpy.typing.NDArray[object_], tableau_x_next: numpy.typing.NDArray[object_], tableau_z_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

H gate: swap X and Z columns of the target qubit.

css_matrix_effect(matrix_curr: numpy.typing.NDArray[object_], matrix_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

H gate not applicable to CSS encoding (requires full Clifford).

to_stim_gate() → tuple[str, list[int]][source]

Convert to Stim gate.

inverse_stim_gate() → tuple[str, list[int]][source]

H is self-inverse.

qubits() → set[int][source]

Get qubits involved.

class SGate(qubit: int)[source]

Bases: SymbolicGateOperation

S (phase) gate operation.

classmethod from_qubits(q1: int, _q2: int) → SGate[source]

Instantiate S gate from qubit indices (_q2 ignored).

clifford_tableau_effect(tableau_x_curr: numpy.typing.NDArray[object_], tableau_z_curr: numpy.typing.NDArray[object_], tableau_x_next: numpy.typing.NDArray[object_], tableau_z_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

S gate: Z <- Z ⊕ X on the target qubit.

css_matrix_effect(matrix_curr: numpy.typing.NDArray[object_], matrix_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

S gate not applicable to CSS encoding.

to_stim_gate() → tuple[str, list[int]][source]

Convert to Stim gate.

inverse_stim_gate() → tuple[str, list[int]][source]

Inverse is S_DAG.

qubits() → set[int][source]

Get qubits involved.

class SqrtXGate(qubit: int)[source]

Bases: SymbolicGateOperation

√X gate (SX = HSH) operation.

Binary tableau action: X_out = X ⊕ Z, Z_out = Z. Self-inverse in the binary tableau: (SX)^2 = X as a unitary, but the binary tableau action squares to the identity (x⊕z)⊕z = x.

classmethod from_qubits(q1: int, _q2: int) → SqrtXGate[source]

Instantiate SX gate from qubit indices (_q2 ignored).

clifford_tableau_effect(tableau_x_curr: numpy.typing.NDArray[object_], tableau_z_curr: numpy.typing.NDArray[object_], tableau_x_next: numpy.typing.NDArray[object_], tableau_z_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

SX gate: X_out = X ⊕ Z, Z_out = Z on the target qubit.

css_matrix_effect(matrix_curr: numpy.typing.NDArray[object_], matrix_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

SX gate not applicable to CSS encoding.

to_stim_gate() → tuple[str, list[int]][source]

Convert to Stim gate.

inverse_stim_gate() → tuple[str, list[int]][source]

Inverse is SQRT_X_DAG.

qubits() → set[int][source]

Get qubits involved.

class CNOTGate(control: int, target: int)[source]

Bases: SymbolicGateOperation

CNOT gate operation.

classmethod from_qubits(q1: int, q2: int) → CNOTGate[source]

Instantiate CNOT gate from qubit indices.

clifford_tableau_effect(tableau_x_curr: numpy.typing.NDArray[object_], tableau_z_curr: numpy.typing.NDArray[object_], tableau_x_next: numpy.typing.NDArray[object_], tableau_z_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

CNOT gate: X[:,t] <- X[:,t] ⊕ X[:,c], Z[:,c] <- Z[:,c] ⊕ Z[:,t].

css_matrix_effect(matrix_curr: numpy.typing.NDArray[object_], matrix_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

CNOT gate for CSS: M[:,t] <- M[:,t] ⊕ M[:,c] (control unchanged).

to_stim_gate() → tuple[str, list[int]][source]

Convert to Stim gate.

inverse_stim_gate() → tuple[str, list[int]][source]

CNOT is self-inverse.

qubits() → set[int][source]

Get qubits involved.

class CZGate(qubit1: int, qubit2: int)[source]

Bases: SymbolicGateOperation

CZ gate operation.

classmethod from_qubits(q1: int, q2: int) → CZGate[source]

Instantiate CZ gate from qubit indices.

clifford_tableau_effect(tableau_x_curr: numpy.typing.NDArray[object_], tableau_z_curr: numpy.typing.NDArray[object_], tableau_x_next: numpy.typing.NDArray[object_], tableau_z_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

CZ gate: Z[:,i] ^= X[:,j], Z[:,j] ^= X[:,i], X columns unchanged.

css_matrix_effect(matrix_curr: numpy.typing.NDArray[object_], matrix_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

CZ gate not applicable to CSS encoding.

to_stim_gate() → tuple[str, list[int]][source]

Convert to Stim gate.

inverse_stim_gate() → tuple[str, list[int]][source]

CZ is self-inverse.

qubits() → set[int][source]

Get qubits involved.

class IdentityGate(qubit: int)[source]

Bases: SymbolicGateOperation

Identity (no-op) gate operation.

classmethod from_qubits(q1: int, _q2: int) → IdentityGate[source]

Instantiate identity gate from qubit indices (_q2 ignored).

clifford_tableau_effect(tableau_x_curr: numpy.typing.NDArray[object_], tableau_z_curr: numpy.typing.NDArray[object_], tableau_x_next: numpy.typing.NDArray[object_], tableau_z_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

Identity: preserve the target qubit’s columns.

css_matrix_effect(matrix_curr: numpy.typing.NDArray[object_], matrix_next: numpy.typing.NDArray[object_]) → z3.BoolRef[source]

Identity: preserve the target qubit’s column.

to_stim_gate() → tuple[str, list[int]][source]

Convert to Stim gate.

inverse_stim_gate() → tuple[str, list[int]][source]

Identity is self-inverse.

qubits() → set[int][source]

Get qubits involved.

class GateRegistry[source]

Registry of available gate operations for synthesis.

register_clifford_gate(name: str, gate_class: type[SymbolicGateOperation]) → None[source]

Register a gate for Clifford synthesis.

Parameters:
  • name – Gate identifier (e.g., ‘H’, ‘S’, ‘CX’).

  • gate_class – Gate operation class.

register_css_gate(name: str, gate_class: type[SymbolicGateOperation]) → None[source]

Register a gate for CSS synthesis.

Parameters:
  • name – Gate identifier (e.g., ‘CX’).

  • gate_class – Gate operation class.

get_clifford_gates() → dict[str, type[SymbolicGateOperation]][source]

Get all registered Clifford gates.

Returns:

Dictionary mapping gate names to gate classes.

get_css_gates() → dict[str, type[SymbolicGateOperation]][source]

Get all registered CSS gates.

Returns:

Dictionary mapping gate names to gate classes.

create_gate(name: str, *args: int, for_css: bool = False) → SymbolicGateOperation[source]

Create a gate instance.

Parameters:
  • name – Gate identifier.

  • *args – Arguments for gate constructor.

  • for_css – Whether this is for CSS encoding.

Returns:

Gate instance.

Raises:

KeyError – If gate not registered.

get_standard_clifford_gate_set() → dict[str, type[SymbolicGateOperation]][source]

Get the standard Clifford gate set {H, S, CX, ID}.

Returns:

Dictionary mapping gate names to gate classes.

get_clifford_sx_gate_set() → dict[str, type[SymbolicGateOperation]][source]

Get the Clifford gate set {H, SX, CX, ID}.

Replaces S with the √X (SX = HSH) gate.

Returns:

Dictionary mapping gate names to gate classes.

get_clifford_cz_gate_set() → dict[str, type[SymbolicGateOperation]][source]

Get the extended Clifford gate set {H, S, CX, CZ, ID}.

Returns:

Dictionary mapping gate names to gate classes.

get_clifford_extended_gate_set() → dict[str, type[SymbolicGateOperation]][source]

Get the full extended Clifford gate set {H, S, SX, CX, CZ, ID}.

Combines CZ and SX extensions on top of the standard {H, S, CX} basis.

Returns:

Dictionary mapping gate names to gate classes.

get_standard_css_gate_set() → dict[str, type[SymbolicGateOperation]][source]

Get the standard CSS gate set {CX, ID}.

Returns:

Dictionary mapping gate names to gate classes.