mimiqcircuits.decomposition.basis.rule_basis

RuleBasis: Wrapper to use a RewriteRule as a DecompositionBasis.

Classes

RuleBasis(rule)

A decomposition basis that recursively applies a single rewrite rule.

class mimiqcircuits.decomposition.basis.rule_basis.RuleBasis(rule)[source]

Bases: DecompositionBasis

A decomposition basis that recursively applies a single rewrite rule.

This allows any RewriteRule to be used directly as a decomposition basis. The rule is applied recursively until no more operations match.

An operation is terminal if the rule does not match it.

Parameters:

rule (RewriteRule) – The rewrite rule to apply.

Example

>>> from mimiqcircuits import Circuit, GateH
>>> from mimiqcircuits.decomposition import decompose, RuleBasis, ZYZRewrite
>>> c = Circuit()
>>> c.push(GateH(), 0)
1-qubit circuit with 1 instruction:
└── H @ q[0]

>>> # Decompose using ZYZ rewrite rule
>>> decomposed = decompose(c, RuleBasis(ZYZRewrite()))
rule: RewriteRule
isterminal(op)[source]

Check if the operation is terminal (rule does not match).

Parameters:

op (Operation) – The operation to check.

Returns:

True if the rule does not match this operation.

Return type:

bool

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

Apply the rewrite rule to decompose the operation.

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

__init__(rule)