qp.decomposition.gate_set.GateSet¶
- class GateSet(gate_set, name='')[source]¶
Bases:
MappingStores the target gate set of a decomposition pass.
- Parameters:
gate_set (Iterable | Mapping) – the contents
name (str) – a shorthand to use in the str and repr
While the
decomposetransform can accept any iterable for it’sgate_setargument, theGateSetclass provides some helpful tools. This includes anameargument for improved inspection and condensed reprs, immutability for improved protection when used as a global variable, and conversion between class and string based representations of operators.We can create a gateset using both
Operatorsubclasses or strings, and use both classes and strings to check inclusion in the gateset>>> from pennylane.decomposition import GateSet >>> gateset = GateSet({"X", qp.RX, "Adjoint(RX)"}) >>> gateset GateSet({Adjoint(RX), PauliX, RX}) >>> qp.X in gateset True >>> "RX" in gateset True
We can also provide a
namefor improved inspection.>>> gateset_name = GateSet({qp.RX, qp.RY, qp.RZ}, name="Rotations") >>> print(gateset_name) Rotations >>> qp.decompose(gate_set=gateset_name) <decompose(gate_set=Rotations)>
Gate sets can be combined with
|:>>> gateset | {qp.RX, qp.RY, qp.RZ} GateSet({Adjoint(RX), PauliX, RX, RY, RZ})
Items can be removed with
-:>>> gateset - {qp.RX, qp.RY} GateSet({Adjoint(RX), PauliX}) >>> gateset - qp.RX GateSet({Adjoint(RX), PauliX}) >>> gateset - "RX" GateSet({Adjoint(RX), PauliX})
Weights can also be provided for use in calculating costs and choosing optimal decompositions:
>>> GateSet({qp.I: 0, qp.RX: 1, qp.CNOT: 3}) GateSet({Identity=0, RX, CNOT=3})
If not provided, weights default to
1:>>> dict(gateset) {'Adjoint(RX)': 1.0, 'PauliX': 1.0, 'RX': 1.0}
Methods