Skip to content
项目

UoA-CARES/cares_reinforcement_learning

在 GitHub 查看

关于

CARES Reinforcement Learning Package

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
0
7天
0
15天
0
1个月
0

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

CARES Reinforcement Learning Logo

A modular reinforcement learning framework for training and evaluating RL algorithms across diverse environments.

Documentation Python GitHub release License: MIT

Introduction

The CARES Reinforcement Learning package is a modular and extensible framework for developing, training, and evaluating reinforcement learning algorithms. It provides a consistent interface across value-based, policy-based, and multi-agent methods, enabling clear comparisons between approaches in a single code base. Designed with research and real-world robotics applications in mind. This code base has been designed for the local team but we feel it has utility beyond our research group and are open to contributions/suggestions from others.

Documentation

Full documentation: https://uoa-cares.github.io/cares_reinforcement_learning/

The docs are split into three main sections:

  • User Guide — how to use the library, run experiments, configure environments, and train agents
  • Developer Guide — how to add algorithms, environments, replay buffers, and contribute to the codebase
  • Learning Reinforcement Learning — conceptual guides covering reinforcement learning fundamentals, algorithm intuition, core theory, and practical understanding of methods used throughout the library.

New users should usually start with the User Guide, while contributors should begin with the Developer Guide.

Installation Instructions

We recommend using the Stable release versions if you are just looking to use the package directly. If you are seeking to develop the package further then follow the Development Environment instructions for installation.

Stable Release v3.0.0 (Recommended)

Clone the latest stable release of CARES Reinforcement Learning.

git clone --branch v3.0.0 https://github.com/UoA-CARES/cares_reinforcement_learning.git

cd cares_reinforcement_learning
pip install -e .[gym]

Clone the main branch for the latest features - note this branch may not be stable as it is the working branch.

Development Environment (UV/pyenv)

We recommend using pyenv to manage Python versions and uv to manage dependencies and work with reproducible environments from papers. This is because we have various other gym packages that can be installed and used and the general pyenv environment is useful to manage them together. This setup should be used those looking to contribute to the code base or various gym packages.

Clone the latest main of CARES Reinforcement Learning.

git clone https://github.com/UoA-CARES/cares_reinforcement_learning.git

1. Install uv and pyenv

Install uv using the official installer:

curl -Ls https://astral.sh/uv/install.sh | sh

Install 'pyenv' using the official installer:

curl -fsSL https://pyenv.run | bash

2. Setup Virtual Environment (pyenv)

Install the required Python version - note you can use 3.12 if you prefer.

pyenv install 3.10
pyenv virtualenv 3.10 cares_rl_310
pyenv activate cares_rl_310

3. Install Requirements (UV)

Install the project and its requirements - note we are using the --active command to work inside of the pyenv environment.

uv sync --active --extra gym

Quick Start

Train a reinforcement learning agent in a Gymnasium environment:

cares-rl train cli --gym openai --task CartPole-v1 DQN

Run training across multiple seeds in parallel

cares-rl train cli --gym openai --task HalfCheetah-v4 TD3 --seeds 10 20 30 40 50 --max_workers 5

Transfer learning from previously learned model weights:

cares-rl transfer --transfer_path <PATH_TO_MODEL_FOLDER> cli --gym openai --task CartPole-v1 DQN

Test a trained model:

cares-rl test --data_path <PATH_TO_TRAINING_DATA> --episodes 10 --eval_seed SEED

# Optionally select a saved model directory
cares-rl test --data_path <PATH_TO_TRAINING_DATA> --episodes 10 --eval_seed SEED --checkpoint 100000

Plot training results

cares-rl-plot -d <PATH_TO_RUN_DIRECTORY> --output <OUTPUT_DIRECTORY>

Usage

We have created a standardised general purpose gym that wraps the most common simulated environments used in reinforcement learning into a single easy to use place.

Running Training and Evaluation

The package is called using the cli command cares-rl. This takes in specific commands list below for training and evaluation purposes. The installed command runs the run.py in the main directory.

Use cares-rl -h for help on what parameters are available for customisation.

Train

The train command in the cares-rl script is used to initiate the training process for reinforcement learning models within specified gym environments. This command can be customized using various hyperparameters to tailor the training environment and the RL algorithm. You can use python cares-rl train cli -h to view all available options for customization and start a run directly through the terminal. This flexibility enables users to experiment with different settings and optimize their models effectively.

Specific and larger configuration changes can be loaded using python cares-rl train config --data_path <PATH_TO_TRAINING_CONFIGS>, allowing for a more structured and repeatable training setup through configuration files including modification of network structures for given algorithms.

cares-rl train cli -h
cares-rl train config --data_path <PATH_TO_TRAINING_CONFIGS>

Training can run training across seeds in parallel using the --max_workers parameter which will run each training seed in its own process.

cares-rl train cli --gym openai --task HalfCheetah-v4 TD3 --seeds 10 20 30 40 50 --max_workers 5

par gif

Resume (Experimental)

The resume command allows you to continue training from a previously saved checkpoint. This is useful if training was interrupted or if you want to further improve a model. You can specify the path to the checkpoint and resume training with your desired settings.

