qml.transforms.map_batch_transform¶
-
map_batch_transform
(transform, tapes)[source]¶ Map a batch transform over multiple tapes.
- Parameters
transform (batch_transform) – the batch transform to be mapped
tapes (Sequence[QuantumTape]) – The sequence of tapes the batch transform should be applied to. Each tape in the sequence is transformed by the batch transform.
Example
Consider the following tapes:
H = qml.PauliZ(0) @ qml.PauliZ(1) - qml.PauliX(0) ops1 = [ qml.RX(0.5, wires=0), qml.RY(0.1, wires=1), qml.CNOT(wires=(0,1)) ] measurements1 = [qml.expval(H)] tape1 = qml.tape.QuantumTape(ops1, measurements1) ops2 = [qml.Hadamard(0), qml.CRX(0.5, wires=(0,1)), qml.CNOT((0,1))] measurements2 = [qml.expval(H + 0.5 * qml.PauliY(0))] tape2 = qml.tape.QuantumTape(ops2, measurements2)
We can use
map_batch_transform
to map a single batch transform across both of the these tapes in such a way that allows us to submit a single job for execution:>>> tapes, fn = map_batch_transform(qml.transforms.hamiltonian_expand, [tape1, tape2]) >>> dev = qml.device("default.qubit", wires=2) >>> fn(qml.execute(tapes, dev, qml.gradients.param_shift)) [0.9950041652780257, 0.8150893013179248]
code/api/pennylane.transforms.map_batch_transform
Download Python script
Download Notebook
View on GitHub