From d16b1a010568064b5686550a48b07a3e831fd7e6 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Wed, 8 Jul 2020 16:39:48 -0700 Subject: [PATCH 1/3] don't allow --num-envs >1 with no --env --- ml-agents/mlagents/trainers/settings.py | 7 ++++++- .../mlagents/trainers/tests/test_settings.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ml-agents/mlagents/trainers/settings.py b/ml-agents/mlagents/trainers/settings.py index 55ee9b0b63..0bd0941a3e 100644 --- a/ml-agents/mlagents/trainers/settings.py +++ b/ml-agents/mlagents/trainers/settings.py @@ -600,9 +600,14 @@ class EnvironmentSettings: env_path: Optional[str] = parser.get_default("env_path") env_args: Optional[List[str]] = parser.get_default("env_args") base_port: int = parser.get_default("base_port") - num_envs: int = parser.get_default("num_envs") + num_envs: int = attr.ib(default=parser.get_default("num_envs")) seed: int = parser.get_default("seed") + @num_envs.validator + def validate_num_envs(self, attribute, value): + if value > 1 and self.env_path is None: + raise ValueError("--num-envs must be 1 if --env is not set.") + @attr.s(auto_attribs=True) class EngineSettings: diff --git a/ml-agents/mlagents/trainers/tests/test_settings.py b/ml-agents/mlagents/trainers/tests/test_settings.py index be93042396..2a9393c1b3 100644 --- a/ml-agents/mlagents/trainers/tests/test_settings.py +++ b/ml-agents/mlagents/trainers/tests/test_settings.py @@ -13,6 +13,7 @@ RewardSignalType, RewardSignalSettings, CuriositySettings, + EnvironmentSettings, EnvironmentParameterSettings, ConstantSettings, UniformSettings, @@ -452,3 +453,18 @@ def test_exportable_settings(use_defaults): check_dict_is_at_least(second_export, dict_export) # Check that the two exports are the same assert dict_export == second_export + + +def test_environment_settings(): + # default args + EnvironmentSettings() + + # 1 env is OK if no env_path + EnvironmentSettings(num_envs=1) + + # multiple envs is OK if env_path is set + EnvironmentSettings(num_envs=42, env_path="/foo/bar.exe") + + # Multiple environments with no env_path is an error + with pytest.raises(ValueError): + EnvironmentSettings(num_envs=2) From c20d4addd9562036584bfea1b88154d9e7092ad4 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Wed, 8 Jul 2020 16:44:38 -0700 Subject: [PATCH 2/3] changelog --- com.unity.ml-agents/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 3291d0b1b3..a53e1fcf55 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to ### Minor Changes ### Bug Fixes +`mlagents-learn` will now raise an error immediately if `--num-envs` is greater than 1 without setting the `--env` +argument. (#4203) ## [1.2.0-preview] - 2020-07-15 From 3c63eed185501a14525c0aa3860781036e4b9122 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Wed, 8 Jul 2020 20:53:22 -0700 Subject: [PATCH 3/3] PR feedback --- ml-agents/mlagents/trainers/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ml-agents/mlagents/trainers/settings.py b/ml-agents/mlagents/trainers/settings.py index 0bd0941a3e..9b75496ffc 100644 --- a/ml-agents/mlagents/trainers/settings.py +++ b/ml-agents/mlagents/trainers/settings.py @@ -606,7 +606,7 @@ class EnvironmentSettings: @num_envs.validator def validate_num_envs(self, attribute, value): if value > 1 and self.env_path is None: - raise ValueError("--num-envs must be 1 if --env is not set.") + raise ValueError("num_envs must be 1 if env_path is not set.") @attr.s(auto_attribs=True)