mimiqcircuits.decomposition.rules.canonical¶
Canonical rewrite rule for decomposing operations to GateU and GateCX.
Classes
Rewrite rule that applies the built-in decomposition of each operation. |
- class CanonicalRewrite[source]¶
Bases:
RewriteRuleRewrite rule that applies the built-in decomposition of each operation.
Every operation class defines one decomposition step in terms of simpler operations; this rule applies it. Repeated, the steps end at
GateU,GateCXand the non-unitary primitives, which is whatCanonicalBasisdoes. One step can stop earlier:GateCCX, for example, becomesGateH,GateT,GateTDGandGateCX.It is the default rule of
decompose_step()and the fallback of the other bases.Examples
>>> from mimiqcircuits import * >>> rule = CanonicalRewrite() >>> # H has a built-in decomposition into GateU >>> rule.matches(GateH()) True >>> rule.decompose_step(GateH(), [0], [], []) 1-qubit circuit with 1 instruction: └── U((1/2)*pi, 0, pi, 0.0) @ q[0] >>> # GateU is a primitive, so there is nothing to rewrite >>> rule.matches(GateU(0.1, 0.2, 0.3)) False
- matches(op)[source]¶
Check whether an operation has a built-in decomposition.
Matches every operation whose
supports_canonical_rewrite()is true. The answer does not depend on any basis: an operation thatCanonicalBasiskeeps terminal (such asResetX) still matches, so other bases can expand it. Primitives without a decomposition (GateU,GateCX,Measure,Reset,Barrier, …) do not match.
- decompose_step(op, qubits, bits, zvars)[source]¶
Apply one step of the built-in decomposition of an operation.
No check is made that
matches()acceptsop. A primitive returns a circuit holding just itself.- Parameters:
- Returns:
A new
Circuitwith the decomposition.- Return type:
- decompose_step_ctx(op, qubits, bits, zvars, ctx)[source]¶
Apply this rule with a
DecompositionContext.Rules that use the context, for example to borrow qubits, override this method. The default drops the context and calls
decompose_step().