docstr: Tests saving and loading the state of the PPO Learner Group.
docstr_tok: ["Tests","saving","and","loading","the","state","of","the","PPO","Learner","Group","."]
code: def test_save_load_state(self):
      """Tests saving and loading the state of the PPO Learner Group."""
      config = (
          ppo.PPOConfig()
          .experimental(_enable_new_api_stack=True)
          .environment("CartPole-v1")
          .rollouts(
              num_rollout_workers=0,
          )
          .training(
              gamma=0.99,
              model=dict(
                  fcnet_hiddens=[10, 10],
                  fcnet_activation="linear",
                  vf_share_layers=False,
              ),
          )
      )
  
      for _ in framework_iterator(config, ("tf2", "torch")):
          algo_config = config.copy(copy_frozen=False)
          algo_config.validate()
          algo_config.freeze()
          learner_group1 = algo_config.build_learner_group(env=self.ENV)
          learner_group2 = algo_config.build_learner_group(env=self.ENV)
          with tempfile.TemporaryDirectory() as tmpdir:
              learner_group1.save_state(tmpdir)
              learner_group2.load_state(tmpdir)
              # Remove functions from state b/c they are not comparable via `check`.
              s1 = learner_group1.get_state()
              s1.pop("should_module_be_updated_fn")
              s2 = learner_group2.get_state()
              s2.pop("should_module_be_updated_fn")
              check(s1, s2)
  
imports: import unittest
  import tempfile
  import gymnasium
  import numpy
  import tensorflow
  import torch
  import tree
  import ray
  import ray.rllib.algorithms.ppo
  from ray.rllib.algorithms.ppo.ppo import LEARNER_RESULTS_CURR_KL_COEFF_KEY
  from ray.rllib.examples.env.multi_agent import MultiAgentCartPole
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.tune.registry import register_env
  from ray.rllib.utils.metrics.learner_info import LEARNER_INFO
  from ray.rllib.utils.test_utils import check, framework_iterator
  from ray.rllib.evaluation.postprocessing import compute_gae_for_sample_batch
label_desc: Use image node_id 4 for calling the TestPPO obj's underlying member method code with example usage: obj.test_save_load_state() without return types