qml.dynamic_one_shot

dynamic_one_shot(tape, **kwargs)[source]

Transform a QNode to into several one-shot tapes to support dynamic circuit execution.

Parameters

tape (QNode or QuantumTape or Callable) – a quantum circuit to add a batch dimension to.

Returns

The transformed circuit as described in qml.transform. This circuit will provide the results of a dynamic execution.

Return type

qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]

Example

Consider the following circuit:

dev = qml.device("default.qubit", shots=100)
params = np.pi / 4 * np.ones(2)

@qml.dynamic_one_shot
@qml.qnode(dev)
def func(x, y):
    qml.RX(x, wires=0)
    m0 = qml.measure(0)
    qml.cond(m0, qml.RY)(y, wires=1)
    return qml.expval(op=m0)

The qml.dynamic_one_shot decorator prompts the QNode to perform a hundred one-shot calculations, where in each calculation the qml.measure operations dynamically measures the 0-wire and collapse the state vector stochastically. This transforms contrasts with qml.defer_measurements, which instead introduces an extra wire for each mid-circuit measurement. The qml.dynamic_one_shot transform is favorable in the few-shots several-mid-circuit-measurement limit, whereas qml.defer_measurements is favorable in the opposite limit.

Contents

Using PennyLane

Release news

Development

API

Internals