qml.ops.one_qubit_decomposition¶
- one_qubit_decomposition(U, wire, rotations='ZYZ', return_global_phase=False)[source]¶
Decompose a one-qubit unitary \(U\) in terms of elementary operations.
Any one qubit unitary operation can be implemented up to a global phase by composing RX, RY, and RZ gates. Currently supported values for
rotations
are “rot”, “ZYZ”, “XYX”, “XZX”, and “ZXZ”.- Parameters:
U (tensor) – A \(2 \times 2\) unitary matrix.
wire (Union[Wires, Sequence[int] or int]) – The wire on which to apply the operation.
rotations (str) – A string defining the sequence of rotations to decompose \(U\) into.
return_global_phase (bool) – Whether to return the global phase as a
qml.GlobalPhase(-alpha)
as the last element of the returned list of operations.
- Returns:
- A list of gates which when applied in the order of appearance in the list
is equivalent to the unitary \(U\) up to a global phase. If
return_global_phase=True
, the global phase is returned as the last element of the list.
- Return type:
list[Operation]
Example
>>> from pprint import pprint >>> U = np.array([[1, 1], [1, -1]]) / np.sqrt(2) # Hadamard >>> decomp = qml.ops.one_qubit_decomposition(U, 0, rotations='ZYZ', return_global_phase=True) >>> pprint(decomp) [RZ(np.float64(3.14159...), wires=[0]), RY(np.float64(1.57079...), wires=[0]), RZ(np.float64(0.0), wires=[0]), GlobalPhase(np.float64(-1.57079...), wires=[])] >>> decomp = qml.ops.one_qubit_decomposition(U, 0, rotations='XZX', return_global_phase=True) >>> pprint(decomp) [RX(np.float64(1.57079...), wires=[0]), RZ(np.float64(1.57079...), wires=[0]), RX(np.float64(1.57079...), wires=[0]), GlobalPhase(np.float64(-1.57079...), wires=[])]