code: def _prepare_app_state_for_restore(
      unit: AppStateMixin, restore_options: RestoreOptions
  ) -> Dict[str, Any]:
      """
      Prepares the application state for restoring from a checkpoint given a RestoreOptions.
      """
      app_state = _prepare_app_state(unit)
  
      restore_options = restore_options or RestoreOptions()
      if not restore_options.restore_train_progress:
          app_state.pop(_TRAIN_PROGRESS_STATE_KEY, None)
  
      if not restore_options.restore_eval_progress:
          app_state.pop(_EVAL_PROGRESS_STATE_KEY, None)
  
      if not restore_options.restore_optimizers:
          # remove all optimizer keys from app_state
          for optim_keys in unit.tracked_optimizers().keys():
              app_state.pop(optim_keys, None)
  
      if not restore_options.restore_lr_schedulers:
          # remove all lr scheduler keys from app_state
          for lr_scheduler_keys in unit.tracked_lr_schedulers().keys():
              app_state.pop(lr_scheduler_keys, None)
  
      return app_state
  
imports: import logging
  import os
  import re
  from typing import Any, Callable, cast, Dict, List, Optional, Pattern, Tuple, TypeVar
  import fsspec
  from pyre_extensions import none_throws
  from torch import distributed
  from torchtnt.framework.callbacks.checkpointer_types import RestoreOptions
  from torchtnt.framework.state import State
  from torchtnt.framework.unit import AppStateMixin
  from torchtnt.utils.distributed import get_global_rank, PGWrapper
  from torchtnt.utils.fsspec import get_filesystem
  from torchtnt.utils.stateful import Stateful
label_desc: Use image node_id 10 for calling a global function with example usage: _prepare_app_state_for_restore(unit, restore_options) and returns: app_state