From e3d658f3a030e7555ea395d61678e5b7c1a71229 Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Fri, 25 Mar 2022 22:08:09 -0400 Subject: [PATCH 1/2] fix neg time --- tianshou/trainer/utils.py | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/tianshou/trainer/utils.py b/tianshou/trainer/utils.py index 9bb841248..585fdf23e 100644 --- a/tianshou/trainer/utils.py +++ b/tianshou/trainer/utils.py @@ -35,8 +35,8 @@ def test_episode( def gather_info( start_time: float, - train_c: Optional[Collector], - test_c: Optional[Collector], + train_collector: Optional[Collector], + test_collector: Optional[Collector], best_reward: float, best_reward_std: float, ) -> Dict[str, Union[float, str]]: @@ -57,20 +57,20 @@ def gather_info( * ``best_reward`` the best reward over the test results; * ``duration`` the total elapsed time. """ - duration = time.time() - start_time + duration = max(0, time.time() - start_time) model_time = duration result: Dict[str, Union[float, str]] = { "duration": f"{duration:.2f}s", "train_time/model": f"{model_time:.2f}s", } - if test_c is not None: - model_time = duration - test_c.collect_time - test_speed = test_c.collect_step / test_c.collect_time + if test_collector is not None: + model_time = max(0, duration - test_collector.collect_time) + test_speed = test_collector.collect_step / test_collector.collect_time result.update( { - "test_step": test_c.collect_step, - "test_episode": test_c.collect_episode, - "test_time": f"{test_c.collect_time:.2f}s", + "test_step": test_collector.collect_step, + "test_episode": test_collector.collect_episode, + "test_time": f"{test_collector.collect_time:.2f}s", "test_speed": f"{test_speed:.2f} step/s", "best_reward": best_reward, "best_result": f"{best_reward:.2f} ± {best_reward_std:.2f}", @@ -78,17 +78,19 @@ def gather_info( "train_time/model": f"{model_time:.2f}s", } ) - if train_c is not None: - model_time -= train_c.collect_time - if test_c is not None: - train_speed = train_c.collect_step / (duration - test_c.collect_time) + if train_collector is not None: + model_time = max(0, model_time - train_collector.collect_time) + if test_collector is not None: + train_speed = train_collector.collect_step / ( + duration - test_collector.collect_time + ) else: - train_speed = train_c.collect_step / duration + train_speed = train_collector.collect_step / duration result.update( { - "train_step": train_c.collect_step, - "train_episode": train_c.collect_episode, - "train_time/collector": f"{train_c.collect_time:.2f}s", + "train_step": train_collector.collect_step, + "train_episode": train_collector.collect_episode, + "train_time/collector": f"{train_collector.collect_time:.2f}s", "train_time/model": f"{model_time:.2f}s", "train_speed": f"{train_speed:.2f} step/s", } From d46a69380404ec9c5aa96033f83dcde4e1d613a9 Mon Sep 17 00:00:00 2001 From: Jiayi Weng Date: Fri, 25 Mar 2022 22:16:54 -0400 Subject: [PATCH 2/2] fix jinjia2 issue https://github.com/sphinx-doc/sphinx/issues/10291 --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index f462f5572..e81d01a36 100644 --- a/setup.py +++ b/setup.py @@ -30,6 +30,7 @@ def get_extras_require() -> str: "dev": [ "sphinx<4", "sphinx_rtd_theme", + "jinja2<3.1", # temporary fix "sphinxcontrib-bibtex", "flake8", "flake8-bugbear",