Home

Awesome

<div align="center">

<img src=docs/source/images/logo1.png width=75% />

</div> <h1 align="center"> MARLlib: A Multi-agent Reinforcement Learning Library </h1> <div align="center">

<img src=docs/source/images/allenv.gif width=99% />

</div>

GitHub license coverage Documentation Status GitHub issues PyPI version Open In Colab Organization Organization Awesome

:exclamation: News
March 2023 :anchor:We are excited to announce that a major update has just been released. For detailed version information, please refer to the version info.
May 2023 Exciting news! MARLlib now supports five more tasks: MATE, GoBigger, Overcooked-AI, MAPDN, and AirCombat. Give them a try!
June 2023 OpenAI: Hide and Seek and SISL environments are incorporated into MARLlib.
Aug 2023 :tada:MARLlib has been accepted for publication in JMLR.
Sept 2023 Latest PettingZoo with Gymnasium are compatiable within MARLlib.
Nov 2023 We are currently in the process of creating a hands-on MARL book and aim to release the draft by the end of 2023.

Multi-agent Reinforcement Learning Library (MARLlib) is a MARL library that utilizes Ray and one of its toolkits RLlib. It offers a comprehensive platform for developing, training, and testing MARL algorithms across various tasks and environments.

Here's an example of how MARLlib can be used:

from marllib import marl

# prepare env
env = marl.make_env(environment_name="mpe", map_name="simple_spread", force_coop=True)

# initialize algorithm with appointed hyper-parameters
mappo = marl.algos.mappo(hyperparam_source='mpe')

# build agent model based on env + algorithms + user preference
model = marl.build_model(env, mappo, {"core_arch": "mlp", "encode_layer": "128-256"})

# start training
mappo.fit(env, model, stop={'timesteps_total': 1000000}, share_policy='group')

Why MARLlib?

Here we provide a table for the comparison of MARLlib and existing work.

LibrarySupported EnvAlgorithmParameter SharingModel
PyMARL1 cooperative5shareGRU
PyMARL22 cooperative11shareMLP + GRU
MAPPO Benchmark4 cooperative1share + separateMLP + GRU
MAlib4 self-play10share + group + separateMLP + LSTM
EPyMARL4 cooperative9share + separateGRU
HARL8 cooperative9share + separateMLP + CNN + GRU
MARLlib17 no task mode restriction18share + group + separate + customizableMLP + CNN + GRU + LSTM
LibraryGithub StarsDocumentationIssues OpenActivityLast Update
PyMARLGitHub stars:x:GitHub opened issueGitHub commit-activityGitHub last commit
PyMARL2GitHub stars:x:GitHub opened issueGitHub commit-activityGitHub last commit
MAPPO BenchmarkGitHub stars:x:GitHub opened issueGitHub commit-activityGitHub last commit
MAlibGitHub starsDocumentation StatusGitHub opened issueGitHub commit-activityGitHub last commit
EPyMARLGitHub stars:x:GitHub opened issueGitHub commit-activityGitHub last commit
HARL*GitHub stars:x:GitHub opened issueGitHub commit-activityGitHub last commit
MARLlibGitHub starsDocumentation StatusGitHub opened issueGitHub commit-activityGitHub last commit

* HARL is the latest MARL library that has been recently released:fire:. If cutting-edge MARL algorithms with state-of-the-art performance are your target, HARL is definitely worth a look!

key features

:beginner: MARLlib offers several key features that make it stand out:

:rocket: Using MARLlib, you can take advantage of various benefits, such as:

Installation

Note: Please note that at this time, MARLlib is only compatible with Linux operating systems.

Step-by-step (recommended)

1. install dependencies (basic)

First, install MARLlib dependencies to guarantee basic usage. following this guide, finally install patches for RLlib.

$ conda create -n marllib python=3.8 # or 3.9
$ conda activate marllib
$ git clone https://github.com/Replicable-MARL/MARLlib.git && cd MARLlib
$ pip install -r requirements.txt

2. install environments (optional)

Please follow this guide.

Note: We recommend the gym version around 0.20.0.

pip install "gym==0.20.0"

3. install patches (basic)

Fix bugs of RLlib using patches by running the following command:

$ cd /Path/To/MARLlib/marllib/patch
$ python add_patch.py -y

PyPI

$ pip install --upgrade pip
$ pip install marllib

Docker-based usage

