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","."]
code: def compare_expected_result(self, phi, state, new_state, g):
      expected0 = (
          np.cos(phi / 2) * state[0, :, :]
          + -1j * np.sin(phi / 2) * state[1, :, :]
      )
      expected1 = (
          -1j * np.sin(phi / 2) * state[0, :, :]
          + np.cos(phi / 2) * state[1, :, :]
      )
  
      assert qml.math.allclose(new_state[0, :, :], expected0)
      assert qml.math.allclose(new_state[1, :, :], expected1)
  
      g_expected0 = (
          -0.5 * np.sin(phi / 2) * state[0, :, :]
          - 0.5j * np.cos(phi / 2) * state[1, :, :]
      )
      g_expected1 = (
          -0.5j * np.cos(phi / 2) * state[0, :, :]
          - 0.5 * np.sin(phi / 2) * state[1, :, :]
      )
  
      assert qml.math.allclose(g[0], g_expected0)
      assert qml.math.allclose(g[1], g_expected1)
  
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 1 for calling the TestRXCalcGrad obj's underlying member method code with example usage: obj.compare_expected_result(phi, state, new_state, g) without return types