这是indexloc提供的服务,不要输入任何密码
Skip to content

Enhanced rliable eval #1183

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

Merged
merged 16 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ v_s_
obs
obs_next
dtype
iqm
kwarg
entrypoint
interquantile
init
Expand Down
31 changes: 28 additions & 3 deletions examples/mujoco/mujoco_ppo_hl_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""

import os
import warnings

import torch

Expand All @@ -38,16 +39,25 @@

def main(
num_experiments: int = 5,
run_experiments_sequentially: bool = False,
run_experiments_sequentially: bool = True,
logger_type: str = "wandb",
) -> RLiableExperimentResult:
""":param num_experiments: the number of experiments to run. The experiments differ exclusively in the seeds.
:param run_experiments_sequentially: if True, the experiments are run sequentially, otherwise in parallel.
If a single experiment is set to use all available CPU cores,
it might be undesired to run multiple experiments in parallel on the same machine,
:param logger_type: the type of logger to use. Currently, "wandb" and "tensorboard" are supported.
:return: an object containing rliable-based evaluation results
"""
if not run_experiments_sequentially and logger_type == "wandb":
warnings.warn(
"Parallel execution with wandb logger is still under development. Falling back to tensorboard.",
)
logger_type = "tensorboard"

task = "Ant-v4"
persistence_dir = os.path.abspath(os.path.join("log", task, "ppo", datetime_tag()))
tag = datetime_tag()
persistence_dir = os.path.abspath(os.path.join("log", task, "ppo", tag))

experiment_config = ExperimentConfig(persistence_base_dir=persistence_dir, watch=False)

Expand All @@ -72,6 +82,21 @@ def main(

hidden_sizes = (64, 64)

match logger_type:
case "wandb":
job_type = f"ppo/{tag}"
logger_factory = LoggerFactoryDefault(
logger_type="wandb",
wandb_project="tianshou",
group=task,
job_type=job_type,
save_interval=1,
)
case "tensorboard":
logger_factory = LoggerFactoryDefault("tensorboard")
case _:
raise ValueError(f"Unknown logger type: {logger_type}")

experiment_collection = (
PPOExperimentBuilder(env_factory, experiment_config, sampling_config)
.with_ppo_params(
Expand All @@ -95,7 +120,7 @@ def main(
)
.with_actor_factory_default(hidden_sizes, torch.nn.Tanh, continuous_unbounded=True)
.with_critic_factory_default(hidden_sizes, torch.nn.Tanh)
.with_logger_factory(LoggerFactoryDefault("tensorboard"))
.with_logger_factory(logger_factory)
.build_seeded_collection(num_experiments)
)

Expand Down
2 changes: 2 additions & 0 deletions tianshou/data/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class SequenceSummaryStats(DataclassPPrintMixin):

@classmethod
def from_sequence(cls, sequence: Sequence[float | int] | np.ndarray) -> "SequenceSummaryStats":
if len(sequence) == 0:
return cls(mean=0.0, std=0.0, max=0.0, min=0.0)
return cls(
mean=float(np.mean(sequence)),
std=float(np.std(sequence)),
Expand Down
11 changes: 5 additions & 6 deletions tianshou/evaluation/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,11 @@ def _launch(self, experiments: Sequence[Experiment]) -> list[InfoStats | None]:
successful_exp_stats = []
failed_exps = []
for exp in experiments:
for exp in experiments:
exp_stats = self._safe_execute(exp)
if exp_stats == "failed":
failed_exps.append(exp)
else:
successful_exp_stats.append(exp_stats)
exp_stats = self._safe_execute(exp)
if exp_stats == "failed":
failed_exps.append(exp)
else:
successful_exp_stats.append(exp_stats)
# noinspection PyTypeChecker
return self._return_from_successful_and_failed_exps(successful_exp_stats, failed_exps)

Expand Down
Loading