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.2.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.2-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.2.tar.gz.

File metadata

  • Download URL: relab-0.5.2.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.2.tar.gz
Algorithm Hash digest
SHA256 a11d09c8eab54555a6c910ba5b6f17f7b89040045f338a4bca8ac4db7905181a
MD5 e46da75d602fa6ed0616d620bfdfa3db
BLAKE2b-256 27be9f374afe2906c8c856e6dfb5fa8df122552b2ae0d3822d1366bbd9d2425d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: relab-0.5.2-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.2-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 bcc6601560f7d16f894b3c982ed6fd161f9b01dea5b5199e2aaf63dc700a282b
MD5 e5b6502f5e2d28dd68043069376217e2
BLAKE2b-256 c76e9ca234853684a0b16f788e358b2508a941e05777fb9dfcd33fa82fd952d4

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