qp.decomposition.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() for op. To exclude rules that are generated for specific operator instances, pass an instance as op.

Raises:
  • TypeError – if a name is not a string, e.g., a DecompositionRule instance.

  • ValueError – if no decomposition rule with a given name exists for op.

Example

When used as a context manager, the rules are excluded only within the context:

>>> with qp.exclude_decomps(qp.CRX, "to_paulirot", "to_h_crz"):
...     print(qp.list_decomps(qp.CRX))
Available Decomposition Rules:
0: to_rx_cz
1: to_rz_ry
>>> print(qp.list_decomps(qp.CRX))
Available Decomposition Rules:
0: to_rx_cz
1: to_rz_ry
2: to_h_crz
3: to_paulirot

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, "to_paulirot")
    assert "to_paulirot" not in qp.list_decomps(qp.CRX)

assert "to_paulirot" in qp.list_decomps(qp.CRX)