code: def _sanitize_state(state: Dict[str, Any]) -> Dict[str, Any]:
      """Utility function to sanitize the state of a component.
  
      Sanitization enables the state to be deep-copied and hashed.
  
      """
      from lightning.app.storage import Drive, Path
      from lightning.app.storage.payload import _BasePayload
  
      def sanitize_path(path: Path) -> Path:
          path_copy = Path(path)
          path_copy._sanitize()
          return path_copy
  
      def sanitize_payload(payload: _BasePayload):
          return type(payload).from_dict(content=payload.to_dict())
  
      def sanitize_drive(drive: Drive) -> Dict:
          return drive.to_dict()
  
      def sanitize_cloud_compute(cloud_compute: CloudCompute) -> Dict:
          return cloud_compute.to_dict()
  
      state = apply_to_collection(
          state, dtype=Path, function=sanitize_path
      )
      state = apply_to_collection(
          state, dtype=_BasePayload, function=sanitize_payload
      )
      state = apply_to_collection(
          state, dtype=Drive, function=sanitize_drive
      )
      state = apply_to_collection(
          state, dtype=CloudCompute, function=sanitize_cloud_compute
      )
      return state
  
imports: import os
  from contextlib import contextmanager
  from typing import TYPE_CHECKING, Any, Dict, Generator, Optional
  from deepdiff.helper import NotPresent
  from lightning_utilities.core.apply_func import apply_to_collection
  from lightning.app.utilities.app_helpers import is_overridden
  from lightning.app.utilities.enum import ComponentContext
  from lightning.app.utilities.packaging.cloud_compute import CloudCompute
  from lightning.app.utilities.tree import breadth_first
label_desc: Use image node_id 2 for calling a global function with example usage: _sanitize_state(state) and returns: state, path_copy, type, drive, cloud_compute