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, optionally set using the name argument of register_resources().

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: 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']

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.