Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
KornbergFresnel committed May 10, 2021
1 parent 88368b0 commit 3982db1
Show file tree
Hide file tree
Showing 171 changed files with 18,086 additions and 1 deletion.
26 changes: 26 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#.PHONY: test-training-agent-interface
#test-training-agent-interface:
# PYTHONHASHSEED=24 pytest -v
#
#.PHONY: test-learning
#test-learning:
#
#.PHONY: profiling
#profiling:

.PHONY: clean
clean:
rm -rf ./logs/*

.PHONY: format
format:
# pip install black==20.8b1
black .

.PHONY: docs
docs:
(cd docs; make clean html)

.PHONY: rm-pycache
rm-pycache:
find . -type f -name '*.py[co]' -delete -o -type d -name __pycache__ -delete
64 changes: 63 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,64 @@
# malib
# MALib
A general-purpose multi-agent training framework.

## Installation

**step1: build environment**

```shell
conda create -n malib python==3.7 -y
conda activate malib
pip install -e .

# for development
pip install -e .[dev]
```
**step2: install openspiel**

installation guides: [openspiel](https://github.com/deepmind/open_spiel)

## Quick Start

```python
"""PSRO with PPO for Leduc Holdem"""

from malib.envs.poker import poker_aec_env as leduc_holdem
from malib.runner import run
from malib.rollout import rollout_func


env = leduc_holdem.env(fixed_player=True)

run(
agent_mapping_func=lambda agent_id: agent_id,
env_description={
"creator": leduc_holdem.env,
"config": {"fixed_player": True},
"id": "leduc_holdem",
"possible_agents": env.possible_agents,
},
training={
"interface": {
"type": "independent",
"observation_spaces": env.observation_spaces,
"action_spaces": env.action_spaces
},
},
algorithms={
"PSRO_PPO": {
"name": "PPO",
"custom_config": {
"gamma": 1.0,
"eps_min": 0,
"eps_max": 1.0,
"eps_decay": 100,
},
}
},
rollout={
"type": "async",
"stopper": "simple_rollout",
"callback": rollout_func.sequential
}
)
```
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

if "%1" == "" goto help

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
7 changes: 7 additions & 0 deletions docs/source/api/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MALib
=====

.. toctree::
:maxdepth: 2

malib
85 changes: 85 additions & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Path setup --------------------------------------------------------------

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import os
import sys
import inspect
import shutil


__location__ = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)

sys.path.insert(0, __location__)


# -- Project information -----------------------------------------------------

project = "MALib"
copyright = "2021, SJTU-MARL"
author = "SJTU-MARL"

# The full version, including alpha/beta/rc tags
release = "v0.1.0"


# -- General configuration ---------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
"sphinx_rtd_theme", # theme
"sphinx.ext.autodoc", # automatically extract docs from docstrings
"sphinx.ext.coverage", # make coverage generates documentation coverage reports
"sphinx.ext.viewcode", # link to sourcecode from docs
# "sphinx.ext.grahviz", # graphviz
"sphinxcontrib.apidoc",
]

apidoc_module_dir = os.path.join(__location__, "malib")
apidoc_exclude_paths = ["setup.py"]
apidoc_module_first = True
apidoc_extra_args = [
"--force",
"--separate",
"--ext-viewcode",
"--doc-project=MALib",
"--maxdepth=2",
]

exclude_patterns = ["tests/", "test*.py", "envs/multiagent_mujoco", "envs/star_craft2"]

# ensure __init__ is always documented
autoclass_content = "both"

# Add any paths that contain templates here, relative to this directory.
templates_path = ["_templates"]

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = []


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'alabaster'
html_theme = "sphinx_rtd_theme"
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ["_static"]
19 changes: 19 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.. MALib documentation master file, created by
sphinx-quickstart on Mon Apr 26 17:29:10 2021.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to MALib's documentation!
=================================

.. toctree::
:maxdepth: 2
:caption: Contents:


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
71 changes: 71 additions & 0 deletions examples/appo_simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import argparse

from pettingzoo.mpe import simple_v2

from malib.runner import run


parser = argparse.ArgumentParser("Async PPO training on mpe environments.")

parser.add_argument("--num_learner", type=int, default=3)
parser.add_argument("--batch_size", type=int, default=64)
parser.add_argument("--num_epoch", type=int, default=100)
parser.add_argument("--algorithm", type=str, default="DQN")
parser.add_argument("--rollout_metric", type=str, default="simple", choices={"simple"})


if __name__ == "__main__":
args = parser.parse_args()
env_config = {
"max_cycles": 25,
}
env = simple_v2.env(**env_config)
possible_agents = env.possible_agents
observation_spaces = env.observation_spaces
action_spaces = env.action_spaces

run(
group="MPE/simple",
name="async_ppo",
worker_config={"worker_num": args.num_learner},
env_description={
"creator": simple_v2.env,
"config": env_config,
"id": "simple_v2",
"possible_agents": possible_agents,
},
agent_mapping_func=lambda agent: [
f"{agent}_async_{i}" for i in range(args.num_learner)
],
training={
"interface": {
"type": "async",
"observation_spaces": observation_spaces,
"action_spaces": action_spaces,
"population_size": -1,
},
"config": {
"update_interval": 1,
"saving_interval": 10,
"batch_size": args.batch_size,
"num_epoch": 100,
},
},
algorithms={
"Async": {"name": args.algorithm},
},
rollout={
"type": "async",
"stopper": "simple_rollout",
"metric_type": args.rollout_metric,
"fragment_length": env_config["max_cycles"],
"num_episodes": 100, # episode for each evaluation/training epoch
"terminate": "any",
"callback": "sequential",
},
global_evaluator={
"name": "generic",
"config": {"stop_metrics": {}},
},
dataset_config={"episode_capacity": 30000},
)
8 changes: 8 additions & 0 deletions examples/configs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# -*- coding:utf-8 -*-
# Create Date: 5/1/21, 3:31 PM
# Author: ming
# ---
# Last Modified: 5/1/21
# Modified By: ming
# ---
# Copyright (c) 2020 MARL @ SJTU
Loading

0 comments on commit 3982db1

Please sign in to comment.