class_docstr: Tests the application and differentiation of an RX gate in the different interfaces.
class_docstr_tok: ["Tests","the","application","and","differentiation","of","an","RX","gate","in","the","different","interfaces","."]
docstr: Tests the application and differentiation of an rx gate with torch.
docstr_tok: ["Tests","the","application","and","differentiation","of","an","rx","gate","with","torch","."]
code: def test_rx_grad_torch(self, method):
      """Tests the application and differentiation of an rx gate with torch."""
  
      import torch
  
      state = torch.tensor(self.state)
  
      def f(phi):
          op = qml.RX(phi, wires=0)
          return method(op, state)
  
      phi = torch.tensor(0.325, requires_grad=True)
  
      new_state = f(phi)
      # forward-mode needed with complex results.
      # See bug: https://github.com/pytorch/pytorch/issues/94397
      g = torch.autograd.functional.jacobian(
          f, phi + 0j, strategy="forward-mode", vectorize=True
      )
  
      self.compare_expected_result(
          phi.detach().numpy(),
          state.detach().numpy(),
          new_state.detach().numpy(),
          g.detach().numpy(),
      )
  
imports: from functools import reduce
  import pytest
  import numpy
  from scipy.stats import unitary_group
  import pennylane
  from pennylane.operation import _UNSET_BATCH_SIZE, Operation
  from pennylane.devices.qubit.apply_operation import apply_operation, apply_operation_einsum, apply_operation_tensordot
label_desc: Use image node_id 4 for calling the TestRXCalcGrad obj's underlying member method code with example usage: obj.test_rx_grad_torch(method) and returns: method