class_docstr: Tests for the _transform_observable method
docstr: Test that the transformation works correctly
  for the case where the transformation applies to more wires
  than the observable.
docstr_tok: ["Test","that","the","transformation","works","correctly","for","the","case","where","the","transformation","applies","to","more","wires","than","the","observable","."]
code: def test_device_wire_expansion(self, tol):
      """Test that the transformation works correctly
      for the case where the transformation applies to more wires
      than the observable."""
  
      # create a 3-mode symmetric transformation
      wires = qml.wires.Wires([0, "a", 2])
      ndim = 1 + 2 * len(wires)
  
      Z = np.arange(ndim**2).reshape(ndim, ndim)
      Z = Z.T + Z
  
      obs = qml.NumberOperator(0)
      res = _transform_observable(obs, Z, device_wires=wires)
  
      # The Heisenberg representation of the number operator
      # is (X^2 + P^2) / (2*hbar) - 1/2. We use the ordering
      # I, X0, Xa, X2, P0, Pa, P2.
      A = np.diag([-0.5, 0.25, 0.25, 0, 0, 0, 0])
      expected = A @ Z + Z @ A
  
      assert isinstance(res, qml.PolyXP)
      assert res.wires == wires
      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 5 for calling the TestTransformObservable obj's underlying member method code with example usage: obj.test_device_wire_expansion(tol) without return types