class_docstr: Test gradients for multiple measurements
class_docstr_tok: ["Test","gradients","for","multiple","measurements"]
docstr: Test derivatives when using torch
docstr_tok: ["Test","derivatives","when","using","torch"]
code: def test_torch(self, diff_method, tol, interface):
      """Test derivatives when using torch"""
      import torch
  
      dev = qml.device("default.qubit", wires=2)
  
      @partial(qml.batch_input, argnum=0)
      @qml.qnode(dev, diff_method=diff_method, interface=interface)
      def circuit(input, x):
          qml.RY(input, wires=0)
          qml.RY(x, wires=0)
          qml.CNOT(wires=[0, 1])
          return qml.expval(qml.PauliZ(0)), qml.probs(wires=[0, 1])
  
      batch_size = 3
      input = torch.tensor(
          np.linspace(0.1, 0.5, batch_size), requires_grad=False
      )
      x = torch.tensor(0.1, requires_grad=True)
  
      res = circuit(input, x)
      expected = (
          torch.cos(input + x),
          qml.math.transpose(
              qml.math.stack(
                  [
                      torch.cos((input + x) / 2) ** 2,
                      torch.zeros_like(input),
                      torch.zeros_like(input),
                      torch.sin((input + x) / 2) ** 2,
                  ]
              )
          ),
      )
  
      assert isinstance(res, tuple)
      assert len(res) == 2
      for r, exp in zip(res, expected):
          assert qml.math.allclose(r, exp, atol=tol)
  
      grad = torch.autograd.functional.jacobian(
          lambda x: circuit(input, x), x
      )
      expected = (
          -torch.sin(input + x),
          qml.math.transpose(
              qml.math.stack(
                  [
                      -torch.sin(input + x) / 2,
                      torch.zeros_like(input),
                      torch.zeros_like(input),
                      torch.sin(input + x) / 2,
                  ]
              )
          ),
      )
  
      assert isinstance(grad, tuple)
      assert len(grad) == 2
      for g, exp in zip(grad, expected):
          assert qml.math.allclose(g, exp, atol=tol, rtol=0)
  
imports: from functools import partial
  import pytest
  import pennylane
  from pennylane import numpy
label_desc: Use image node_id 4 for calling the TestDiffMulti obj's underlying member method code with example usage: obj.test_torch(diff_method, tol, interface) and returns: qml,  qml