mimiqcircuits.decomposition.abstract

Abstract base classes for the decomposition framework.

This module defines the core abstractions for quantum circuit decomposition:

Classes

DecompositionBasis()

Abstract base class for decomposition targets.

RewriteRule()

Abstract base class for single-step rewrite rules.

Exceptions

DecompositionError

Raised when an operation cannot be decomposed.

class mimiqcircuits.decomposition.abstract.RewriteRule[source]

Bases: ABC

Abstract base class for single-step rewrite rules.

A RewriteRule defines how to transform an operation into a sequence of simpler operations, but not when to stop. For recursive decomposition to a target set of operations, see DecompositionBasis.

Subclasses must implement:

Example

>>> class MyRewrite(RewriteRule):
...     def matches(self, op: Operation) -> bool:
...         return isinstance(op, GateToffoli)
...
...     def decompose_step(self, op, qubits, bits, zvars):
...         from mimiqcircuits import Circuit
...         circ = Circuit()
...         # ... decomposition logic ...
...         return circ
abstract matches(op)[source]

Check if this rule can transform the given operation.

Parameters:

op (Operation) – The operation to check.

Returns:

True if this rule can decompose the operation.

Return type:

bool

abstract decompose_step(op, qubits, bits, zvars)[source]

Apply this rule to transform an operation.

This method should only be called if matches() returns True.

Parameters:
  • op (Operation) – The operation to transform.

  • qubits (Sequence[int]) – Qubit indices for the operation.

  • bits (Sequence[int]) – Classical bit indices for the operation.

  • zvars (Sequence[int]) – Z-variable indices for the operation.

Returns:

A Circuit containing the decomposed instructions.

Raises:

DecompositionError – If the operation cannot be decomposed.

Return type:

Circuit

class mimiqcircuits.decomposition.abstract.DecompositionBasis[source]

Bases: ABC

Abstract base class for decomposition targets.

A DecompositionBasis combines two concerns:
  1. What is terminal: Operations that should not be decomposed further.

  2. How to decompose: The transformation logic for non-terminal operations.

Subclasses must implement:

Example

>>> class CliffordT(DecompositionBasis):
...     def isterminal(self, op: Operation) -> bool:
...         return isinstance(op, (GateH, GateS, GateT, GateCX))
...
...     def decompose(self, op, qubits, bits, zvars):
...         # Use a rewrite rule to decompose
...         return CanonicalRewrite().decompose_step(op, qubits, bits, zvars)
abstract isterminal(op)[source]

Check if an operation is terminal in this basis.

Terminal operations are not decomposed further - they represent the target instruction set that decomposition reduces circuits to.

Parameters:

op (Operation) – The operation to check.

Returns:

True if the operation is terminal.

Return type:

bool

abstract decompose(op, qubits, bits, zvars)[source]

Decompose a non-terminal operation.

This method should only be called for non-terminal operations (i.e., when isterminal() returns False).

Parameters:
  • op (Operation) – The operation to decompose.

  • qubits (Sequence[int]) – Qubit indices for the operation.

  • bits (Sequence[int]) – Classical bit indices for the operation.

  • zvars (Sequence[int]) – Z-variable indices for the operation.

Returns:

A Circuit containing the decomposed instructions.

Raises:

DecompositionError – If the operation cannot be decomposed.

Return type:

Circuit

exception mimiqcircuits.decomposition.abstract.DecompositionError[source]

Bases: Exception

Raised when an operation cannot be decomposed.