code: def get_checkpoint_info(
      checkpoint: Union[str, Checkpoint]
  ) -> Dict[str, Any]:
      """Returns a dict with information about a Algorithm/Policy checkpoint.
  
      If the given checkpoint is a >=v1.0 checkpoint directory, try reading all
      information from the contained `rllib_checkpoint.json` file.
  
      Args:
          checkpoint: The checkpoint directory (str) or an AIR Checkpoint object.
  
      Returns:
          A dict containing the keys:
          "type": One of "Policy" or "Algorithm".
          "checkpoint_version": A version tuple, e.g. v1.0, indicating the checkpoint
          version. This will help RLlib to remain backward compatible wrt. future
          Ray and checkpoint versions.
          "checkpoint_dir": The directory with all the checkpoint files in it. This might
          be the same as the incoming `checkpoint` arg.
          "state_file": The main file with the Algorithm/Policy's state information in it.
          This is usually a pickle-encoded file.
          "policy_ids": An optional set of PolicyIDs in case we are dealing with an
          Algorithm checkpoint. None if `checkpoint` is a Policy checkpoint.
      """
      # Default checkpoint info.
      info = {
          "type": "Algorithm",
          "format": "cloudpickle",
          "checkpoint_version": CHECKPOINT_VERSION,
          "checkpoint_dir": None,
          "state_file": None,
          "policy_ids": None,
      }
  
      # `checkpoint` is a Checkpoint instance: Translate to directory and continue.
      if isinstance(checkpoint, Checkpoint):
          checkpoint: str = checkpoint.to_directory()
  
      # Checkpoint is dir.
      if os.path.isdir(checkpoint):
          info.update({"checkpoint_dir": checkpoint})
  
          # Figure out whether this is an older checkpoint format
          # (with a `checkpoint-\d+` file in it).
          for file in os.listdir(checkpoint):
              path_file = os.path.join(checkpoint, file)
              if os.path.isfile(path_file):
                  if re.match("checkpoint-\\d+", file):
                      info.update(
                          {
                              "checkpoint_version": version.Version(
                                  "0.1"
                              ),
                              "state_file": path_file,
                          }
                      )
                      return info
  
          # No old checkpoint file found.
  
          # If rllib_checkpoint.json file present, read available information from it
          # and then continue with the checkpoint analysis (possibly overriding further
          # information).
          if os.path.isfile(
              os.path.join(checkpoint, "rllib_checkpoint.json")
          ):
              with open(
                  os.path.join(checkpoint, "rllib_checkpoint.json")
              ) as f:
                  rllib_checkpoint_info = json.load(fp=f)
              if "checkpoint_version" in rllib_checkpoint_info:
                  rllib_checkpoint_info[
                      "checkpoint_version"
                  ] = version.Version(
                      rllib_checkpoint_info["checkpoint_version"]
                  )
              info.update(rllib_checkpoint_info)
          else:
              # No rllib_checkpoint.json file present: Warn and continue trying to figure
              # out checkpoint info ourselves.
              if log_once("no_rllib_checkpoint_json_file"):
                  logger.warning(
                      "No `rllib_checkpoint.json` file found in checkpoint directory "
                      f"{checkpoint}! Trying to extract checkpoint info from other files "
                      f"found in that dir."
                  )
  
          # Policy checkpoint file found.
          for extension in ["pkl", "msgpck"]:
              if os.path.isfile(
                  os.path.join(checkpoint, "policy_state." + extension)
              ):
                  info.update(
                      {
                          "type": "Policy",
                          "format": "cloudpickle"
                          if extension == "pkl"
                          else "msgpack",
                          "checkpoint_version": CHECKPOINT_VERSION,
                          "state_file": os.path.join(
                              checkpoint, f"policy_state.{extension}"
                          ),
                      }
                  )
                  return info
  
          # Valid Algorithm checkpoint >v0 file found?
          format = None
          for extension in ["pkl", "msgpck"]:
              state_file = os.path.join(
                  checkpoint, f"algorithm_state.{extension}"
              )
              if os.path.isfile(state_file):
                  format = (
                      "cloudpickle" if extension == "pkl" else "msgpack"
                  )
                  break
          if format is None:
              raise ValueError(
                  "Given checkpoint does not seem to be valid! No file with the name "
                  "`algorithm_state.[pkl|msgpck]` (or `checkpoint-[0-9]+`) found."
              )
  
          info.update(
              {
                  "format": format,
                  "state_file": state_file,
              }
          )
  
          # Collect all policy IDs in the sub-dir "policies/".
          policies_dir = os.path.join(checkpoint, "policies")
          if os.path.isdir(policies_dir):
              policy_ids = set()
              for policy_id in os.listdir(policies_dir):
                  policy_ids.add(policy_id)
              info.update({"policy_ids": policy_ids})
  
      # Checkpoint is a file: Use as-is (interpreting it as old Algorithm checkpoint
      # version).
      elif os.path.isfile(checkpoint):
          info.update(
              {
                  "checkpoint_version": version.Version("0.1"),
                  "checkpoint_dir": os.path.dirname(checkpoint),
                  "state_file": checkpoint,
              }
          )
  
      else:
          raise ValueError(
              f"Given checkpoint ({checkpoint}) not found! Must be a "
              "checkpoint directory (or a file for older checkpoint versions)."
          )
  
      return info
  
file_path: ray/rllib/utils/checkpoints.py
imports: import logging
  import json
  import os
  from packaging import version
  import re
  from typing import Any, Dict, Union
  import ray
  from ray.rllib.utils.serialization import NOT_SERIALIZABLE, serialize_type
  from ray.train import Checkpoint
  from ray.util import log_once
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 1 for calling a global function with example usage: get_checkpoint_info(checkpoint) and returns: info, info, info