qml.transforms.combine_global_phases¶
- combine_global_phases(tape)[source]¶
Combine all
qml.GlobalPhase
gates into a singleqml.GlobalPhase
operation.This transform returns a new circuit where all
qml.GlobalPhase
gates in the original circuit (if exists) are removed, and a newqml.GlobalPhase
is added at the end of the list of operations with its phase being a total global phase computed as the algebraic sum of all global phases in the original circuit.- Parameters
tape (QNode or QuantumScript or Callable) – the input circuit to be transformed.
- Returns
the transformed circuit as described in
qml.transform
.- Return type
qnode (QNode) or quantum function (Callable) or tuple[List[QuantumScript], function]
Example
Suppose we want to combine all the global phase gates in a given quantum circuit. The
combine_global_phases
transform can be used to do this as follows:dev = qml.device("default.qubit", wires=3) @qml.transforms.combine_global_phases @qml.qnode(dev) def circuit(): qml.GlobalPhase(0.3, wires=0) qml.PauliY(wires=0) qml.Hadamard(wires=1) qml.CNOT(wires=(1,2)) qml.GlobalPhase(0.46, wires=2) return qml.expval(qml.X(0) @ qml.Z(1))
To check the result, let’s print out the circuit:
>>> print(qml.draw(circuit)()) 0: ──Y─────GlobalPhase(0.76)─┤ ╭<X@Z> 1: ──H─╭●──GlobalPhase(0.76)─┤ ╰<X@Z> 2: ────╰X──GlobalPhase(0.76)─┤