Skip to main content

MASA-Safe-RL

MASA-Safe-RL PyPI DOI Docs License

View Documentation


MASA-Safe-RL (Multi- and Single-Agent Safe RL) is a modular library for safe reinforcement learning, built on the Gymnasium and PettingZoo interfaces. You supply an environment plus a labelling function and a cost function. MASA wraps the environment in a stateful constraint monitor and, optionally, a shield, and trains it with algorithm-agnostic learners. Safety specifications live outside the environment, so the same environment can be evaluated under different constraints without modification.

  • Constraints: CMDPs, constrained Markov games (per-coalition budgets), LTL safety (DFA), PCTL, probabilistic safety and reach-avoid.
  • Shielding: deterministic shields from LTL safety games (preemptive or post-posed, including coalitional shields for multi-agent settings) and probabilistic shielding.
  • Algorithms: tabular safe RL baselines; JAX implementations of PPO, A2C, TRPO, CPO and Lagrangian variants; and multi-agent independent Q-learning variants.
  • Environments: 35 single- and multi-agent benchmarks, from gridworlds and matrix games to continuous control.
  • Tooling: a masa command-line interface, TensorBoard and W&B logging, plotting utilities and tutorial notebooks.

MASA-Safe-RL is under active development (pre-1.0), so APIs may still change. We'd love to hear what you'd like to see implemented; see Getting in Touch.

Citing MASA-Safe-RL

If you use MASA-Safe-RL in your research please cite our release archive on Zenodo. The DOI here resolves the latest release, if you want to cite a specific version please see each release's own version DOI on its Zenodo page.

@software{goodall2026masa,
  author    = {Goodall, Alexander W. and Adalat, Omar and {Hamel-De le Court}, Edwin and Belardinelli, Francesco},
  title     = {{MASA-Safe-RL}: A Modular Library for Single- and Multi-Agent Safe Reinforcement Learning},
  year      = {2026},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.24396240},
  url       = {https://doi.org/10.5281/zenodo.24396240}
}

Quick Start

Installation

Prequisites

Python 3.12+ is required (3.13 recommended).

Installation with conda

  • Install conda, e.g., via anaconda.
  • Clone the repo:
git clone https://github.com/sacktock/MASA-Safe-RL.git
cd MASA-Safe-RL
  • Create a conda virtual environment:
conda env create --name masa --file conda-environment.yaml
conda activate masa
  • Install dependencies:
pip install -e .

Installation with uv

uv sync installs only base dependency package from the repository root.

Easiest way to install all dependencies: All dependency groups (docs and GPU support for CUDA13): uv sync --all-groups --no-group cuda12.

Alternatively, uv sync --all-groups --no-group cuda13 if your system only supports CUDA 12.

More minimal ways of installing dependency groups:

  • For building docs, use uv sync --group docs from the repository root.
  • Adding GPU support for Jax: uv sync --group cuda13 (or cuda12 if CUDA 13 is not supported by your device)

Installation with PyPI

MASA-Safe-RL is now available on PyPI: MASA-Safe-RL.

pip install -U MASA-Safe-RL

Enabling GPU Acceleration with JAX (Optional)

MASA-Safe-RL relies on JAX for GPU acceleration. If you are only interested in the gymnasium wrappers and constraints API then you do not need to complete the following steps.

Mac and Windows

macOS and Windows: we recommend JAX with CPU. No further action is required if you correctly followed the earlier steps.

pip

  • Linux x86_64/aarch64 and Windows WSL2 x86_64: We strongly recommend using Ubuntu 22.04 or similar, jax and jaxlib should already be installed. You need to reinstall JAX based on your cuda driver compatibility. Do not use the -U option here as it may break earlier dependencies!
pip install "jax[cuda13]"
pip install "jax[cuda12]"

uv

Alternatively with uv,

uv sync --group cuda12
uv sync --group cuda13

How to run MASA

  • You can run masa with the prebuilt CLI:
masa run --env-id bridge_crossing --algo ppo --seed 0
  • You can run examples from the \examples folder via:
masa example prob_shield_example

Editing documentation

Documentation uses the root pyproject.toml and uv.lock, so you can build and serve it directly from the repository root.

uv run zensical build --strict

The built site will be available at site/index.html.

For live reload while editing, run:

uv run zensical serve

Local storage

The project currently uses the following directories for local storage:

  • .cache/ - for persisting transition matrices to avoid recomputation
  • videos/ - stores recorded videos from training runs at configured intervals or played runs using notebooks/
  • runs/ - persisted data and metrics of training runs
  • benchmarks/ - stores results from masa benchmark runs

Contributing

We use pre-commit for formatting and linting (Ruff, yamlfmt, taplo, mdformat, plus local checks). Install the git hook once per clone:

pip install pre-commit   # or: uv tool install pre-commit
pre-commit install

It then runs automatically on every git commit (run manually with pre-commit run --all-files). CI runs the same pinned hooks on changed files via pre-commit/action, alongside the test suite.

Getting in Touch

MASA-Safe-RL is primarliy managed by Alex Goodall and Omar Adalat. For correspondence in the early stages of the library we prefer you contact us directly via email (a.goodall22@imperial.ac.uk & o.adalat24@imperial.ac.uk), rather than raising issues on GitHub directly.

License

MASA-Safe-RL is released under Apache License 2.0.

Metadata

Release files for MASA-Safe-RL 0.3.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for MASA-Safe-RL 0.3.17
File Size Uploaded Provenance Actions
masa_safe_rl-0.3.17.tar.gz 304.6 kB Without provenance Details for masa_safe_rl-0.3.17.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for MASA-Safe-RL 0.3.17
File Interpreter ABI Platform Actions
masa_safe_rl-0.3.17-py3-none-any.whl Python 3 none any Details for masa_safe_rl-0.3.17-py3-none-any.whl

Total release size: 746.6 kB

Release files / masa_safe_rl-0.3.17.tar.gz

Download URL masa_safe_rl-0.3.17.tar.gz
Size 304.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ed40c0955d03f3f8e9b8e745efd3571d29e4f8aa0c1299389c083a980333b9b8
BLAKE2b-256 checksum
How to use checksums
1d38506dda9ded1618da7ea2b900130506ec5348c55e3d1c7e8991448c8f0270
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / masa_safe_rl-0.3.17-py3-none-any.whl

Download URL masa_safe_rl-0.3.17-py3-none-any.whl
Size 442.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5ef35af54f0c51267bb9e3e3aeeb23bff57b2b6f7c65e08f8d4b66de8caf6874
BLAKE2b-256 checksum
How to use checksums
98e1097aead0aa2ce9f95e3cab3bd11e7a06f0630951a2657802004bd7947add
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for MASA-Safe-RL 0.3.17

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3.17 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page