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 theqml.measure
operations dynamically measures the 0-wire and collapse the state vector stochastically. This transforms contrasts withqml.defer_measurements
, which instead introduces an extra wire for each mid-circuit measurement. Theqml.dynamic_one_shot
transform is favorable in the few-shots several-mid-circuit-measurement limit, whereasqml.defer_measurements
is favorable in the opposite limit.