docstr: Test that appo_policy_rlm loss matches the appo learner loss.
docstr_tok: ["Test","that","appo_policy_rlm","loss","matches","the","appo","learner","loss","."]
code: def test_appo_loss(self):
      """Test that appo_policy_rlm loss matches the appo learner loss."""
      config = (
          appo.APPOConfig()
          .experimental(_enable_new_api_stack=True)
          .environment("CartPole-v1")
          .rollouts(
              num_rollout_workers=0,
              rollout_fragment_length=frag_length,
          )
          .resources(num_gpus=0)
          .training(
              gamma=0.99,
              model=dict(
                  fcnet_hiddens=[10, 10],
                  fcnet_activation="linear",
                  vf_share_layers=False,
              ),
          )
      )
      # We have to set exploration_config here manually because setting it through
      # config.exploration() only deep-updates it
      config.exploration_config = {}
  
      for fw in framework_iterator(config, frameworks=("torch", "tf2")):
          algo = config.build()
  
          if fw == "tf2":
              train_batch = SampleBatch(
                  tree.map_structure(
                      lambda x: tf.convert_to_tensor(x), FAKE_BATCH
                  )
              )
          else:
              train_batch = SampleBatch(
                  tree.map_structure(
                      lambda x: convert_to_torch_tensor(x), FAKE_BATCH
                  )
              )
  
          algo_config = config.copy(copy_frozen=False)
          algo_config.resources(num_learner_workers=0)
          algo_config.validate()
  
          learner_group = algo_config.build_learner_group(
              env=algo.workers.local_worker().env
          )
          learner_group.set_weights(algo.get_weights())
          learner_group.update_from_batch(
              batch=train_batch.as_multi_agent()
          )
  
          algo.stop()
  
file_path: ray/rllib/algorithms/appo/tests/test_appo_learner.py
imports: import unittest
  import numpy
  import tree
  import ray
  import ray.rllib.algorithms.appo
  from ray.rllib.algorithms.appo.tf.appo_tf_learner import LEARNER_RESULTS_CURR_KL_COEFF_KEY
  from ray.rllib.policy.sample_batch import SampleBatch, DEFAULT_POLICY_ID
  from ray.rllib.utils.metrics.learner_info import LEARNER_INFO
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.test_utils import framework_iterator
  from ray.rllib.utils.torch_utils import convert_to_torch_tensor
label_desc: Use image node_id 3 for calling the TestAPPOTfLearner obj's underlying member method code with example usage: obj.test_appo_loss() without return types