qp.decomposition.DecompCollection¶
- class DecompCollection(decomps=None)[source]¶
Bases:
objectAn ordered, name-addressable collection of
DecompositionRuleobjects.A
DecompCollectionis exclusively returned bylist_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 viaregister_resources()withname="...").Individual rules can be accessed by integer index or by string name. The collection supports
len(), iteration, membership checks (by name or byDecompositionRuleinstance),copy(),append(),extend(),+, and+=. Duplicate names within a collection are rejected with aValueError.Important
A
DecompCollectionreturned bylist_decomps()is a copy of the internally registered rules. Mutating it (e.g. withappend()orextend()) does not update the global decomposition registry. Useadd_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']
Methods