qp.exclude_decomps¶
- exclude_decomps(op, *names)[source]¶
Excludes decomposition rules of an operator by name.
Excluded rules are not removed from the registry. They are hidden from
list_decomps(), and are therefore not considered by the graph-based decomposition system. When used as a context manager, the rules are excluded only within the context. This function is thread-safe.- Parameters:
op (type or Operator or str) – the operator type to exclude decomposition rules for. For symbolic operators, use strings like
"Adjoint(RY)","C(RX)", etc.*names (str) – the names of the decomposition rules to exclude. Each name must be one of the rules listed by
list_decomps()forop. To exclude rules that are generated for specific operator instances, pass an instance asop.
- Raises:
TypeError – if a name is not a string, e.g., a
DecompositionRuleinstance.ValueError – if no decomposition rule with a given name exists for
op.
See also
Example
When used as a context manager, the rules are excluded only within the context:
>>> with qp.exclude_decomps(qp.CRX, "_crx_to_ppr", "_crx_to_h_crz"): ... print(qp.list_decomps(qp.CRX)) Available Decomposition Rules: 0: _crx_to_rx_cz 1: _crx_to_rz_ry >>> print(qp.list_decomps(qp.CRX)) Available Decomposition Rules: 0: _crx_to_rx_cz 1: _crx_to_rz_ry 2: _crx_to_h_crz 3: _crx_to_ppr
Otherwise, the rules remain excluded for the rest of the session, or until the enclosing
local_decomps()context exits:with qp.decomposition.local_decomps(): qp.exclude_decomps(qp.CRX, "_crx_to_ppr") assert "_crx_to_ppr" not in qp.list_decomps(qp.CRX) assert "_crx_to_ppr" in qp.list_decomps(qp.CRX)