Skip to content

Commit

Permalink
[Doc] Add notebook
Browse files Browse the repository at this point in the history
Signed-off-by: Matteo Bettini <[email protected]>
  • Loading branch information
matteobettini committed Oct 7, 2023
1 parent af95bcb commit 0b56e32
Show file tree
Hide file tree
Showing 3 changed files with 263 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
python benchmarl/run.py algorithm=mappo task=vmas/balance
```

[![Examples](https://img.shields.io/badge/Examples-blue.svg)](examples)
[![Examples](https://img.shields.io/badge/Examples-blue.svg)](examples) [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/facebookresearch/BenchMARL/blob/main/notebooks/run.ipynb)
<!--
[![Static Badge](https://img.shields.io/badge/Benchmarks-Wandb-yellow)]()
-->
Expand Down Expand Up @@ -44,6 +44,7 @@ statistically strong evaluations.
## How to use

### Notebooks
- [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/facebookresearch/BenchMARL/blob/main/notebooks/run.ipynb) &ensp; **Running BenchMARL experiments**.

### Install

Expand Down
2 changes: 1 addition & 1 deletion examples/running/run_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# Loads from "benchmarl/conf/experiment/base_experiment.yaml"
experiment_config = ExperimentConfig.get_from_yaml()

# Loads from "benchmarl/conf/task"
# Loads from "benchmarl/conf/task/vmas"
tasks = [VmasTask.BALANCE.get_from_yaml(), VmasTask.SAMPLING.get_from_yaml()]

# Loads from "benchmarl/conf/algorithm"
Expand Down
260 changes: 260 additions & 0 deletions notebooks/run.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,260 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "20326118",
"metadata": {},
"source": [
"# Install"
]
},
{
"cell_type": "markdown",
"id": "2422f32f",
"metadata": {},
"source": [
"## Install BenchMARL"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b10fd32",
"metadata": {},
"outputs": [],
"source": [
"#@title\n",
"!git clone https://github.com/facebookresearch/BenchMARL"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6cd7b69b",
"metadata": {},
"outputs": [],
"source": [
"#@title\n",
"%cd /content/BenchMARL"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4f32b88e",
"metadata": {},
"outputs": [],
"source": [
"#@title\n",
"!pip install -e ."
]
},
{
"cell_type": "markdown",
"id": "585d3a35",
"metadata": {},
"source": [
"## Install VMAS"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d2e551b1",
"metadata": {},
"outputs": [],
"source": [
"#@title\n",
"!pip install vmas"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "33d72783",
"metadata": {},
"outputs": [],
"source": [
"#@title\n",
"!apt-get update\n",
"!apt-get install -y x11-utils \n",
"!apt-get install -y xvfb\n",
"!apt-get install -y imagemagick\n",
"!pip install pyvirtualdisplay\n",
"import pyvirtualdisplay\n",
"display = pyvirtualdisplay.Display(visible=False, size=(1400, 900))\n",
"display.start()"
]
},
{
"cell_type": "markdown",
"id": "caa7225f",
"metadata": {},
"source": [
"# Launch from command line"
]
},
{
"cell_type": "markdown",
"id": "30075032",
"metadata": {},
"source": [
"To launch an experiment from the command line you can do"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5369898f",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"!python benchmarl/run.py algorithm=mappo task=vmas/balance experiment.max_n_iters=2 \"experiment.loggers=[]\""
]
},
{
"cell_type": "markdown",
"id": "23f9338f",
"metadata": {},
"source": [
"You can run benchmarks as multi-runs like"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "90a135ea",
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"!python benchmarl/run.py -m algorithm=mappo,qmix,masac task=vmas/balance,vmas/sampling seed=0,1 experiment.max_n_iters=2 \"experiment.loggers=[]\""
]
},
{
"cell_type": "markdown",
"id": "0b01091a",
"metadata": {},
"source": [
"# Launch from a python script"
]
},
{
"cell_type": "markdown",
"id": "67c6dc69",
"metadata": {},
"source": [
"You can also load and launch your experiments from within a script"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2c5b5fcd",
"metadata": {},
"outputs": [],
"source": [
"from benchmarl.algorithms import MappoConfig\n",
"from benchmarl.environments import VmasTask\n",
"from benchmarl.experiment import Experiment, ExperimentConfig\n",
"from benchmarl.models.mlp import MlpConfig\n",
"\n",
"# Loads from \"benchmarl/conf/experiment/base_experiment.yaml\"\n",
"experiment_config = ExperimentConfig.get_from_yaml()\n",
"# Loads from \"benchmarl/conf/task/vmas/balance.yaml\"\n",
"task = VmasTask.BALANCE.get_from_yaml()\n",
"# Loads from \"benchmarl/conf/algorithm/mappo.yaml\"\n",
"algorithm_config = MappoConfig.get_from_yaml()\n",
"# Loads from \"benchmarl/conf/model/layers/mlp.yaml\"\n",
"model_config = MlpConfig.get_from_yaml()\n",
"critic_model_config = MlpConfig.get_from_yaml()\n",
"\n",
"experiment_config.max_n_iters = 2\n",
"experiment_config.loggers = []\n",
"\n",
"experiment = Experiment(\n",
" task=task,\n",
" algorithm_config=algorithm_config,\n",
" model_config=model_config,\n",
" critic_model_config=critic_model_config,\n",
" seed=0,\n",
" config=experiment_config,\n",
")\n",
"experiment.run()"
]
},
{
"cell_type": "markdown",
"id": "a20864e3",
"metadata": {},
"source": [
"You can also run multiple experiments in a Benchmark."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6ec3bd4b",
"metadata": {},
"outputs": [],
"source": [
"from benchmarl.algorithms import MappoConfig, MasacConfig, QmixConfig\n",
"from benchmarl.benchmark import Benchmark\n",
"from benchmarl.environments import VmasTask\n",
"from benchmarl.experiment import ExperimentConfig\n",
"from benchmarl.models.mlp import MlpConfig\n",
"\n",
"# Loads from \"benchmarl/conf/experiment/base_experiment.yaml\"\n",
"experiment_config = ExperimentConfig.get_from_yaml()\n",
"# Loads from \"benchmarl/conf/task/vmas\"\n",
"tasks = [VmasTask.BALANCE.get_from_yaml(), VmasTask.SAMPLING.get_from_yaml()]\n",
"# Loads from \"benchmarl/conf/algorithm\"\n",
"algorithm_configs = [\n",
" MappoConfig.get_from_yaml(),\n",
" QmixConfig.get_from_yaml(),\n",
" MasacConfig.get_from_yaml(),\n",
"]\n",
"# Loads from \"benchmarl/conf/model/layers\"\n",
"model_config = MlpConfig.get_from_yaml()\n",
"critic_model_config = MlpConfig.get_from_yaml()\n",
"\n",
"experiment_config.max_n_iters = 2\n",
"experiment_config.loggers = []\n",
"\n",
"benchmark = Benchmark(\n",
" algorithm_configs=algorithm_configs,\n",
" tasks=tasks,\n",
" seeds={0, 1},\n",
" experiment_config=experiment_config,\n",
" model_config=model_config,\n",
" critic_model_config=critic_model_config,\n",
")\n",
"benchmark.run_sequential()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 0b56e32

Please sign in to comment.