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, optionally set using thenameargument ofregister_resources().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: to_rx_cz 1: to_rz_ry 2: to_h_crz 3: to_paulirot
Access rules by index or by name:
>>> decomps[0] DecompositionRule(name=to_rx_cz) >>> decomps["to_paulirot"] DecompositionRule(name=to_paulirot)
Check membership:
>>> "to_paulirot" in decomps True
Iterate through rule names:
>>> [rule.name for rule in decomps] ['to_rx_cz', 'to_rz_ry', 'to_h_crz', 'to_paulirot']
Methods