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×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
>>> U = np.array([[1, 1], [1, -1]]) / np.sqrt(2) # Hadamard >>> qml.ops.one_qubit_decomposition(U, 0, rotations='ZYZ', return_global_phase=True) [RZ(3.1415926535897927, wires=[0]), RY(1.5707963267948963, wires=[0]), RZ(0.0, wires=[0]), GlobalPhase(-1.5707963267948966, wires=[])] >>> qml.ops.one_qubit_decomposition(U, 0, rotations='XZX', return_global_phase=True) [RX(1.5707963267948966, wires=[0]), RZ(1.5707963267948968, wires=[0]), RX(1.5707963267948966, wires=[0]), GlobalPhase(-1.5707963267948966, wires=[])]