class_docstr: Tests for the map_batch_transform function
class_docstr_tok: ["Tests","for","the","map_batch_transform","function"]
docstr: Test that an execution using map_batch_transform can be differentiated
docstr_tok: ["Test","that","an","execution","using","map_batch_transform","can","be","differentiated"]
code: def test_differentiation(self):
      """Test that an execution using map_batch_transform can be differentiated"""
      dev = qml.device("default.qubit.legacy", wires=2)
      H = qml.PauliZ(0) @ qml.PauliZ(1) - qml.PauliX(0)
  
      weights = np.array([0.6, 0.8], requires_grad=True)
  
      def cost(weights):
          with qml.queuing.AnnotatedQueue() as q1:
              qml.RX(weights[0], wires=0)
              qml.RY(weights[1], wires=1)
              qml.CNOT(wires=[0, 1])
              qml.expval(H)
  
          tape1 = qml.tape.QuantumScript.from_queue(q1)
          with qml.queuing.AnnotatedQueue() as q2:
              qml.Hadamard(wires=0)
              qml.CRX(weights[0], wires=[0, 1])
              qml.CNOT(wires=[0, 1])
              qml.expval(H + 0.5 * qml.PauliY(0))
  
          tape2 = qml.tape.QuantumScript.from_queue(q2)
          tapes, fn = qml.transforms.map_batch_transform(
              qml.transforms.hamiltonian_expand, [tape1, tape2]
          )
          res = qml.execute(
              tapes,
              dev,
              qml.gradients.param_shift,
              device_batch_transform=False,
          )
          return np.sum(fn(res))
  
      res = cost(weights)
      x, y = weights
      expected = np.cos(y) + 0.5 + 0.5 * np.cos(x) - 0.5 * np.sin(x / 2)
      assert np.allclose(res, expected)
  
      res = qml.grad(cost)(weights)
      expected = [-0.5 * np.sin(x) - 0.25 * np.cos(x / 2), -np.sin(y)]
      assert np.allclose(res, expected)
  
imports: import functools
  import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 2 for calling the TestMapBatchTransform obj's underlying member method code with example usage: obj.test_differentiation() and returns: np