code: def purity(wires) -> "PurityMP":
      r"""The purity of the system prior to measurement.
  
      .. math::
          \gamma = \text{Tr}(\rho^2)
  
      where :math:`\rho` is the density matrix. The purity of a normalized quantum state satisfies
      :math:`\frac{1}{d} \leq \gamma \leq 1`, where :math:`d` is the dimension of the Hilbert space.
      A pure state has a purity of 1.
  
      Args:
          wires (Sequence[int] or int): The wires of the subsystem
  
      Returns:
          PurityMP: Measurement process instance
  
      **Example**
  
      .. code-block:: python3
  
          dev = qml.device("default.mixed", wires=2)
  
          @qml.qnode(dev)
          def circuit_purity(p):
              qml.Hadamard(wires=0)
              qml.CNOT(wires=[0, 1])
              qml.BitFlip(p, wires=0)
              qml.BitFlip(p, wires=1)
              return qml.purity(wires=[0,1])
  
      >>> circuit_purity(0.1)
      array(0.7048)
  
      .. seealso:: :func:`pennylane.qinfo.transforms.purity` and :func:`pennylane.math.purity`
      """
      wires = Wires(wires)
      return PurityMP(wires=wires)
  
file_path: pennylane/pennylane/measurements/purity.py
imports: from typing import Sequence, Optional
  import pennylane
  from pennylane.wires import Wires
  from .measurements import StateMeasurement, Purity
label_desc: Use image node_id 1 for calling a global function with example usage: purity(wires) and returns: PurityMP