浏览代码

Close environment if step raises an exception. (#3043)

* close env manager in finally

* rename to env_manager

* remove obsolete mock checks
/develop
GitHub 5 年前
当前提交
e7bf6fff
共有 3 个文件被更改,包括 6 次插入6 次删除
  1. 9
      ml-agents/mlagents/trainers/learn.py
  2. 2
      ml-agents/mlagents/trainers/tests/test_trainer_controller.py
  3. 1
      ml-agents/mlagents/trainers/trainer_controller.py

9
ml-agents/mlagents/trainers/learn.py


options.time_scale,
options.target_frame_rate,
)
env = SubprocessEnvManager(env_factory, engine_config, options.num_envs)
env_manager = SubprocessEnvManager(env_factory, engine_config, options.num_envs)
curriculum_folder, env, options.lesson
curriculum_folder, env_manager, options.lesson
)
sampler_manager, resampling_interval = create_sampler_manager(
options.sampler_file_path, run_seed

# Signal that environment has been launched.
process_queue.put(True)
# Begin training
tc.start_learning(env)
try:
tc.start_learning(env_manager)
finally:
env_manager.close()
def create_sampler_manager(sampler_file_path, run_seed=None):

2
ml-agents/mlagents/trainers/tests/test_trainer_controller.py


assert tc.advance.call_count == 11
tc._export_graph.assert_not_called()
tc._save_model.assert_not_called()
env_mock.close.assert_called_once()
@patch.object(tf, "reset_default_graph")

tf_reset_graph.assert_called_once()
env_mock.reset.assert_called_once()
assert tc.advance.call_count == trainer_mock.get_max_steps + 1
env_mock.close.assert_called_once()
tc._save_model.assert_called_once()

1
ml-agents/mlagents/trainers/trainer_controller.py


self._write_training_metrics()
self._export_graph()
self._write_timing_tree()
env_manager.close()
def end_trainer_episodes(
self, env: EnvManager, lessons_incremented: Dict[str, bool]

正在加载...
取消
保存