class_docstr: Test gradients for a single measurement
class_docstr_tok: ["Test","gradients","for","a","single","measurement"]
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=1)
          qml.CNOT(wires=[0, 1])
          qml.RX(x, wires=0)
          return qml.expval(qml.PauliZ(0) @ qml.PauliX(1))
  
      batch_size = 3
  
      def cost(input, x):
          return torch.sum(circuit(input, x))
  
      input = torch.linspace(0.1, 0.5, batch_size, requires_grad=False)
      x = torch.tensor(0.1, requires_grad=True)
  
      loss = cost(input, x)
      loss.backward()
  
      res = x.grad
      expected = -np.sin(0.1) * torch.sum(torch.sin(input))
      assert qml.math.allclose(res, expected, 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 TestDiffSingle obj's underlying member method code with example usage: obj.test_torch(diff_method, tol, interface) and returns: qml, torch