mimiqcircuits.decomposition.rules.canonical

Canonical rewrite rule for decomposing operations to GateU and GateCX.

Classes

CanonicalRewrite()

Rewrite rule that decomposes operations using their built-in decomposition.

class mimiqcircuits.decomposition.rules.canonical.CanonicalRewrite[source]

Bases: RewriteRule

Rewrite rule that decomposes operations using their built-in decomposition.

This rule delegates to each operation’s _decompose method, which typically reduces gates to a minimal set of primitives (GateU, GateCX, etc.).

The canonical decomposition is the default decomposition defined by each gate class. Most gates decompose down to GateU (arbitrary single-qubit) and GateCX (two-qubit entangling gate).

Example

>>> from mimiqcircuits import GateH
>>> from mimiqcircuits.decomposition import CanonicalRewrite
>>> rule = CanonicalRewrite()
>>> rule.matches(GateH())
True
>>> circ = rule.decompose_step(GateH(), [0], [], [])
>>> print(circ)
1-qubit circuit with 1 instruction:
└── U((1/2)*pi, 0, pi, 0.0) @ q[0]
matches(op)[source]

Check if this rule can decompose the operation.

Matches every operation that has a canonical decomposition, that is whose supports_canonical_rewrite() is true. The answer does not depend on any basis: an operation that CanonicalBasis keeps terminal (such as ResetX) still matches, so other bases can expand it. Primitives without a decomposition (GateU, GateCX, Measure, Reset, Barrier, …) do not match.

Parameters:

op (Operation) – The operation to check.

Returns:

True if the operation should be rewritten by canonical decomposition.

Return type:

bool

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

Decompose the operation using its built-in decomposition.

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.

Return type:

Circuit