map_batch_transform(transform, tapes)[source]

Map a transform over multiple tapes.

  • transform (Callable) – the transform to be mapped

  • tapes (Sequence[QuantumTape]) – The sequence of tapes the transform should be applied to. Each tape in the sequence is transformed by the transform.


Consider the following tapes:

H = qml.Z(0) @ qml.Z(1) - qml.X(0)

ops1 = [
    qml.RX(0.5, wires=0),
    qml.RY(0.1, wires=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.Y(0))]
tape2 = qml.tape.QuantumTape(ops2, measurements2)

We can use map_batch_transform to map a single 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))
[array(0.99500417), array(0.8150893)]