Skip to main content

Implementations of popular Deep Reinforcement Learning algorithms

Project description

rlib

Build Status

rlib is a small deep reinforcement learning library with implementations of popular deep RL algorithms. Each algorithm is highly modular and customizable, making this library a great choice for anyone who wants to test the performance of different algorithms in the same environment. rlib uses PyTorch as the library of choice for its initial version, but support for TensorFlow is on the roadmap.

Installation

pip install rlib

Usage

Using rlib is this simple:

from rlib.algorithms.dqn import DQNAgent
from rlib.environments.gym import GymEnvironment


e = gym.make('CartPole-v0')

observation_size = 4
action_size = 2

dqn = DQNAgent(observation_size, action_size)
env = GymEnvironment(e, dqn)
env.train()
env.test()

Advanced

TensorBoard and GIFRecorder

  1. Initialize Logger and/or GIFRecorder objects.
os.makedirs('your/log/dir', exist_ok=True)

logger = Logger(output_dir)
gifs_recorder = GIFRecorder(output_dir, duration=3.0)
  1. Initialize a new environment using these objects.
env = GymEnvironment(e, dqn, logger=logger, gifs_recorder=gifs_recorder)
  1. To check Tensorboard logs, run:
tensorboard --logdir=your/log/dir

Custom models

  1. Define your own custom model.
class NeuralNet(torch.nn.Module):
    def __init__(self):
        super(NeuralNet, self).__init__()
        self.fc1 = nn.Linear(4, 8) 
        self.relu = nn.ReLU()
        self.fc2 = nn.Linear(8, 2)  

    def forward(self, x):
        out = self.fc1(x)
        out = self.relu(out)
        out = self.fc2(out)
        return out
  1. Check the documentation for the algorithm you are using for the appropriate argument name. For DQN:
dqn = DQNAgent(
    observation_size, action_size,
    qnetwork_local=NeuralNet(),
    qnetwork_target=NeuralNet(),
)

Saving model weights

  1. Set the model_output_dir argument when creating a new instance of an algorithm to the directory where you want your model to be saved.

Testing

To run all tests:

python -m unittest discover test/

Contributing

Installation

Feel free to open issues with any bugs found or any feature requests. Pull requests are always welcome for new functionality.

virtualenv -p python3 venv
cd rlib/
source venv/bin/activate
pip install -r requirements.txt

To make sure your installation worked, run one of the algorithms in the test folder:

python test/algorithms/dqn_test.py

License

rlib is released under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rlib-0.0.2.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

rlib-0.0.2-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file rlib-0.0.2.tar.gz.

File metadata

  • Download URL: rlib-0.0.2.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for rlib-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4715f8f91a80f70c481199b406ad16931324bae0bbe2509ec5f08102d4610704
MD5 0cebd7d4b63b371ee2b83b91a9880feb
BLAKE2b-256 016816d21c4b9b5550d4549945e4cb21f11a3b87f04fcc898c3c8769efc16a09

See more details on using hashes here.

File details

Details for the file rlib-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: rlib-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 37.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.26.0 CPython/3.7.0

File hashes

Hashes for rlib-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7dbe468fb6020e6980479bb9853d7cff999e96862a6013efe8a2b3a5d2477f67
MD5 2cd25487712428f885a47b39cdfd79eb
BLAKE2b-256 06e84d8ef94541cd7e81e4fd597ebc8843dc48e8b7085b1b077d22c6ebc68444

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page