Note: to enable a training to be resumable you need to enable the --save_train_checkpoints 1 when using the train command. Checkpoint saving does not default to true, this is because saving a checkpoint of the memory, and training parameters increases data storage on the HD - especially for image based learning. This is also an experimental feature and the resume does not set all parameters/evnrioments to the same state as before - this will change the training outcomes, it is not a true resume command but it is useful for restarting training.

cares-rl resume --data_path <PATH_TO_TRAINING_DATA>

Transfer

The transfer command starts a new training run initialized from previously learned model weights. Unlike resume, it does not restore the previous replay or rollout memory, optimizer state, training counters, normalizer state, or exploration progression. The new run therefore begins from step zero with fresh training state while retaining the learned model initialization.

--transfer_path must point to the exact folder containing the saved model files, for example a run's models/final directory. Transfer then uses the normal cli or config interface to define the new training run.

cares-rl transfer --transfer_path <PATH_TO_MODEL_FOLDER> cli --gym openai --task CartPole-v1 DQN
cares-rl transfer --transfer_path <PATH_TO_MODEL_FOLDER> config --data_path <PATH_TO_TRAINING_CONFIGS>

Transfer runs perform an evaluation at step 0 before any new training updates so the transferred policy can be measured before adaptation begins. If multiple seeds are configured, each fresh run starts from the same source model. Generic transfer loading is not supported for CrossMARL.

Evaluate

The evaluate command is used to re-run the evaluation loops from a prior training run - this will reproduce the evaluation graphs and data from a given training experiment. Useful if you have updated metrics you want to capture without having to re-run the entire training process.

cares-rl evaluate --data_path <PATH_TO_TRAINING_DATA>

Test

The test command is used to run evaluation loops on a trained reinforcement learning model on the environment, users can load the trained model to evaluate how well the model performs on the given task with different evaluation seeds and over any number of episodes.

cares-rl test --data_path <PATH_TO_TRAINING_DATA> --eval_seed <EVAL_SEED> --episodes <NUM_EPISODES>

Plotting

The plotting utility plots training and evaluation logs from one task, multiple tasks, or an explicit list of run directories.

Running cares-rl-plot -h provides full plotting options, including custom plot panels via repeated --plot specifications.

cares-rl-plot -h

Plot one discovered task

cares-rl-plot --task ~/cares_rl_logs/ALGORITHM/ALGORITHM-TASK-YY_MM_DD:HH:MM:SS --output ~/cares_rl_plots

Plot and compare explicit run directories as one task

cares-rl-plot -d \
    ~/cares_rl_logs/ALGORITHM_A/ALGORITHM_A-TASK-YY_MM_DD:HH:MM:SS \
    ~/cares_rl_logs/ALGORITHM_B/ALGORITHM_B-TASK-YY_MM_DD:HH:MM:SS \
    --output ~/cares_rl_plots

Statistical Analysis

The statistical analysis pipeline (cares-rl-stats) computes task-level and cross-task summaries, publication tables, and a guided PDF report.

cares-rl-stats benchmark_root --output results

Use the statistical docs for full details.

Gym Environments

This package contains wrappers for the following gym environments - these wrapper standardise the different interfaces various tasks/environments use so we can use the same algorithm interface.

Single Agent Enviroments

Training environments for single agent reinforcement learning algorithms.

Deep Mind Control Suite

The standard Deep Mind Control suite: https://github.com/google-deepmind/dm_control

cares-rl train cli --gym dmcs --domain ball_in_cup --task catch TD3

OpenAI Gymnasium

The standard OpenAI Gymnasium: https://github.com/Farama-Foundation/Gymnasium

cares-rl train cli --gym openai --task CartPole-v1 DQN

cares-rl train cli --gym openai --task HalfCheetah-v4 TD3

Game Boy Emulator

Environment running Gameboy games utilising the pyboy wrapper: https://github.com/UoA-CARES/pyboy_environment

cares-rl train cli --gym pyboy --task mario SACAE

Drone Gym

The Drone gym contains all the code for training the CrazyFly drone on navigation tasks: https://github.com/UoA-CARES/drone_gym

cares-rl train cli --gym drone --task move_2d SAC

crazyfly

F1Tenth Gym V2.0

The F1Tenth gym contains all the code for training F1Tenth cars in autonomous racing.

crazyfly

Multi Agent Enviroments

Training environments for multi agent reinforcement learning algorithms.

SMAC/SMACv2

