code: def test_train_multi_agent_cartpole_multi_policy(self):
      n = 10
      register_env(
          "multi_agent_cartpole",
          lambda _: MultiAgentCartPole({"num_agents": n}),
      )
  
      def gen_policy():
          config = PPOConfig.overrides(
              gamma=random.choice([0.5, 0.8, 0.9, 0.95, 0.99]),
              lr=random.choice([0.001, 0.002, 0.003]),
          )
          return PolicySpec(config=config)
  
      config = (
          PPOConfig()
          .environment("multi_agent_cartpole")
          .rollouts(num_rollout_workers=0)
          .multi_agent(
              policies={
                  "policy_1": gen_policy(),
                  "policy_2": gen_policy(),
              },
              policy_mapping_fn=lambda agent_id, episode, worker, **kwargs: (
                  "policy_1"
              ),
          )
          .framework("tf")
          .training(
              train_batch_size=50, sgd_minibatch_size=50, num_sgd_iter=1
          )
      )
  
      algo = config.build()
      # Just check that it runs without crashing
      for i in range(10):
          result = algo.train()
          print(
              "Iteration {}, reward {}, timesteps {}".format(
                  i,
                  result["episode_reward_mean"],
                  result["timesteps_total"],
              )
          )
      self.assertTrue(
          algo.compute_single_action([0, 0, 0, 0], policy_id="policy_1")
          in [0, 1]
      )
      self.assertTrue(
          algo.compute_single_action([0, 0, 0, 0], policy_id="policy_2")
          in [0, 1]
      )
      self.assertRaisesRegex(
          KeyError,
          "not found in PolicyMap",
          lambda: algo.compute_single_action(
              [0, 0, 0, 0], policy_id="policy_3"
          ),
      )
  
imports: import gymnasium
  import numpy
  import random
  import tree
  import unittest
  import ray
  from ray.tune.registry import register_env
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
  from ray.rllib.algorithms.dqn.dqn import DQNConfig
  from ray.rllib.algorithms.dqn.dqn_tf_policy import DQNTFPolicy
  from ray.rllib.algorithms.ppo import PPOConfig
  from ray.rllib.env.multi_agent_env import make_multi_agent, MultiAgentEnvWrapper
  from ray.rllib.evaluation.episode import Episode
  from ray.rllib.evaluation.rollout_worker import get_global_worker, RolloutWorker
  from ray.rllib.evaluation.tests.test_rollout_worker import MockPolicy
  from ray.rllib.examples.policy.random_policy import RandomPolicy
  from ray.rllib.examples.env.multi_agent import MultiAgentCartPole, BasicMultiAgent, EarlyDoneMultiAgent, FlexAgentsMultiAgent, RoundRobinMultiAgent, SometimesZeroAgentsMultiAgent
  from ray.rllib.policy.policy import PolicySpec
  from ray.rllib.policy.sample_batch import convert_ma_batch_to_sample_batch
  from ray.rllib.tests.test_nested_observation_spaces import NestedMultiAgentEnv
  from ray.rllib.utils.numpy import one_hot
  from ray.rllib.utils.test_utils import check
label_desc: Use image node_id 18 for calling the TestMultiAgentEnv obj's underlying member method code with example usage: obj.test_train_multi_agent_cartpole_multi_policy() and returns: PolicySpec