Make monitor_gym configurable in WandbLogger. (#896)

At the moment, WandbLogger is always using wandb.init with monitor_gym =
True.
This fails when OpenAI's gym is not installed, which doesn't make sense
after the transition to Gymnasium.

I am using Tianshou with non-standard RL environment, which adhere to
Gymnasium API, and the current code is throwing exceptions.

I suggest to make it a controllable parameter. I left the default value
to True (to make it functionally the same for people using gym). It may
also make sense to change the default to False.
This commit is contained in:
Błażej Osiński 2023-08-10 00:13:25 +02:00 committed by GitHub
parent cd218dc12d
commit 864ee3df2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,6 +54,7 @@ class WandbLogger(BaseLogger):
entity: Optional[str] = None,
run_id: Optional[str] = None,
config: Optional[argparse.Namespace] = None,
monitor_gym: bool = True,
) -> None:
super().__init__(train_interval, test_interval, update_interval)
self.last_save_step = -1
@ -70,7 +71,7 @@ class WandbLogger(BaseLogger):
resume="allow",
entity=entity,
sync_tensorboard=True,
monitor_gym=True,
monitor_gym=monitor_gym,
config=config, # type: ignore
) if not wandb.run else wandb.run
self.wandb_run._label(repo="tianshou") # type: ignore