Skip to content

Commit

Permalink
Merge pull request #153 from Replicable-MARL/rllib_1.8.0_dev
Browse files Browse the repository at this point in the history
customize env config path
  • Loading branch information
Theohhhu committed Jul 17, 2023
2 parents 0ac275e + 45d513a commit 521316d
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/add_new_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_env_info(self):
# register new env
ENV_REGISTRY["magym"] = RLlibMAGym
# initialize env
env = marl.make_env(environment_name="magym", map_name="Checkers")
env = marl.make_env(environment_name="magym", map_name="Checkers", abs_path="../../examples/config/env_config/magym.yaml")
# pick mappo algorithms
mappo = marl.algos.mappo(hyperparam_source="test")
# customize model
Expand Down
3 changes: 2 additions & 1 deletion examples/config/env_config/magym.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ env_args:

mask_flag: False
global_state_flag: False
opp_action_in_cc: True
opp_action_in_cc: True
agent_level_batch_update: True
1 change: 1 addition & 0 deletions examples/config/env_config/two_teams_smac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ mask_flag: True
global_state_flag: True
opp_action_in_cc: True
fixed_batch_timesteps: 3200
agent_level_batch_update: False
2 changes: 1 addition & 1 deletion examples/customize_policy_sharing.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_env_info(self):
# register new env
ENV_REGISTRY["two_teams_smac"] = Two_Teams_SMAC
# initialize env
env = marl.make_env(environment_name="two_teams_smac", map_name="3m")
env = marl.make_env(environment_name="two_teams_smac", map_name="3m", abs_path="../../examples/config/env_config/two_teams_smac.yaml")
# pick mappo algorithms
mappo = marl.algos.mappo(hyperparam_source="test")
# customize model
Expand Down
13 changes: 7 additions & 6 deletions marllib/marl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def make_env(
environment_name: str,
map_name: str,
force_coop: bool = False,
abs_path: str = "",
**env_params
) -> Tuple[MultiAgentEnv, Dict]:
"""
Expand All @@ -81,18 +82,18 @@ def make_env(
:param environment_name: name of the environment
:param map_name: name of the scenario
:param force_coop: enforce the reward return of the environment to be global
:param abs_path: env configuration path
:param env_params: parameters that can be pass to the environment for customizing the environment
Returns:
Tuple[MultiAgentEnv, Dict]: env instance & env configuration dict
"""

# default config
env_config_file_path = os.path.join(os.path.dirname(__file__),
"../envs/base_env/config/{}.yaml".format(environment_name))
if not os.path.exists(env_config_file_path):
if abs_path != "":
env_config_file_path = os.path.join(os.path.dirname(__file__), abs_path)
else:
# default config
env_config_file_path = os.path.join(os.path.dirname(__file__),
"../../examples/config/env_config/{}.yaml".format(environment_name))
"../envs/base_env/config/{}.yaml".format(environment_name))

with open(env_config_file_path, "r") as f:
env_config_dict = yaml.load(f, Loader=yaml.FullLoader)
Expand Down

1 comment on commit 521316d

@Theohhhu
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.