We provide a Dockerfile for building the MARLlib docker image in MARLlib/docker/Dockerfile and a devcontainer setup in MARLlib/.devcontainer folder. If you use the devcontainer, one thing to note is that you may need to customise certain arguments in runArgs of devcontainer.json according to your hardware, for example the --shm-size argument.

Getting started

<details> <summary><b><big>Prepare the configuration</big></b></summary>

There are four parts of configurations that take charge of the whole training process.

<div align="center"> <img src=docs/source/images/configurations.png width=100% /> </div>

Before training, ensure all the parameters are set correctly, especially those you don't want to change.

Note: You can also modify all the pre-set parameters via MARLLib API.*

</details> <details> <summary><b><big>Register the environment</big></b></summary>

Ensure all the dependencies are installed for the environment you are running with. Otherwise, please refer to MARLlib documentation.

task modeapi example
cooperativemarl.make_env(environment_name="mpe", map_name="simple_spread", force_coop=True)
collaborativemarl.make_env(environment_name="mpe", map_name="simple_spread")
competitivemarl.make_env(environment_name="mpe", map_name="simple_adversary")
mixedmarl.make_env(environment_name="mpe", map_name="simple_crypto")

Most of the popular environments in MARL research are supported by MARLlib:

Env NameLearning ModeObservabilityAction SpaceObservations
LBFcooperative + collaborativeBothDiscrete1D
RWAREcooperativePartialDiscrete1D
MPEcooperative + collaborative + mixedBothBoth1D
SISLcooperative + collaborativeFullBoth1D
SMACcooperativePartialDiscrete1D
MetaDrivecollaborativePartialContinuous1D
MAgentcollaborative + mixedPartialDiscrete2D
Pommermancollaborative + competitive + mixedBothDiscrete2D
MAMuJoCocooperativeFullContinuous1D
GRFcollaborative + mixedFullDiscrete2D
HanabicooperativePartialDiscrete1D
MATEcooperative + mixedPartialBoth1D
GoBiggercooperative + mixedBothContinuous1D
Overcooked-AIcooperativeFullDiscrete1D
PDNcooperativePartialContinuous1D
AirCombatcooperative + mixedPartialMultiDiscrete1D
HideAndSeekcompetitive + mixedPartialMultiDiscrete1D

Each environment has a readme file, standing as the instruction for this task, including env settings, installation, and important notes.

</details> <details> <summary><b><big>Initialize the algorithm</big></b></summary>
running targetapi example
train & finetunemarl.algos.mappo(hyperparam_source=$ENV)
develop & debugmarl.algos.mappo(hyperparam_source="test")
3rd party envmarl.algos.mappo(hyperparam_source="common")

Here is a chart describing the characteristics of each algorithm:

algorithmsupport task modediscrete actioncontinuous actionpolicy type
IQL*all four:heavy_check_mark:off-policy
PGall four:heavy_check_mark::heavy_check_mark:on-policy
A2Call four:heavy_check_mark::heavy_check_mark:on-policy
DDPGall four:heavy_check_mark:off-policy
TRPOall four:heavy_check_mark::heavy_check_mark:on-policy
PPOall four:heavy_check_mark::heavy_check_mark:on-policy
COMAall four:heavy_check_mark:on-policy
MADDPGall four:heavy_check_mark:off-policy
MAA2C*all four:heavy_check_mark::heavy_check_mark:on-policy
MATRPO*all four:heavy_check_mark::heavy_check_mark:on-policy
MAPPOall four:heavy_check_mark::heavy_check_mark:on-policy
HATRPOcooperative:heavy_check_mark::heavy_check_mark:on-policy
HAPPOcooperative:heavy_check_mark::heavy_check_mark:on-policy
VDNcooperative:heavy_check_mark:off-policy
QMIXcooperative:heavy_check_mark:off-policy
FACMACcooperative:heavy_check_mark:off-policy
VDACcooperative:heavy_check_mark::heavy_check_mark:on-policy
VDPPO*cooperative:heavy_check_mark::heavy_check_mark:on-policy

*all four: cooperative collaborative competitive mixed

IQL is the multi-agent version of Q learning. MAA2C and MATRPO are the centralized version of A2C and TRPO. VDPPO is the value decomposition version of PPO.

</details> <details> <summary><b><big>Build the agent model</big></b></summary>

An agent model consists of two parts, encoder and core arch. encoder will be constructed by MARLlib according to the observation space. Choose mlp, gru, or lstm as you like to build the complete model.