SMAC - The StarCraft Multi-Agent Challenge versions one (https://github.com/oxwhirl/smac) and two (https://github.com/oxwhirl/smacv2).

cares-rl train cli --gym smac --task m3 QMIX

crazyfly

MPE2

The standard MPE2 environment: https://mpe2.farama.org/

cares-rl train cli --gym mpe --task simple_spread_v3 MADDPG

mep2

Training Data Logs

All data from a training run is saved into the directory specified in the CARES_LOG_BASE_DIR environment variable. If not specified, this will default to '~/cares_rl_logs'.

You may specify a custom log directory format using the CARES_LOG_PATH_TEMPLATE environment variable. This path supports variable interpolation such as the algorithm used, seed, date etc. This defaults to "{algorithm}/{algorithm}-{domain_task}-{date}".

This folder will contain the following directories and information saved during the training session:

├─ <log_path>
|  ├─ env_config.json
|  ├─ alg_config.json
|  ├─ train_config.json
|  ├─ *_config.json
|  ├─ ...
|  ├─ SEED_N
|  |  ├─ data
|  |  |  ├─ train.csv
|  |  |  ├─ eval.csv
|  |  ├─ figures
|  |  |  ├─ eval.png
|  |  |  ├─ train.png
|  |  ├─ models
|  |  |  ├─ model.pht
|  |  |  ├─ CHECKPOINT_N.pht
|  |  |  ├─ ...
|  |  ├─ videos
|  |  |  ├─ STEP.mp4
|  |  |  ├─ ...
|  ├─ SEED_N
|  |  ├─ ...
|  ├─ ...

Supported Algorithms

We support a wide range of algorithms in the Reinforcement Learning space all under the same abstraction.

Q-Learning

Implementations of Q-Learning based methods

Algorithm Observation Space Action Space Paper Reference
DQN Vector Discrete DQN Paper
PERDQN Vector Discrete PERDQN Paper
DoubleDQN Vector Discrete DoubleDQN Paper
DuelingDQN Vector Discrete DuelingDQN Paper
NoisyNet Vector Discrete NoisyNet Paper
C51 Vector Discrete C51 Paper
QRDQN Vector Discrete QR-DQN Paper
IQN Vector Discrete IQN Paper
FQF Vector Discrete FQF Paper
Rainbow Vector Discrete Rainbow
RainbowQR Vector Discrete Rainbow-QR Paper
RainbowIQN Vector Discrete Rainbow-IQN Paper
RainbowFQF Vector Discrete Rainbow-FQF Paper

Actor Critic

Implementation of various Actor Critic methods.

Algorithm Observation Space Action Space Paper Reference
PPO Vector Continuous PPO Paper
DDPG Vector Continuous DDPG Paper
TD3 Vector Continuous TD3 Paper
SAC Vector Continuous SAC Paper
PERTD3 Vector Continuous PERTD3 Paper
PERSAC Vector Continuous PERSAC Paper
PALTD3 Vector Continuous PALTD3 Paper
LAPTD3 Vector Continuous LAPTD3 Paper
LAPSAC Vector Continuous LAPSAC Paper
LA3PTD3 Vector Continuous LA3PTD3 Paper
LA3PSAC Vector Continuous LA3PSAC Paper
MAPERTD3 Vector Continuous MAPERTD3 Paper
MAPERSAC Vector Continuous MAPERSAC Paper
RDTD3 Vector Continuous RDTD3 Paper
RDSAC Vector Continuous RDSAC Paper
REDQ Vector Continuous REDQ Paper
TQC Vector Continuous TQC Paper
CTD4 Vector Continuous CTD4 Paper
CrossQ Vector Continuous CrossQ Paper
Droq Vector Continuous DroQ Paper
SDAR Vector Continuous SDAR Paper
TD7 Vector Continuous TD7 Paper
SIMBA Vector Continuous SIMBA Paper
SIMBAV2 Vector Continuous SIMBAV2 Paper
MRQ Vector Continuous MRQ Paper
BRO Vector Continuous BRO Paper
SACD Vector Discrete SAC-Discrete Paper
----------- -------------------------- ------------ ---------------
NaSATD3 Image Continuous NaSATD3 Paper
TD3AE Image Continuous TD3AE Paper
SACAE Image Continuous SACAE Paper

Multi-Agent

Multi-Agent Reinforcement Learning algorithms (MARL).

Algorithm Observation Space Action Space Paper Reference
QMIX Vector (MARL) Discrete QMIX
IDDPG Vector (MARL) Continuous N/A
MADDPG Vector (MARL) Continuous MADDPG
M3DDPG Vector (MARL) Continuous M3DDPG
ERNIE Vector (MARL) Continuous ERNIE
ITD3 Vector (MARL) Continuous N/A
MATD3 Vector (MARL) Continuous MATD3
ISAC Vector (MARL) Continuous N/A
MASAC Vector (MARL) Continuous MASAC
IPPO Vector (MARL) Continuous N/A
MAPPO Vector (MARL) Continuous MAPPO

Unsupervised Skill Discovery

Implementation of Unsupervised Skill discovery methods

Algorithm Observation Space Action Space Paper Reference
DIAYN (Diversity Is All You Need) Vector Continuous DIYAN Paper
DADS Dynamics-Aware Discovery OF Skills Vector Continuous DADS Paper

Citation

@misc{cares_reinforcement_learning,
  title = {CARES Reinforcement Learning},
  author = {CARES},
  year = {2025},
  publisher = {GitHub},
  url = {https://github.com/UoA-CARES/cares_reinforcement_learning}
}

License

This project is licensed under the MIT License – see the LICENSE file for details.

探索相关项目

加载中…