code: def _transform_observable(obs, Z, device_wires):
      """Apply a Gaussian linear transformation to an observable.
  
      Args:
          obs (.Observable): observable to transform
          Z (array[float]): Heisenberg picture representation of the linear transformation
          device_wires (.Wires): wires on the device the transformed observable is to be
              measured on
  
      Returns:
          .Observable: the transformed observable
      """
      # Get the Heisenberg representation of the observable
      # in the position/momentum basis. The returned matrix/vector
      # will have been expanded to act on the entire device.
      if obs.ev_order > 2:
          raise NotImplementedError(
              "Transforming observables of order > 2 not implemented."
          )
  
      A = obs.heisenberg_obs(device_wires)
  
      if A.ndim != obs.ev_order:
          raise ValueError(
              "Mismatch between the polynomial order of observable and its Heisenberg representation"
          )
  
      # transform the observable by the linear transformation Z
      A = A @ Z
  
      if A.ndim == 2:
          A = A + A.T
  
      # TODO: if the A matrix corresponds to a known observable in PennyLane,
      # for example qml.QuadX, qml.QuadP, qml.NumberOperator, we should return that
      # instead. This will allow for greater device compatibility.
      return qml.PolyXP(A, wires=device_wires)
  
imports: from typing import Sequence, Callable
  import itertools
  from functools import partial
  import warnings
  import numpy
  import pennylane
  from pennylane.measurements import ExpectationMP, ProbabilityMP, StateMP, VarianceMP, MeasurementProcess
  from pennylane import transform
  from pennylane.transforms.tape_expand import expand_invalid_trainable
  from pennylane.gradients.gradient_transform import _contract_qjac_with_cjac, choose_trainable_params, _validate_gradient_methods
  from .finite_difference import finite_diff
  from .general_shift_rules import generate_shifted_tapes, process_shifts
  from .gradient_transform import _no_trainable_grad
  from .parameter_shift import _get_operation_recipe, expval_param_shift
label_desc: Use image node_id 4 for calling a global function with example usage: _transform_observable(obs, Z, device_wires) and returns: qml