class_docstr: Tests utilities helping with Checkpoint management.
class_docstr_tok: ["Tests","utilities","helping","with","Checkpoint","management","."]
docstr: Tests, whether a Policy checkpoint can be translated into msgpack ...
  
  ... and recovered back into a Policy, which is identical to a
  pickle-checkpoint-recovered Policy (given same initial config).
docstr_tok: ["Tests",",","whether","a","Policy","checkpoint","can","be","translated","into","msgpack","...","...","and","recovered","back","into","a","Policy",",","which","is","identical","to","a","pickle-checkpoint-recovered","Policy","(","given","same","initial","config",")","."]
code: def test_msgpack_policy_checkpoint_translation(self):
      """Tests, whether a Policy checkpoint can be translated into msgpack ...
  
      ... and recovered back into a Policy, which is identical to a
      pickle-checkpoint-recovered Policy (given same initial config).
      """
      # Base config used for both pickle-based checkpoint and msgpack-based one.
      config = PPOConfig().environment("CartPole-v1")
      # Build algorithm/policy objects.
      algo1 = config.build()
      pol1 = algo1.get_policy()
      # Get its state.
      pickle_state = pol1.get_state()
  
      # Create standard (pickle-based) checkpoint.
      with tempfile.TemporaryDirectory() as pickle_cp_dir:
          pol1.export_checkpoint(pickle_cp_dir)
          # Now convert pickle checkpoint to msgpack using the provided
          # utility function.
          with tempfile.TemporaryDirectory() as msgpack_cp_dir:
              convert_to_msgpack_policy_checkpoint(
                  pickle_cp_dir, msgpack_cp_dir
              )
              msgpack_cp_info = get_checkpoint_info(msgpack_cp_dir)
              self.assertTrue(msgpack_cp_info["type"] == "Policy")
              self.assertTrue(msgpack_cp_info["format"] == "msgpack")
              self.assertTrue(msgpack_cp_info["policy_ids"] is None)
              # Try recreating a new policy object from the msgpack checkpoint.
              pol2 = Policy.from_checkpoint(msgpack_cp_dir)
      # Get the state of the policy recovered from msgpack.
      msgpack_state = pol2.get_state()
  
      # Make sure the states? match 100%. Our `check` utility
      # cannot handle comparing types/classes, so we'll have to serialize the
      # pickle'd config (which contains types, rather than class strings).
      pickle_state["policy_spec"][
          "config"
      ] = AlgorithmConfig._serialize_dict(
          pickle_state["policy_spec"]["config"]
      )
      check(pickle_state, msgpack_state)
  
imports: import os
  from pathlib import Path
  import tempfile
  import unittest
  import ray
  from ray.rllib.algorithms.algorithm import Algorithm
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
  from ray.rllib.algorithms.dqn import DQNConfig
  from ray.rllib.algorithms.ppo import PPOConfig
  from ray.rllib.examples.env.multi_agent import MultiAgentCartPole
  from ray.rllib.policy.policy import Policy
  from ray.rllib.utils.checkpoints import get_checkpoint_info, convert_to_msgpack_checkpoint, convert_to_msgpack_policy_checkpoint
  from ray.rllib.utils.test_utils import check
  from ray import tune
label_desc: Use image node_id 8 for calling the TestCheckpointUtils obj's underlying member method code with example usage: obj.test_msgpack_policy_checkpoint_translation() without return types