mimiqcircuits.decomposition.basis.rule_basis¶
RuleBasis: Wrapper to use a RewriteRule as a DecompositionBasis.
Classes
|
Decomposition basis that applies one rewrite rule until it no longer matches. |
- class RuleBasis(rule)[source]¶
Bases:
DecompositionBasisDecomposition basis that applies one rewrite rule until it no longer matches.
An operation is terminal when the rule does not match it. When the rule does not match an
IfStatement, it is applied to the body, which stays conditional.decompose()andeachdecomposed()wrap a rule passed in place of a basis in aRuleBasis.- Parameters:
rule (RewriteRule) – The rewrite rule to apply.
Examples
>>> from mimiqcircuits import * >>> from symengine import pi >>> c = Circuit() >>> c.push(GateH(), 0) 1-qubit circuit with 1 instruction: └── H @ q[0] >>> c.push(GateRX(pi/2), 0) 1-qubit circuit with 2 instructions: ├── H @ q[0] └── RX((1/2)*pi) @ q[0] >>> # rewrite every X and Y rotation into Z rotations; H is kept >>> decompose(c, RuleBasis(ToZRotationRewrite())) 1-qubit circuit with 4 instructions: ├── H @ q[0] ├── H @ q[0] ├── RZ((1/2)*pi) @ q[0] └── H @ q[0]
- decompose(op, qubits, bits, zvars)[source]¶
Apply the rule once to an operation.
- Parameters:
- Returns:
A new
Circuitwith the rewrite. For anIfStatementthe rule does not match, the rewrite of its body, with each instruction made conditional.- Raises:
DecompositionError – If the rule cannot rewrite
op.- Return type:
- decompose_ctx(op, qubits, bits, zvars, ctx)[source]¶
Apply the rule once, with a context, as
decompose()does.