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 that the Torch interface can be applied to a QNode
  with a pre-existing interface
docstr_tok: ["Test","that","the","Torch","interface","can","be","applied","to","a","QNode","with","a","pre-existing","interface"]
code: def test_interface_swap(
      self,
      interface,
      dev,
      diff_method,
      grad_on_execution,
      device_vjp,
      tol,
  ):
      """Test that the Torch interface can be applied to a QNode
      with a pre-existing interface"""
  
      @qnode(
          dev,
          diff_method=diff_method,
          interface="autograd",
          grad_on_execution=grad_on_execution,
          device_vjp=device_vjp,
      )
      def circuit(a):
          qml.RY(a, wires=0)
          qml.RX(0.2, wires=0)
          return qml.expval(qml.PauliZ(0))
  
      from pennylane import numpy as anp
  
      a = anp.array(0.1, requires_grad=True)
  
      res1 = circuit(a)
      grad_fn = qml.grad(circuit)
      grad1 = grad_fn(a)
  
      # switch to Torch interface
      circuit.interface = interface
  
      a = torch.tensor(0.1, dtype=torch.float64, requires_grad=True)
  
      res2 = circuit(a)
      res2.backward()
      grad2 = a.grad
      assert np.allclose(res1, res2.detach().numpy(), atol=tol, rtol=0)
      assert np.allclose(grad1, grad2, 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 2 for calling the TestQNode obj's underlying member method code with example usage: obj.test_interface_swap(interface, dev, diff_method, grad_on_execution, device_vjp, tol) and returns: qml