code: def reduced_dm(
      tape: QuantumTape, wires, **kwargs
  ) -> (Sequence[QuantumTape], Callable):
      """Compute the reduced density matrix from a :class:`~.QNode` returning
      :func:`~pennylane.state`.
  
      Args:
          tape (QuantumTape or QNode or Callable)): A quantum circuit returning :func:`~pennylane.state`.
          wires (Sequence(int)): List of wires in the considered subsystem.
  
      Returns:
          qnode (QNode) or quantum function (Callable) or tuple[List[QuantumTape], function]:
  
          The transformed circuit as described in :func:`qml.transform <pennylane.transform>`. Executing this circuit
          will provide the reduced density matrix in the form of a tensor.
  
      **Example**
  
      .. code-block:: python
  
          import numpy as np
  
          dev = qml.device("default.qubit", wires=2)
  
          @qml.qnode(dev)
          def circuit(x):
              qml.IsingXX(x, wires=[0,1])
              return qml.state()
  
      >>> transformed_circuit = reduced_dm(circuit, wires=[0])
      >>> transformed_circuit(np.pi/2)
      tensor([[0.5+0.j, 0. +0.j],
              [0. +0.j, 0.5+0.j]], requires_grad=True)
  
      .. seealso:: :func:`pennylane.density_matrix` and :func:`pennylane.math.reduce_dm`
      """
      # device_wires is provided by the custom QNode transform
      all_wires = kwargs.get("device_wires", tape.wires)
      wire_map = {w: i for i, w in enumerate(all_wires)}
      indices = [wire_map[w] for w in wires]
  
      measurements = tape.measurements
      if len(measurements) != 1 or not isinstance(
          measurements[0], StateMP
      ):
          raise ValueError("The qfunc measurement needs to be State.")
  
      def processing_fn(res):
          # device is provided by the custom QNode transform
          device = kwargs.get("device", None)
          c_dtype = getattr(device, "C_DTYPE", "complex128")
  
          # determine the density matrix
          dm_func = (
              qml.math.reduce_dm
              if isinstance(measurements[0], DensityMatrixMP)
              or isinstance(device, DefaultMixed)
              else qml.math.reduce_statevector
          )
          density_matrix = dm_func(
              res[0], indices=indices, c_dtype=c_dtype
          )
  
          return density_matrix
  
      return [tape], processing_fn
  
imports: from functools import partial
  from typing import Callable, Sequence
  import pennylane
  from pennylane.tape import QuantumTape
  from pennylane.devices import DefaultQubit, DefaultQubitLegacy, DefaultMixed
  from pennylane.measurements import StateMP, DensityMatrixMP
  from pennylane.gradients import adjoint_metric_tensor, metric_tensor
  from pennylane import transform
label_desc: Use image node_id 1 for calling a global function with example usage: reduced_dm(tape, wires) and returns: list,  processing_fn, density_matrix