From d6e8f094216b8075838c54aacee87455bfcefe42 Mon Sep 17 00:00:00 2001 From: Ervin Teng Date: Fri, 5 Jun 2020 15:13:34 -0700 Subject: [PATCH 1/3] Fix broken --initialize-from feature --- ml-agents/mlagents/trainers/learn.py | 2 +- ml-agents/mlagents/trainers/tests/test_learn.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ml-agents/mlagents/trainers/learn.py b/ml-agents/mlagents/trainers/learn.py index 63af614370..c308881a2f 100644 --- a/ml-agents/mlagents/trainers/learn.py +++ b/ml-agents/mlagents/trainers/learn.py @@ -70,7 +70,7 @@ def run_training(run_seed: int, options: RunOptions) -> None: base_path = "results" write_path = os.path.join(base_path, checkpoint_settings.run_id) maybe_init_path = ( - os.path.join(base_path, checkpoint_settings.run_id) + os.path.join(base_path, checkpoint_settings.initialize_from) if checkpoint_settings.initialize_from else None ) diff --git a/ml-agents/mlagents/trainers/tests/test_learn.py b/ml-agents/mlagents/trainers/tests/test_learn.py index daacc1c4d3..16ea79be1b 100644 --- a/ml-agents/mlagents/trainers/tests/test_learn.py +++ b/ml-agents/mlagents/trainers/tests/test_learn.py @@ -20,6 +20,8 @@ def basic_options(extra_args=None): MOCK_YAML = """ behaviors: {} + checkpoint_settings: + initialize_from: notuselessrun """ MOCK_PARAMETER_YAML = """ @@ -32,6 +34,7 @@ def basic_options(extra_args=None): seed: 9870 checkpoint_settings: run_id: uselessrun + initialize_from: notuselessrun debug: false """ @@ -88,7 +91,9 @@ def test_run_training( sampler_manager_mock.return_value, None, ) - handle_dir_mock.assert_called_once_with("results/ppo", False, False, None) + handle_dir_mock.assert_called_once_with( + "results/ppo", False, False, "results/notuselessrun" + ) write_timing_tree_mock.assert_called_once_with("results/ppo/run_logs") write_run_options_mock.assert_called_once_with("results/ppo", options) StatsReporter.writers.clear() # make sure there aren't any writers as added by learn.py @@ -120,6 +125,7 @@ def test_commandline_args(mock_file): assert opt.checkpoint_settings.resume is False assert opt.checkpoint_settings.inference is False assert opt.checkpoint_settings.run_id == "ppo" + assert opt.checkpoint_settings.initialize_from is None assert opt.env_settings.seed == -1 assert opt.env_settings.base_port == 5005 assert opt.env_settings.num_envs == 1 @@ -136,6 +142,7 @@ def test_commandline_args(mock_file): "--seed=7890", "--train", "--base-port=4004", + "--initialize-from=testdir", "--num-envs=2", "--no-graphics", "--debug", @@ -146,6 +153,7 @@ def test_commandline_args(mock_file): assert opt.env_settings.env_path == "./myenvfile" assert opt.parameter_randomization is None assert opt.checkpoint_settings.run_id == "myawesomerun" + assert opt.checkpoint_settings.initialize_from == "testdir" assert opt.env_settings.seed == 7890 assert opt.env_settings.base_port == 4004 assert opt.env_settings.num_envs == 2 From d1960190a557639e2c5aa63f8f05dd533450fae8 Mon Sep 17 00:00:00 2001 From: Ervin Teng Date: Fri, 5 Jun 2020 17:01:11 -0700 Subject: [PATCH 2/3] Fix test --- ml-agents/mlagents/trainers/tests/test_learn.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ml-agents/mlagents/trainers/tests/test_learn.py b/ml-agents/mlagents/trainers/tests/test_learn.py index 16ea79be1b..19a559f54d 100644 --- a/ml-agents/mlagents/trainers/tests/test_learn.py +++ b/ml-agents/mlagents/trainers/tests/test_learn.py @@ -20,8 +20,6 @@ def basic_options(extra_args=None): MOCK_YAML = """ behaviors: {} - checkpoint_settings: - initialize_from: notuselessrun """ MOCK_PARAMETER_YAML = """ @@ -172,6 +170,7 @@ def test_yaml_args(mock_file): assert opt.env_settings.env_path == "./oldenvfile" assert opt.parameter_randomization is None assert opt.checkpoint_settings.run_id == "uselessrun" + assert opt.checkpoint_settings.initialize_from == "notuselessrun" assert opt.env_settings.seed == 9870 assert opt.env_settings.base_port == 4001 assert opt.env_settings.num_envs == 4 From 9f109367878e6fd20d37f4bc82f18804c92dffdf Mon Sep 17 00:00:00 2001 From: Ervin Teng Date: Fri, 5 Jun 2020 17:04:35 -0700 Subject: [PATCH 3/3] Fix test_learn --- ml-agents/mlagents/trainers/tests/test_learn.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ml-agents/mlagents/trainers/tests/test_learn.py b/ml-agents/mlagents/trainers/tests/test_learn.py index 19a559f54d..5a67036ade 100644 --- a/ml-agents/mlagents/trainers/tests/test_learn.py +++ b/ml-agents/mlagents/trainers/tests/test_learn.py @@ -22,6 +22,13 @@ def basic_options(extra_args=None): {} """ +MOCK_INITIALIZE_YAML = """ + behaviors: + {} + checkpoint_settings: + initialize_from: notuselessrun + """ + MOCK_PARAMETER_YAML = """ behaviors: {} @@ -72,7 +79,7 @@ def test_run_training( mock_env.external_brain_names = [] mock_env.academy_name = "TestAcademyName" create_environment_factory.return_value = mock_env - load_config.return_value = yaml.safe_load(MOCK_YAML) + load_config.return_value = yaml.safe_load(MOCK_INITIALIZE_YAML) mock_init = MagicMock(return_value=None) with patch.object(TrainerController, "__init__", mock_init):