Skip to content

Commit

Permalink
[Example] Made available premade example script
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Bettini <[email protected]>
  • Loading branch information
matteobettini committed Sep 26, 2023
1 parent 944d562 commit fd57ae9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 58 deletions.
12 changes: 4 additions & 8 deletions benchmarl/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@
def hydra_experiment(cfg: DictConfig) -> None:
hydra_choices = HydraConfig.get().runtime.choices
task_name = hydra_choices.task
print(f"\nAlgorithm: {hydra_choices.algorithm}, Task: {task_name}")
algorithm_name = hydra_choices.algorithm

print(f"\nAlgorithm: {algorithm_name}, Task: {task_name}")
print("\nLoaded config:\n")
print(OmegaConf.to_yaml(cfg))

experiment = load_experiment_from_hydra(
cfg,
task_name=task_name,
)
experiment = load_experiment_from_hydra(cfg, task_name=task_name)
experiment.run()


if __name__ == "__main__":
hydra_experiment()

# You can run multiple experiments like so
# python simple_hydra_run.py --multirun algorithm=mappo,qmix,maddpg,masac task=vmas/balance
50 changes: 0 additions & 50 deletions examples/vmas_run.py

This file was deleted.

22 changes: 22 additions & 0 deletions premade_scripts/vmas/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
defaults:
- experiment: base_experiment
- algorithm: mappo
- task: vmas/balance
- model: layers/mlp
- model@critic_model: layers/mlp
- _self_

seed: 0

hydra:
searchpath:
# Tells hydra to add the default benchmarl configuration to its path
- pkg://benchmarl/conf

experiment:
sampling_device: "cuda"
train_device: "cuda"
collected_frames_per_batch: 60_000
n_envs_per_worker: 600
on_policy_minibatch_size: 4096
evaluation_episodes: 200
24 changes: 24 additions & 0 deletions premade_scripts/vmas/vmas_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import hydra
from benchmarl.experiment import Experiment

from benchmarl.hydra_config import load_experiment_from_hydra
from hydra.core.hydra_config import HydraConfig
from omegaconf import DictConfig, OmegaConf


@hydra.main(version_base=None, config_path=".", config_name="config")
def hydra_experiment(cfg: DictConfig) -> None:
hydra_choices = HydraConfig.get().runtime.choices
task_name = hydra_choices.task
algorithm_name = hydra_choices.algorithm

print(f"\nAlgorithm: {algorithm_name}, Task: {task_name}")
print("\nLoaded config:\n")
print(OmegaConf.to_yaml(cfg))

experiment: Experiment = load_experiment_from_hydra(cfg, task_name=task_name)
experiment.run()


if __name__ == "__main__":
hydra_experiment()

0 comments on commit fd57ae9

Please sign in to comment.