qp.decomposition.DecompCollection

class DecompCollection(decomps=None)[source]

Bases: object

An ordered, name-addressable collection of DecompositionRule objects.

A DecompCollection is exclusively returned by list_decomps(), which retrieves all registered decomposition rules for a given operator. Each rule in the collection has a unique name (derived from the decorated function name by default, or explicitly set via register_resources() with name="...").

Individual rules can be accessed by integer index or by string name. The collection supports len(), iteration, membership checks (by name or by DecompositionRule instance), copy(), append(), extend(), +, and +=. Duplicate names within a collection are rejected with a ValueError.

Important

A DecompCollection returned by list_decomps() is a copy of the internally registered rules. Mutating it (e.g. with append() or extend()) does not update the global decomposition registry. Use add_decomps() to register new decomposition rules globally.

Examples

Retrieve and explore decomposition rules for an operator:

>>> decomps = qp.list_decomps(qp.CRX)
>>> len(decomps)
4
>>> print(decomps)
Available Decomposition Rules:
0: _crx_to_rx_cz
1: _crx_to_rz_ry
2: _crx_to_h_crz
3: _crx_to_ppr

Access rules by index or by name:

>>> decomps[0]
DecompositionRule(name=_crx_to_rx_cz)
>>> decomps["_crx_to_ppr"]
DecompositionRule(name=_crx_to_ppr)

Check membership:

>>> "_crx_to_ppr" in decomps
True

Iterate through rule names:

>>> [rule.name for rule in decomps]
['_crx_to_rx_cz', '_crx_to_rz_ry', '_crx_to_h_crz', '_crx_to_ppr']

append(rule)

Add a decomposition rule to the collection.

copy()

Return a copy of the DecompCollection.

extend(rules)

Add a sequence of decomposition rules to the collection.

append(rule)[source]

Add a decomposition rule to the collection.

copy()[source]

Return a copy of the DecompCollection.

extend(rules)[source]

Add a sequence of decomposition rules to the collection.