qml.ops.op_math.ctrl_decomp_zyz

ctrl_decomp_zyz(target_operation, control_wires, work_wires=None)[source]

Decompose the controlled version of a target single-qubit operation

This function decomposes both single and multiple controlled single-qubit target operations using the decomposition defined in Lemma 4.3 and Lemma 5.1 for single controlled_wires, and Lemma 7.9 for multiple controlled_wires from Barenco et al. (1995).

Parameters
  • target_operation (Operator) – the target operation to decompose

  • control_wires (Wires) – the control wires of the operation.

Returns

the decomposed operations

Return type

list[Operation]

Raises

ValueError – if target_operation is not a single-qubit operation

Example

We can create a controlled operation using qml.ctrl, or by creating the decomposed controlled version of using qml.ctrl_decomp_zyz.

import pennylane as qml

dev = qml.device("default.qubit", wires=2)

@qml.qnode(dev)
def expected_circuit(op):
    qml.Hadamard(wires=0)
    qml.ctrl(op, [0])
    return qml.probs()

@qml.qnode(dev)
def decomp_circuit(op):
    qml.Hadamard(wires=0)
    qml.ops.ctrl_decomp_zyz(op, [0])
    return qml.probs()

Measurements on both circuits will give us the same results:

>>> op = qml.RX(0.123, wires=1)
>>> expected_circuit(op)
tensor([0.5       , 0.        , 0.49811126, 0.00188874], requires_grad=True)
>>> decomp_circuit(op)
tensor([0.5       , 0.        , 0.49811126, 0.00188874], requires_grad=True)