Code Monkey home page Code Monkey logo

stable-baselines's Introduction

Build Status Documentation Status Codacy Badge Codacy Badge

Stable Baselines

Stable Baselines is a set of improved implementations of reinforcement learning algorithms based on OpenAI Baselines.

You can read a detailed presentation of Stable Baselines in the Medium article.

These algorithms will make it easier for the research community and industry to replicate, refine, and identify new ideas, and will create good baselines to build projects on top of. We expect these tools will be used as a base around which new ideas can be added, and as a tool for comparing a new approach against existing ones. We also hope that the simplicity of these tools will allow beginners to experiment with a more advanced toolset, without being buried in implementation details.

Main differences with OpenAI Baselines

This toolset is a fork of OpenAI Baselines, with a major structural refactoring, and code cleanups:

  • Unified structure for all algorithms
  • PEP8 compliant (unified code style)
  • Documented functions and classes
  • More tests & more code coverage
Features Stable-Baselines OpenAI Baselines
State of the art RL methods ✔️ (1) ✔️
Documentation ✔️
Custom environments ✔️ ✔️
Custom policies ✔️ (2)
Common interface ✔️ (3)
Tensorboard support ✔️ (4)
Ipython / Notebook friendly ✔️
PEP8 code style ✔️ (5)
Custom callback ✔️ (6)

(1): Forked from previous version of OpenAI baselines, however missing refactoring for HER.
(2): Currently not available for DDPG, and only from the run script.
(3): Only via the run script.
(4): Rudimentary logging of training information (no loss nor graph).
(5): WIP on OpenAI's side (you can do it OpenAI! 🐱)
(6): Passing a callback function is only available for DQN

Documentation

Documentation is available online: https://stable-baselines.readthedocs.io/

Installation

Prerequisites

Baselines requires python3 (>=3.5) with the development headers. You'll also need system packages CMake, OpenMPI and zlib. Those can be installed as follows

Ubuntu

sudo apt-get update && sudo apt-get install cmake libopenmpi-dev python3-dev zlib1g-dev

Mac OS X

Installation of system packages on Mac requires Homebrew. With Homebrew installed, run the follwing:

brew install cmake openmpi

Install using pip

Install the Stable Baselines package

Using pip from pypi:

pip install stable-baselines

Please read the documentation for more details and alternatives (from source, using docker).

Example

Most of the library tries to follow a sklearn-like syntax for the Reinforcement Learning algorithms.

Here is a quick example of how to train and run PPO2 on a cartpole environment:

import gym

from stable_baselines.common.policies import MlpPolicy
from stable_baselines.common.vec_env import DummyVecEnv
from stable_baselines import PPO2

env = gym.make('CartPole-v1')
env = DummyVecEnv([lambda: env])  # The algorithms require a vectorized environment to run

model = PPO2(MlpPolicy, env, verbose=1)
model.learn(total_timesteps=10000)

obs = env.reset()
for i in range(1000):
    action, _states = model.predict(obs)
    obs, rewards, dones, info = env.step(action)
    env.render()

Or just train a model with a one liner if the environment is registered in Gym and if the policy is registered:

from stable_baselines import PPO2

model = PPO2('MlpPolicy', 'CartPole-v1').learn(10000)

Please read the documentation for more examples.

Try it online with Colab Notebooks !

All the following examples can be executed online using Google colab notebooks:

Implemented Algorithms

Name Refactored(1) Recurrent Box Discrete MultiDiscrete MultiBinary Multi Processing
A2C ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
ACER ✔️ ✔️ (5) ✔️ ✔️
ACKTR ✔️ ✔️ (5) ✔️ ✔️
DDPG ✔️ ✔️
DQN ✔️ ✔️
GAIL (2) ✔️ ✔️ ✔️ ✔️ (4)
HER (3) (5) ✔️
PPO1 ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ (4)
PPO2 ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
TRPO ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ (4)

(1): Whether or not the algorithm has be refactored to fit the BaseRLModel class.
(2): Only implemented for TRPO.
(3): Only implemented for DDPG.
(4): Multi Processing with MPI.
(5): TODO, in project scope.

Actions gym.spaces:

  • Box: A N-dimensional box that containes every point in the action space.
  • Discrete: A list of possible actions, where each timestep only one of the actions can be used.
  • MultiDiscrete: A list of possible actions, where each timestep only one action of each discrete set can be used.
  • MultiBinary: A list of possible actions, where each timestep any of the actions can be used in any combination.

MuJoCo

Some of the baselines examples use MuJoCo (multi-joint dynamics in contact) physics simulator, which is proprietary and requires binaries and a license (temporary 30-day license can be obtained from www.mujoco.org). Instructions on setting up MuJoCo can be found here

Testing the installation

All unit tests in baselines can be run using pytest runner:

pip install pytest pytest-cov
pytest --cov-config .coveragerc --cov-report html --cov-report term --cov=.

Citing the Project

To cite this repository in publications:

    @misc{stable-baselines,
      author = {Hill, Ashley and Raffin, Antonin and Traore, Rene and Dhariwal, Prafulla and Hesse, Christopher and Klimov, Oleg and Nichol, Alex and Plappert, Matthias and Radford, Alec and Schulman, John and Sidor, Szymon and Wu, Yuhuai},
      title = {Stable Baselines},
      year = {2018},
      publisher = {GitHub},
      journal = {GitHub repository},
      howpublished = {\url{https://github.com/hill-a/stable-baselines}},
    }

Maintainers

Stable-Baselines is currently maintained by Ashley Hill (aka @hill-a) and Antonin Raffin (aka @araffin).

How To Contribute

To any interested in making the baselines better, there is still some documentation that needs to be done. If you want to contribute, please open an issue first and then propose your pull request.

Nice to have (for the future):

  • Continuous actions support for ACER
  • Continuous actions support for ACKTR

Acknowledgments

Stable Baselines was created in the robotics lab U2IS (INRIA Flowers team) at ENSTA ParisTech.

Logo credits: L.M. Tenkes

stable-baselines's People

Contributors

hill-a avatar araffin avatar joschu avatar andrewliao11 avatar siemanko avatar pzhokhov avatar kalifou avatar unixpickle avatar 20chase avatar matthiasplappert avatar shakenes avatar olegklimov avatar louiehelm avatar christopherhesse avatar ngc92 avatar definitelyuncertain avatar cxxgtxy avatar linzichuan avatar zach-nervana avatar ppwwyyxx avatar uidilr avatar yenchenlin avatar tiagosgc avatar stevenschmatz avatar ryanjulian avatar quanvuong avatar welinder avatar omoindrot avatar mirceamironenco avatar mkarutz avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.