class_docstr: Test that the top-level compile function works across all interfaces.
class_docstr_tok: ["Test","that","the","top-level","compile","function","works","across","all","interfaces","."]
docstr: Test QNode and gradient in torch interface.
docstr_tok: ["Test","QNode","and","gradient","in","torch","interface","."]
code: def test_compile_torch(self):
      """Test QNode and gradient in torch interface."""
      import torch
  
      original_qnode = qml.QNode(
          qfunc_emb, dev_3wires, diff_method="parameter-shift"
      )
      transformed_qnode = qml.QNode(
          transformed_qfunc_emb,
          dev_3wires,
          diff_method="parameter-shift",
      )
  
      original_x = torch.tensor([0.3, -0.2, 0.8], requires_grad=False)
      original_params = torch.ones((2, 3), requires_grad=True)
  
      transformed_x = torch.tensor(
          [0.3, -0.2, 0.8], requires_grad=False
      )
      transformed_params = torch.ones((2, 3), requires_grad=True)
  
      original_result = original_qnode(original_x, original_params)
      transformed_result = transformed_qnode(
          transformed_x, transformed_params
      )
  
      # Check that the numerical output is the same
      assert qml.math.allclose(original_result, transformed_result)
  
      # Check that the gradient is the same
      original_result.backward()
      transformed_result.backward()
  
      assert qml.math.allclose(
          original_params.grad, transformed_params.grad
      )
  
      # Check operation list
      ops = transformed_qnode.qtape.operations
      compare_operation_lists(
          ops, expected_op_list, expected_wires_list
      )
  
imports: from functools import partial
  import pytest
  from test_optimization.utils import compare_operation_lists
  import pennylane
  from pennylane import numpy
  from pennylane.wires import Wires
  from pennylane.transforms.compile import compile
  from pennylane.transforms import unitary_to_rot
  from pennylane.transforms.optimization import cancel_inverses, commute_controlled, merge_rotations, single_qubit_fusion
  from pennylane.transforms.optimization.optimization_utils import _fuse_global_phases
label_desc: Use image node_id 2 for calling the TestCompileInterfaces obj's underlying member method code with example usage: obj.test_compile_torch() without return types