Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't allow --num-envs >1 with no --env #4203

Merged
merged 4 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 6 additions & 1 deletion ml-agents/mlagents/trainers/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
chriselion marked this conversation as resolved.
Show resolved Hide resolved


@attr.s(auto_attribs=True)
class EngineSettings:
Expand Down
16 changes: 16 additions & 0 deletions ml-agents/mlagents/trainers/tests/test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
RewardSignalType,
RewardSignalSettings,
CuriositySettings,
EnvironmentSettings,
EnvironmentParameterSettings,
ConstantSettings,
UniformSettings,
Expand Down Expand Up @@ -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)