model archapi example
MLPmarl.build_model(env, algo, {"core_arch": "mlp")
GRUmarl.build_model(env, algo, {"core_arch": "gru"})
LSTMmarl.build_model(env, algo, {"core_arch": "lstm"})
Encoder Archmarl.build_model(env, algo, {"core_arch": "gru", "encode_layer": "128-256"})
</details> <details> <summary><b><big>Kick off the training</big></b></summary>
settingapi example
trainalgo.fit(env, model)
debugalgo.fit(env, model, local_mode=True)
stop conditionalgo.fit(env, model, stop={'episode_reward_mean': 2000, 'timesteps_total': 10000000})
policy sharingalgo.fit(env, model, share_policy='all') # or 'group' / 'individual'
save modelalgo.fit(env, model, checkpoint_freq=100, checkpoint_end=True)
GPU acceleratealgo.fit(env, model, local_mode=False, num_gpus=1)
CPU acceleratealgo.fit(env, model, local_mode=False, num_workers=5)
</details> <details> <summary><b><big>Training & rendering API</big></b></summary>
from marllib import marl

# prepare env
env = marl.make_env(environment_name="smac", map_name="5m_vs_6m")
# initialize algorithm with appointed hyper-parameters
mappo = marl.algos.mappo(hyperparam_source="smac")
# build agent model based on env + algorithms + user preference
model = marl.build_model(env, mappo, {"core_arch": "gru", "encode_layer": "128-256"})
# start training
mappo.fit(
  env, model, 
  stop={"timesteps_total": 1000000}, 
  checkpoint_freq=100, 
  share_policy="group"
)
# rendering
mappo.render(
  env, model, 
  local_mode=True, 
  restore_path={'params_path': "checkpoint/params.json",
                'model_path': "checkpoint/checkpoint-10"}
)
</details>

Results

Under the current working directory, you can find all the training data (logging and TensorFlow files) as well as the saved models. To visualize the learning curve, you can use Tensorboard. Follow the steps below:

  1. Install Tensorboard by running the following command:
pip install tensorboard
  1. Use the following command to launch Tensorboard and visualize the results:
tensorboard --logdir .

Alternatively, you can refer to this tutorial for more detailed instructions.

For a list of all the existing results, you can visit this link. Please note that these results were obtained from an older version of MARLlib, which may lead to inconsistencies when compared to the current results.

Quick examples

MARLlib provides some practical examples for you to refer to.

Tutorials

Try MPE + MAPPO examples on Google Colaboratory! Open In Colab More tutorial documentations are available here.

Awesome List

A collection of research and review papers of multi-agent reinforcement learning (MARL) is available. The papers have been organized based on their publication date and their evaluation of the corresponding environments.

Algorithms: Awesome Environments: Awesome

Community

ChannelLink
IssuesGitHub Issues

Roadmap

The roadmap to the future release is available in ROADMAP.md.

Contributing

We are a small team on multi-agent reinforcement learning, and we will take all the help we can get! If you would like to get involved, here is information on contribution guidelines and how to test the code locally.

You can contribute in multiple ways, e.g., reporting bugs, writing or translating documentation, reviewing or refactoring code, requesting or implementing new features, etc.

Citation

If you use MARLlib in your research, please cite the MARLlib paper.

@article{hu2022marllib,
  author  = {Siyi Hu and Yifan Zhong and Minquan Gao and Weixun Wang and Hao Dong and Xiaodan Liang and Zhihui Li and Xiaojun Chang and Yaodong Yang},
  title   = {MARLlib: A Scalable and Efficient Multi-agent Reinforcement Learning Library},
  journal = {Journal of Machine Learning Research},
  year    = {2023},
}

Works that are based on or closely collaborate with MARLlib <link>

@InProceedings{hu2022policy,
      title={Policy Diagnosis via Measuring Role Diversity in Cooperative Multi-agent {RL}},
      author={Hu, Siyi and Xie, Chuanlong and Liang, Xiaodan and Chang, Xiaojun},
      booktitle={Proceedings of the 39th International Conference on Machine Learning},
      year={2022},
}
@misc{zhong2023heterogeneousagent,
      title={Heterogeneous-Agent Reinforcement Learning}, 
      author={Yifan Zhong and Jakub Grudzien Kuba and Siyi Hu and Jiaming Ji and Yaodong Yang},
      archivePrefix={arXiv},
      year={2023},
}