Skip to content

Commit

Permalink
Update: setup, README
Browse files Browse the repository at this point in the history
  • Loading branch information
zuoxingdong committed Aug 5, 2019
1 parent eb4d368 commit 5fb4f14
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 80 deletions.
114 changes: 55 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,89 @@
# lagom
<!--- <img src='doc/img/infrastructure.png' width='300'> --->

[![Build Status](https://travis-ci.org/zuoxingdong/lagom.svg?branch=master)](https://travis-ci.org/zuoxingdong/lagom)
[![CircleCI](https://circleci.com/gh/zuoxingdong/lagom.svg?style=svg)](https://circleci.com/gh/zuoxingdong/lagom)
[![Documentation Status](https://readthedocs.org/projects/lagom/badge/?version=latest)](https://lagom.readthedocs.io/en/latest/?badge=latest)

**lagom is a light PyTorch infrastructure to quickly prototype reinforcement learning algorithms.** [Lagom](https://sv.wikipedia.org/wiki/Lagom) is a 'magic' word in Swedish, *"inte för mycket och inte för lite, enkelhet är bäst"*, meaning *"not too much and not too little, simplicity is often the best"*. lagom is the philosophy on which this library was designed.
<p align='center'>
<a href='https://github.com/zuoxingdong/lagom/'>
<img alt="" src='docs/lagom.png' width="50">
</a>
</p>
<h3 align='center'>
lagom
</h3>
<p align='center'>
A PyTorch infrastructure for rapid prototyping of reinforcement learning algorithms.
</p>
<p align="center">
<a href='https://travis-ci.org/zuoxingdong/lagom'><img src='https://travis-ci.org/zuoxingdong/lagom.svg?branch=master'></a>
<a href='https://circleci.com/gh/zuoxingdong/lagom'><img src='https://circleci.com/gh/zuoxingdong/lagom.svg?style=svg'></a>
<a href='https://lagom.readthedocs.io/en/latest/?badge=latest'><img src='https://readthedocs.org/projects/lagom/badge/?version=latest'></a>
<a href='http://choosealicense.com/licenses/mit/'><img src='https://img.shields.io/badge/License-MIT-blue.svg'></a>
</p>

[lagom](https://sv.wikipedia.org/wiki/Lagom) is a 'magic' word in Swedish, *inte för mycket och inte för lite, enkelhet är bäst* (*not too much and not too little, simplicity is often the best*). It is the philosophy on which this library was designed.

## Why to use lagom ?
`lagom` balances between the flexibility and the usability when developing reinforcement learning (RL) algorithms. The library is built on top of [PyTorch](https://pytorch.org/) and provides modular tools to quickly prototype RL algorithms. However, it does not go overboard, because too low level is often time consuming and prone to potential bugs, while too high level degrades the flexibility which makes it difficult to try out some crazy ideas fast.

**Contents of this document**
We are continuously making `lagom` more 'self-contained' to set up and run experiments quickly. It internally supports base classes for multiprocessing ([master-worker framework](https://en.wikipedia.org/wiki/Master/slave_(technology))) for parallelization (e.g. experiments and evolution strategies). It also supports hyperparameter search by defining configurations either as grid search or random search.

- [Basics](#basics)
**Table of Contents**
- [Installation](#installation)
- [Install dependencies](#install-dependencies)
- [Install lagom](#install-lagom)
- [Getting Started](#getting-started)
- [Install lagom from source](#install-lagom-from-source)
- [Documentation](#documentation)
- [Examples](#examples)
- [RL Baselines](#rl-baselines)
- [How to use lagom](#how-to-use-lagom)
- [Examples](#examples)
- [Test](#test)
- [What's new](#What's-new)
- [Reference](#reference)

# Basics

`lagom` balances between the flexibility and the usability when developing reinforcement learning (RL) algorithms. The library is built on top of [PyTorch](https://pytorch.org/) and provides modular tools to quickly prototype RL algorithms. However, it does not go overboard, because too low level is often time consuming and prone to potential bugs, while too high level degrades the flexibility which makes it difficult to try out some crazy ideas fast.

We are continuously making `lagom` more 'self-contained' to set up and run experiments quickly. It internally supports base classes for multiprocessing ([master-worker framework](https://en.wikipedia.org/wiki/Master/slave_(technology))) for parallelization (e.g. experiments and evolution strategies). It also supports hyperparameter search by defining configurations either as grid search or random search.

A common pipeline to use `lagom` can be done as following:
1. Define your [RL agent](lagom/agent.py)
2. Define your [environment](lagom/envs)
3. Define your [engine](lagom/engine.py) for training and evaluating the agent in the environment.
4. Define your [Configurations](lagom/experiment/config.py) for hyperparameter search
5. Define `run(config, seed, device)` for your experiment pipeline
6. Call `run_experiment(run, config, seeds, num_worker)` to parallelize your experiments

A graphical illustration is coming soon.

# Installation

## Install dependencies
Run the following command to install [all required dependencies](./requirements.txt):

## Installation
We highly recommand using an Miniconda environment:
```bash
pip install -r requirements.txt
conda create -n lagom python=3.7
```

Note that it is highly recommanded to use an Miniconda environment:

### Install dependencies
```bash
conda create -n lagom python=3.7
pip install -r requirements.txt
```

We also provide some bash scripts in [scripts/](scripts/) directory to automatically set up the conda environment and dependencies.

## Install lagom

Run the following commands to install lagom from source:
We also provide some bash scripts in [scripts/](scripts/) directory to automatically set up the system configurations, conda environment and dependencies.

### Install lagom from source
```bash
git clone https://github.com/zuoxingdong/lagom.git
cd lagom
pip install -e .
```

Installing from source allows to flexibly modify and adapt the code as you pleased, this is very convenient for research purpose which often needs fast prototyping.

# Getting Started

Detailed tutorials is coming soon. For now, it is recommended to have a look in [examples/](examples/) or the source code.

# Documentation
Installing from source allows to flexibly modify and adapt the code as you pleased, this is very convenient for research purpose.

## Documentation
The documentation hosted by ReadTheDocs is available online at [http://lagom.readthedocs.io](http://lagom.readthedocs.io)

# Baselines
## RL Baselines
We implemented a collection of standard reinforcement learning algorithms at [baselines](baselines/) using lagom.

We provide a set of implementations of reinforcement learning algorithms at [baselines](baselines/) using lagom.
## How to use lagom
A common pipeline to use `lagom` can be done as following:
1. Define your [RL agent](lagom/agent.py)
2. Define your [environment](lagom/envs)
3. Define your [engine](lagom/engine.py) for training and evaluating the agent in the environment.
4. Define your [Configurations](lagom/experiment/config.py) for hyperparameter search
5. Define `run(config, seed, device)` for your experiment pipeline
6. Call `run_experiment(run, config, seeds, num_worker)` to parallelize your experiments

A graphical illustration is coming soon.

# Test
### Examples
We provide a few simple [examples](examples/).

## Test
We are using [pytest](https://docs.pytest.org) for tests. Feel free to run via

```bash
pytest test -v
```

# What's new

## What's new
- 2019-03-04 (v0.0.3)
- Much easier and cleaner APIs

Expand All @@ -97,15 +94,14 @@ pytest test -v
- 2018-09-20 (v0.0.1)
- Initial release

# Reference

## Reference
This repo is inspired by [OpenAI Gym](https://github.com/openai/gym/), [OpenAI baselines](https://github.com/openai/baselines), [OpenAI Spinning Up](https://github.com/openai/spinningup)

Please use this bibtex if you want to cite this repository in your publications:

@misc{lagom,
author = {Zuo, Xingdong},
title = {lagom: A light PyTorch infrastructure to quickly prototype reinforcement learning algorithms},
title = {lagom: A PyTorch infrastructure for rapid prototyping of reinforcement learning algorithms},
year = {2018},
publisher = {GitHub},
journal = {GitHub repository},
Expand Down
7 changes: 3 additions & 4 deletions lagom/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# Versioning format: (Major, Minor, Maintenance)
version = (0, 0, 2)

__version__ = f'{version[0]}.{version[1]}.{version[2]}'
# Useful for setup.py and when lagom is not installed yet
# Versioning format: Major.Minor.Maintenance
__version__ = '0.0.3'
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ ignore =
exclude =
build, # building files
dist, # building files
legacy, # legacy code for backup only
*.pyc,
__pycache__,
.ipynb_checkpoints
Expand Down
31 changes: 14 additions & 17 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from importlib.machinery import SourceFileLoader
import pkg_resources
from distutils.version import LooseVersion
import re
import codecs

from setuptools import setup
from setuptools import find_packages


# read version directly as variable, not import lagom, because it might not be installed yet
with open('lagom/version.py') as f:
exec(f.read())

# Read long description of README markdown, shows in Python Package Index
with codecs.open('README.md', encoding='utf-8') as f:
long_description = f.read()

# Minimal requried dependencies (full dependencies in requirements.txt)
install_requires = ['numpy',
'scipy',
'gym>=0.13.0',
'gym>=0.14.0',
'cloudpickle',
'pyyaml',
'colored']
Expand All @@ -25,18 +24,20 @@
'sphinx_rtd_theme']

setup(name='lagom',
version=__version__,
version=SourceFileLoader('version', 'lagom/version.py').load_module().__version__,
# List all lagom packages (folder with __init__.py), useful to distribute a release
packages=find_packages(),

install_requires=install_requires,
tests_require=tests_require,
python_requires='>=3',

author='Xingdong Zuo',
author_email='zuoxingdong@hotmail.com',
description='lagom: A light PyTorch infrastructure to quickly prototype reinforcement learning algorithms.',
long_description=long_description,
long_description_content_type='text/markdown',
url='https://github.com/zuoxingdong/lagom',
install_requires=install_requires,
tests_require=tests_require,
python_requires='>=3',
# List all lagom packages (folder with __init__.py), useful to distribute a release
packages=find_packages(),
# tell pip some metadata (e.g. Python version, OS etc.)
classifiers=['Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
Expand All @@ -46,17 +47,13 @@
)


# ensure PyTorch is installed
import pkg_resources
# check PyTorch installation
pkg = None
for name in ['torch', 'torch-nightly']:
try:
pkg = pkg_resources.get_distribution(name)
except pkg_resources.DistributionNotFound:
pass
assert pkg is not None, 'PyTorch is not correctly installed.'

from distutils.version import LooseVersion
import re
version_msg = 'PyTorch of version above 1.0.0 expected'
assert LooseVersion(re.search(r'\d+[.]\d+[.]\d+', pkg.version)[0]) >= LooseVersion('1.0.0'), version_msg

0 comments on commit 5fb4f14

Please sign in to comment.