qp.testing.decomp_rule_to_tape¶
- decomp_rule_to_tape(op, rule)[source]¶
Apply a decomposition rule to an operator and record the result as a tape.
If program capture is enabled, the rule is captured and the tape is extracted from the resulting plxpr with
plxpr_to_tape(). Otherwise, the rule is called within a queuing context, and the queued operations are returned.- Parameters:
op (Operator) – the operator to decompose
rule (DecompositionRule) – a decomposition rule for
op
- Returns:
a tape containing the operations produced by the rule
- Return type:
Example
@qp.register_resources({qp.H: 2, qp.CZ: 1}, name="cnot_to_cz") def cnot_to_cz(wires): qp.H(wires[1]) qp.CZ(wires) qp.H(wires[1])
>>> qp.testing.decomp_rule_to_tape(qp.CNOT([0, 1]), cnot_to_cz).operations [H(1), CZ(wires=[0, 1]), H(1)]