class_docstr: Test that using the QNode with Torch integrates with the PennyLane stack
class_docstr_tok: ["Test","that","using","the","QNode","with","Torch","integrates","with","the","PennyLane","stack"]
docstr: Test jacobian calculation
docstr_tok: ["Test","jacobian","calculation"]
code: def test_jacobian(
      self,
      interface,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      tol,
  ):
      """Test jacobian calculation"""
      kwargs = dict(
          diff_method=diff_method,
          grad_on_execution=grad_on_execution,
          interface=interface,
          device_vjp=device_vjp,
      )
      if diff_method == "spsa":
          kwargs["sampler_rng"] = np.random.default_rng(SEED_FOR_SPSA)
          kwargs["num_directions"] = 20
          tol = TOL_FOR_SPSA
  
      a_val = 0.1
      b_val = 0.2
  
      a = torch.tensor(a_val, dtype=torch.float64, requires_grad=True)
      b = torch.tensor(b_val, dtype=torch.float64, requires_grad=True)
  
      @qnode(dev, **kwargs)
      def circuit(a, b):
          qml.RY(a, wires=0)
          qml.RX(b, wires=1)
          qml.CNOT(wires=[0, 1])
          return qml.expval(qml.PauliZ(0)), qml.expval(qml.PauliY(1))
  
      res = circuit(a, b)
  
      assert circuit.qtape.trainable_params == [0, 1]
  
      assert isinstance(res, tuple)
      assert len(res) == 2
  
      assert isinstance(res[0], torch.Tensor)
      assert res[0].shape == ()
  
      assert isinstance(res[1], torch.Tensor)
      assert res[1].shape == ()
  
      expected = [np.cos(a_val), -np.cos(a_val) * np.sin(b_val)]
      assert np.allclose(
          res[0].detach().numpy(), expected[0], atol=tol, rtol=0
      )
      assert np.allclose(
          res[1].detach().numpy(), expected[1], atol=tol, rtol=0
      )
  
      loss = res[0] + res[1]
  
      loss.backward()
      expected = [
          -np.sin(a_val) + np.sin(a_val) * np.sin(b_val),
          -np.cos(a_val) * np.cos(b_val),
      ]
      assert np.allclose(a.grad, expected[0], atol=tol, rtol=0)
      assert np.allclose(b.grad, expected[1], atol=tol, rtol=0)
  
imports: import numpy
  import pytest
  import pennylane
  from pennylane import qnode
  from pennylane.devices import DefaultQubit
label_desc: Use image node_id 4 for calling the TestQNode obj's underlying member method code with example usage: obj.test_jacobian(interface, dev, diff_method, grad_on_execution, device_vjp, tol) and returns: qml,  qml