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)

with qml.tape.QuantumTape() as tape1:
    qml.RX(0.5, wires=0)
    qml.RY(0.1, wires=1)
    qml.CNOT(wires=[0, 1])
    qml.expval(H)

with qml.tape.QuantumTape() as tape2:
    qml.Hadamard(wires=0)
    qml.CRX(0.5, wires=[0, 1])
    qml.CNOT(wires=[0, 1])
    qml.expval(H + 0.5 * qml.PauliY(0))

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]