Skip to main content

Reinforcement learning made easy with prebuilt agents, Gym integration, and performance visualization.

Project description


ReLab is a powerful and user-friendly library designed to streamline reinforcement learning experiments. With a curated collection of well-known RL agents and seamless integration with Gym environments, ReLab empowers you to train agents effortlessly, visualize their learned behaviors, and compare their performance across diverse metrics. Whether you're a researcher exploring state-of-the-art algorithms or a practitioner fine-tuning agents for real-world applications, ReLab simplifies the process, saving you time and effort.

Installation

Install Poetry

Linux, macOS, Windows (WSL):

curl -sSL https://install.python-poetry.org | python3 -

Windows (Powershell)

(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | py -

Install ReLab and its dependencies

Clone the ReLab repository:

git clone git@github.com:TheophileChampion/ReLab.git
cd ReLab

Install ReLab's package and its dependencies inside a virtual environment:

poetry install

Check that the installation was successful:

poetry run test_install

ReLab Fundamentals

ReLab provides a collection of well-known reinforcement learning agents and enables you to train them on any Gym environment. You can then visualize the learned policies and compare the performance of various agents. Before proceeding with the following sections, make sure that ReLab is installed and activate the virtual environment using the following command:

source ./.venv/bin/activate

Training an Agent

An agent can be trained by running the following command:

poetry run training --agent DQN --env ALE/Pong-v5 --seed 0

The training script accepts three parameters:

  • --agent specifies the reinforcement learning agent to train,
  • --env defines the environment in which the agent will be trained, and
  • --seed sets the random seed to ensure reproducibility.

As the agent is learning, you can visualize its performance using the following command:

tensorboard --logdir=./data/runs/

This will open a graphical interface at http://localhost:6006/, allowing you to monitor:

  • the agent's mean episodic reward,
  • the training speed (in milliseconds per training iteration), and
  • the memory usage of the training script.

Visualizing a Learned Policy

By default, ReLab saves the learned policy every 500,000 training iterations. Once an agent has been trained, you can visualize its learned policy using the following command:

poetry run demo --agent DQN --env ALE/Pong-v5 --seed 0

These parameters should look familiar, as they are identical to those used in the training script. By default, ReLab demonstrates the latest policy. However, you can specify a particular model checkpoint using the following command:

poetry run demo --agent DQN --env ALE/Pong-v5 --seed 0 --index 1000000

Here, the --index parameter allows you to select the policy learned by the agent after 1,000,000 training iterations. After running the above command, ReLab will generate a GIF of the agent's behavior, which can be found in:

./data/demos/Pong-v5/DQN/0/demo_1000000.gif

Comparing the Performance of Various Agents

ReLab also provides a script to generate graphs summarizing the agent performance:

poetry run draw_graph --agents DQN --env ALE/Pong-v5 --seeds 0 --metric mean_episodic_reward

Importantly, the parameters --agents and --seeds are now plural because the script accepts a list of agents and seeds. The --metric parameter allows you to compare agents based on various metrics, such as episodic mean reward, training speed, or memory usage. This script can also be used to compare multiple agents across different seeds, as shown below:

poetry run draw_graph --agents DQN RainbowDQN --env ALE/Pong-v5 --seeds 0 1 2 3 4 --metric mean_episodic_reward

When multiple seeds are provided, the graph will display a solid line representing the average metric, along with a shaded area indicating the metric's standard deviation.

For a deeper dive into advanced use cases of ReLab and additional examples, check out our In-Depth Tutorial.

Documentation

ReLab documentation is based on doxygen and hosted with GitHub Pages.

Releases and Contributing

Please let us know if you encounter a bug by filing an issue.

ReLab follows a "fork and pull request" workflow. If you are planning to contribute, you must:

  • Fork ReLab to your GitHub account
  • Clone your fork on your computer
  • Create a new branch to work on
  • Make changes and commit them with a clear description
  • Push your branch to your forked GitHub repository
  • Open a pull request to the ReLab project

ReLab is still in beta. The latest version of ReLab is version 1.0.0-b.

License

ReLab has a MIT license, as found in the license file.

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

relab-0.5.3.tar.gz (81.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

relab-0.5.3-cp312-cp312-manylinux_2_39_x86_64.whl (544.0 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

File details

Details for the file relab-0.5.3.tar.gz.

File metadata

  • Download URL: relab-0.5.3.tar.gz
  • Upload date:
  • Size: 81.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-51-generic

File hashes

Hashes for relab-0.5.3.tar.gz
Algorithm Hash digest
SHA256 7c48167a504391167a26f9420e12e491f3ceb40c1f1ba1feac66b91af04be880
MD5 a0a333c188e6dc4f1087c65064f7ca08
BLAKE2b-256 21f236e01d29340766569995d8c4a71a2dbf7738a0159555f763a819aed29f9c

See more details on using hashes here.

File details

Details for the file relab-0.5.3-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: relab-0.5.3-cp312-cp312-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 544.0 kB
  • Tags: CPython 3.12, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.3 Linux/6.8.0-51-generic

File hashes

Hashes for relab-0.5.3-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 8130b2d72156656c33384b0e27dc95c84fbeafde123f0e760d0a7de089d00d14
MD5 0155b7809cf11a73af05a5292f63e20f
BLAKE2b-256 f27e740224a9fa2c5e839cb41d0a040fe88c17b220170307f979b4c62a80dfe4

See more details on using hashes here.

Supported by

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