class_docstr: Tests for the _transform_observable method
docstr: Test that a second order observable is transformed correctly
docstr_tok: ["Test","that","a","second","order","observable","is","transformed","correctly"]
code: def test_second_order_transform(self, tol):
      """Test that a second order observable is transformed correctly"""
      # create a symmetric transformation
      Z = np.arange(3**2).reshape(3, 3)
      Z = Z.T + Z
  
      obs = qml.NumberOperator(0)
      res = _transform_observable(obs, Z, device_wires=[0])
  
      # The Heisenberg representation of the number operator
      # is (X^2 + P^2) / (2*hbar) - 1/2
      A = np.array([[-0.5, 0, 0], [0, 0.25, 0], [0, 0, 0.25]])
      expected = A @ Z + Z @ A
  
      assert isinstance(res, qml.PolyXP)
      assert res.wires.labels == (0,)
      assert np.allclose(res.data[0], expected, atol=tol, rtol=0)
  
imports: import unittest.mock
  import pytest
  import pennylane
  from pennylane import numpy
  from pennylane.gradients import param_shift_cv
  from pennylane.gradients.gradient_transform import choose_trainable_params
  from pennylane.gradients.parameter_shift_cv import _grad_method_cv, _find_gradient_methods_cv, _transform_observable
label_desc: Use image node_id 4 for calling the TestTransformObservable obj's underlying member method code with example usage: obj.test_second_order_transform(tol) without return types