docstr: Test if updating a SingleAgentRLModuleSpec in MultiAgentRLModuleSpec works.
  
  This tests if we can update a `model_config_dict` field through different
  kinds of updates:
      - Create a SingleAgentRLModuleSpec and update its model_config_dict.
      - Create two MultiAgentRLModuleSpecs and update the first one with the
          second one without overwriting it.
      - Check if the updated MultiAgentRLModuleSpec does not(!) have the
          updated model_config_dict.
      - Create two MultiAgentRLModuleSpecs and update the first one with the
          second one with overwriting it.
      - Check if the updated MultiAgentRLModuleSpec has(!) the updated
          model_config_dict.
docstr_tok: ["Test","if","updating","a","SingleAgentRLModuleSpec","in","MultiAgentRLModuleSpec","works",".","This","tests","if","we","can","update","a","`","model_config_dict","`","field","through","different","kinds","of","updates",":","-","Create","a","SingleAgentRLModuleSpec","and","update","its","model_config_dict",".","-","Create","two","MultiAgentRLModuleSpecs","and","update","the","first","one","with","the","second","one","without","overwriting","it",".","-","Check","if","the","updated","MultiAgentRLModuleSpec","does","not","(","!",")","have","the","updated","model_config_dict",".","-","Create","two","MultiAgentRLModuleSpecs","and","update","the","first","one","with","the","second","one","with","overwriting","it",".","-","Check","if","the","updated","MultiAgentRLModuleSpec","has","(","!",")","the","updated","model_config_dict","."]
code: def test_update_specs_multi_agent(self):
      """Test if updating a SingleAgentRLModuleSpec in MultiAgentRLModuleSpec works.
  
      This tests if we can update a `model_config_dict` field through different
      kinds of updates:
          - Create a SingleAgentRLModuleSpec and update its model_config_dict.
          - Create two MultiAgentRLModuleSpecs and update the first one with the
              second one without overwriting it.
          - Check if the updated MultiAgentRLModuleSpec does not(!) have the
              updated model_config_dict.
          - Create two MultiAgentRLModuleSpecs and update the first one with the
              second one with overwriting it.
          - Check if the updated MultiAgentRLModuleSpec has(!) the updated
              model_config_dict.
  
      """
      env = gym.make("CartPole-v0")
  
      # Test if SingleAgentRLModuleSpec.update() works.
      module_spec_1 = SingleAgentRLModuleSpec(
          module_class=DiscreteBCTorchModule,
          observation_space="Do not update me!",
          action_space=env.action_space,
          model_config_dict="Update me!",
      )
      module_spec_2 = SingleAgentRLModuleSpec(
          model_config_dict={"fcnet_hiddens": [32]},
      )
  
      self.assertEqual(module_spec_1.model_config_dict, "Update me!")
      module_spec_1.update(module_spec_2)
      self.assertEqual(
          module_spec_1.module_class, DiscreteBCTorchModule
      )
      self.assertEqual(
          module_spec_1.observation_space, "Do not update me!"
      )
      self.assertEqual(module_spec_1.action_space, env.action_space)
      self.assertEqual(
          module_spec_1.model_config_dict,
          module_spec_2.model_config_dict,
      )
  
      # Redefine module_spec_1 for following tests.
      module_spec_1 = SingleAgentRLModuleSpec(
          module_class=DiscreteBCTorchModule,
          observation_space="Do not update me!",
          action_space=env.action_space,
          model_config_dict="Update me!",
      )
  
      marl_spec_1 = MultiAgentRLModuleSpec(
          marl_module_class=BCTorchMultiAgentModuleWithSharedEncoder,
          module_specs={"agent_1": module_spec_1},
      )
      marl_spec_2 = MultiAgentRLModuleSpec(
          marl_module_class=BCTorchMultiAgentModuleWithSharedEncoder,
          module_specs={"agent_1": module_spec_2},
      )
  
      # Test if updating MultiAgentRLModuleSpec with overwriting works. This means
      # that the single agent specs should be overwritten
      self.assertEqual(
          marl_spec_1.module_specs["agent_1"].model_config_dict,
          "Update me!",
      )
      marl_spec_1.update(marl_spec_2, overwrite=True)
      self.assertEqual(
          marl_spec_1.module_specs["agent_1"], module_spec_2
      )
  
      # Test if updating MultiAgentRLModuleSpec without overwriting works. This
      # means that the single agent specs should not be overwritten
      marl_spec_3 = MultiAgentRLModuleSpec(
          marl_module_class=BCTorchMultiAgentModuleWithSharedEncoder,
          module_specs={"agent_1": module_spec_1},
      )
  
      self.assertEqual(
          marl_spec_3.module_specs["agent_1"].observation_space,
          "Do not update me!",
      )
      marl_spec_3.update(marl_spec_2, overwrite=False)
      # If we would overwrite, we would replace the observation space even though
      # it was None. This is not the case here.
      self.assertEqual(
          marl_spec_3.module_specs["agent_1"].observation_space,
          "Do not update me!",
      )
  
      # Test if updating with an additional SingleAgentRLModuleSpec works.
      module_spec_3 = SingleAgentRLModuleSpec(
          module_class=DiscreteBCTorchModule,
          observation_space=env.observation_space,
          action_space=env.action_space,
          model_config_dict="I'm new!",
      )
      marl_spec_3 = MultiAgentRLModuleSpec(
          marl_module_class=BCTorchMultiAgentModuleWithSharedEncoder,
          module_specs={"agent_2": module_spec_3},
      )
      self.assertEqual(marl_spec_1.module_specs.get("agent_2"), None)
      marl_spec_1.update(marl_spec_3)
      self.assertEqual(
          marl_spec_1.module_specs["agent_2"].model_config_dict,
          "I'm new!",
      )
  
file_path: ray/rllib/core/rl_module/tests/test_rl_module_specs.py
imports: import unittest
  import gymnasium
  import torch
  from ray.rllib.core.rl_module.rl_module import SingleAgentRLModuleSpec
  from ray.rllib.core.rl_module.marl_module import MultiAgentRLModule, MultiAgentRLModuleSpec
  from ray.rllib.core.testing.torch.bc_module import DiscreteBCTorchModule, BCTorchRLModuleWithSharedGlobalEncoder, BCTorchMultiAgentModuleWithSharedEncoder
  from ray.rllib.core.testing.tf.bc_module import DiscreteBCTFModule, BCTfRLModuleWithSharedGlobalEncoder, BCTfMultiAgentModuleWithSharedEncoder
label_desc: Use image node_id 7 for calling the TestRLModuleSpecs obj's underlying member method code with example usage: obj.test_update_specs_multi_agent() without return types