qp.decomposition.all_decomps

all_decomps(op, skip_ops=None)[source]

Collect all decomposition rules downstream of an Operator.

Parameters:
  • op (Operator2) – an operator that we will want to decompose:

  • skip_ops (set[Operator2] | None) – abstract operators that should not be included in the results

Returns:

A map from abstract operators to their applicable rules

Return type:

dict[Operator2, list[DecompositionRule]]

>>> from pennylane.typing import Wire, Float
>>> rules_map = all_decomps(qp.X(0))
>>> len(rules_map)
80
>>> rules_map[qp.RX(Float, Wire[1])]
[DecompositionRule(name=to_rot),
 DecompositionRule(name=to_rz_ry),
 DecompositionRule(name=to_paulirot),
 DecompositionRule(name=to_ry_cliff),
 DecompositionRule(name=to_rz_cliff)]

The keys from a rule map can be reused on successive calls to avoid recollecting the same nodes. Note that if an op is skipped, it’s children will also not be added.

>>> qp.decomposition.all_decomps(qp.Y(0), skip_ops=rules_map)
{}