From 00f2c3138f9907235c6f622a144acfdfa176e359 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Thu, 9 Jul 2020 09:42:35 -0700 Subject: [PATCH 1/2] don't allow --num-envs >1 with no --env (#4203) * don't allow --num-envs >1 with no --env * changelog * PR feedback --- com.unity.ml-agents/CHANGELOG.md | 2 ++ ml-agents/mlagents/trainers/settings.py | 7 ++++++- .../mlagents/trainers/tests/test_settings.py | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) 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 diff --git a/ml-agents/mlagents/trainers/settings.py b/ml-agents/mlagents/trainers/settings.py index 55ee9b0b63..9b75496ffc 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_path 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 8261a21e4881b6e3bd8ff7f70803fd5e4ee77876 Mon Sep 17 00:00:00 2001 From: Chris Elion Date: Thu, 9 Jul 2020 13:21:02 -0700 Subject: [PATCH 2/2] update changelog --- com.unity.ml-agents/CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index a53e1fcf55..9d458420d7 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -13,8 +13,6 @@ 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 @@ -47,6 +45,8 @@ empty string). (#4155) - Fixed issue with FoodCollector, Soccer, and WallJump when playing with keyboard. (#4147, #4174) - Fixed a crash in StatsReporter when using threaded trainers with very frequent summary writes (#4201) +- `mlagents-learn` will now raise an error immediately if `--num-envs` is greater than 1 without setting the `--env` +argument. (#4203) ## [1.1.0-preview] - 2020-06-10 ### Major Changes