class_docstr: Gradient tests for the vjp function
class_docstr_tok: ["Gradient","tests","for","the","vjp","function"]
docstr: Tests that the output of the VJP transform
  can be differentiated using Torch.
docstr_tok: ["Tests","that","the","output","of","the","VJP","transform","can","be","differentiated","using","Torch","."]
code: def test_torch(self, dev_name, tol):
      """Tests that the output of the VJP transform
      can be differentiated using Torch."""
      import torch
  
      dev = qml.device(dev_name, wires=2)
  
      params_np = np.array([0.543, -0.654], requires_grad=True)
      params = torch.tensor(
          params_np, requires_grad=True, dtype=torch.float64
      )
      dy = torch.tensor([-1.0, 0.0, 0.0, 1.0], dtype=torch.float64)
  
      with qml.queuing.AnnotatedQueue() as q:
          ansatz(params[0], params[1])
  
      tape = qml.tape.QuantumScript.from_queue(q)
      tape.trainable_params = {0, 1}
      tapes, fn = qml.gradients.vjp(tape, dy, param_shift)
      vjp = fn(qml.execute(tapes, dev, qml.gradients.param_shift))
  
      assert np.allclose(
          vjp.detach(), expected(params.detach()), atol=tol, rtol=0
      )
  
      cost = vjp[0]
      cost.backward()
  
      exp = qml.jacobian(lambda x: expected(x)[0])(params_np)
      assert np.allclose(params.grad, exp, atol=tol, rtol=0)
  
imports: from functools import partial
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.gradients import param_shift
label_desc: Use image node_id 2 for calling the TestVJPGradients obj's underlying member method code with example usage: obj.test_torch(dev_name, tol) without return types