code: def convert_to_msgpack_checkpoint(
      checkpoint: Union[str, Checkpoint],
      msgpack_checkpoint_dir: str,
  ) -> str:
      """Converts an Algorithm checkpoint (pickle based) to a msgpack based one.
  
      Msgpack has the advantage of being python version independent.
  
      Args:
          checkpoint: The directory, in which to find the Algorithm checkpoint (pickle
              based).
          msgpack_checkpoint_dir: The directory, in which to create the new msgpack
              based checkpoint.
  
      Returns:
          The directory in which the msgpack checkpoint has been created. Note that
          this is the same as `msgpack_checkpoint_dir`.
      """
      from ray.rllib.algorithms import Algorithm
      from ray.rllib.utils.policy import validate_policy_id
  
      # Try to import msgpack and msgpack_numpy.
      msgpack = try_import_msgpack(error=True)
  
      # Restore the Algorithm using the python version dependent checkpoint.
      algo = Algorithm.from_checkpoint(checkpoint)
      state = algo.__getstate__()
  
      # Convert all code in state into serializable data.
      # Serialize the algorithm class.
      state["algorithm_class"] = serialize_type(
          state["algorithm_class"]
      )
      # Serialize the algorithm's config object.
      state["config"] = state["config"].serialize()
  
      # Extract policy states from worker state (Policies get their own
      # checkpoint sub-dirs).
      policy_states = {}
      if "worker" in state and "policy_states" in state["worker"]:
          policy_states = state["worker"].pop("policy_states", {})
  
      # Policy mapping fn.
      state["worker"]["policy_mapping_fn"] = NOT_SERIALIZABLE
      # Is Policy to train function.
      state["worker"]["is_policy_to_train"] = NOT_SERIALIZABLE
  
      # Add RLlib checkpoint version (as string).
      if state["config"]["_enable_new_api_stack"]:
          state["checkpoint_version"] = str(CHECKPOINT_VERSION_LEARNER)
      else:
          state["checkpoint_version"] = str(CHECKPOINT_VERSION)
  
      # Write state (w/o policies) to disk.
      state_file = os.path.join(
          msgpack_checkpoint_dir, "algorithm_state.msgpck"
      )
      with open(state_file, "wb") as f:
          msgpack.dump(state, f)
  
      # Write rllib_checkpoint.json.
      with open(
          os.path.join(msgpack_checkpoint_dir, "rllib_checkpoint.json"),
          "w",
      ) as f:
          json.dump(
              {
                  "type": "Algorithm",
                  "checkpoint_version": state["checkpoint_version"],
                  "format": "msgpack",
                  "state_file": state_file,
                  "policy_ids": list(policy_states.keys()),
                  "ray_version": ray.__version__,
                  "ray_commit": ray.__commit__,
              },
              f,
          )
  
      # Write individual policies to disk, each in their own sub-directory.
      for pid, policy_state in policy_states.items():
          # From here on, disallow policyIDs that would not work as directory names.
          validate_policy_id(pid, error=True)
          policy_dir = os.path.join(
              msgpack_checkpoint_dir, "policies", pid
          )
          os.makedirs(policy_dir, exist_ok=True)
          policy = algo.get_policy(pid)
          policy.export_checkpoint(
              policy_dir,
              policy_state=policy_state,
              checkpoint_format="msgpack",
          )
  
      # Release all resources used by the Algorithm.
      algo.stop()
  
      return msgpack_checkpoint_dir
  
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 2 for calling a global function with example usage: convert_to_msgpack_checkpoint(checkpoint, msgpack_checkpoint_dir) and returns: msgpack_checkpoint_dir