Ajax
Fast, modular reinforcement learning in JAX.
The environment, the agent and every seed run together in one program, on a CPU or a GPU, and agents are built from parts that snap together.
Install · Quickstart · Agents · Expert and data · Reproduction · Documentation
Ajax has nineteen agents, each from a published paper. Compared with Stable-Baselines3 and SBX, it offers:
- Fast and parallel: the environment steps beside the agent on a CPU or a GPU, with no Python in the loop, so many seeds and environment copies train at once on one device. The benchmarks run on a CPU; GPU speed is not yet measured.
- Modular: GRU, LSTM, transformer and Mamba memories, CNN encoders, sequence replay with burn-in, a PID policy and thirty-four extensions, combined in the agent's constructor. The compatibility table shows which parts go together.
- Multi-paradigm: discounted and average-reward agents (ASAC, RVI-SAC, APO), model-free and model-based, online and offline, all behind one interface.
- Expert-guided: cloning, imitation, prior data and offline training.
- World models, ready to use: DreamerV3 and TD-MPC2 are among the hardest agents to get right, and their papers run them on over a hundred tasks with one set of hyperparameters. Ajax checks them against the official code, update by update.
Why Ajax compares it with SB3, SBX, PureJaxRL, Brax, Stoix, Rejax, TorchRL and Tianshou, including when to use them instead.
Install
pip install ajax-rl # imports as ajax; Python 3.12 or newer
pip install "ajax-rl[playground]" # adds Brax and MuJoCo Playground environments
pip install "ajax-rl[cuda]" # adds CUDA, on Linux with an NVIDIA GPU
ajax-rl[brax] adds Brax alone; Installation
covers the other extras and uv sync from a clone.
Quickstart
from ajax import PPO
from ajax.logging import LoggingConfig
agent = PPO("CartPole-v1") # 4 environments x 2048-step rollouts: one update per 8,192 steps
# Evaluate after every update; backends=() keeps the results in memory only.
logging = LoggingConfig(log_frequency=8_192, backends=())
state, evaluations = agent.train(seed=[1, 2, 3], n_timesteps=40_960, logging_config=logging)
print(evaluations["timestep"][0]) # when each evaluation ran
print(evaluations["Eval/episodic mean reward"]) # one row per seed, one column per evaluation
The three seeds train together, in about fifteen seconds on a laptop CPU, compilation included. Parts combine in the constructor:
from ajax import PPO, SAC
from ajax.extensions.instrumentation import ConditioningMetrics
# A recurrent actor and critic, for when one observation is not enough.
agent = SAC("Pendulum-v1", memory={"kind": "lstm", "hidden_size": 64})
# A research feature as an extension: the critic's health at each evaluation.
agent = PPO("CartPole-v1", extensions=(ConditioningMetrics(),))
# Brax and MuJoCo Playground environments by id (their extras), here 8 copies in parallel.
agent = PPO("ant", n_envs=8)
Agents
- Off-policy actor-critic: SAC, TD3, REDQ, CrossQ (batch-renormalised, no target networks), TQC (truncated quantile critics), AVG (no replay), ASAC and RVISAC (RVI-SAC; average reward), IQL (offline)
- On-policy: PPO, APO (average reward)
- Value-based: DQN, PQN
- World models: DreamerV3, TDMPC2, TDMPC2MultiTask (multi-task, offline)
- Supervised: DAgger (imitation of an expert), UDRL (command-conditioned)
- Differentiable simulation: APG
DQN and PQN take discrete actions; PPO, APO, DAgger, UDRL and DreamerV3 take
both; the others continuous ones. SAC, TD3, REDQ, ASAC and DQN also train
offline (train_offline). Each name opens the agent's page, with its paper;
the compatibility table lists every extension
per agent.
Learning from an expert or from data
- Before training: behaviour cloning (
CloningPretrain), expert transitions in the replay (ExpertPrefill), prior data as in RLPD (PriorData). - During training: TD3+BC's actor term, kickstarting and Q-filtered cloning (
ImitationLoss), IBRL (IBRL), residual RL (ResidualPolicy), JSRL hand-over (JSRLCurriculum), GAIL (AdversarialReward), and theDAggeragent. - Instead of online data:
agent.train_offline(dataset, n_updates), then online fine-tuning if wanted: IQL, CQL and Cal-QL (ConservativeQ,CalQL), ReBRAC (TargetBC), TD3+BC; TD-MPC2's multi-task agent (TDMPC2MultiTask) on pooled datasets.
Choosing the pieces gives each method's paper and the agents that take it.
Beside reference implementations
Ajax's PPO beside Stable-Baselines3's and its PQN beside purejaxql's, on the same JAX environment, 96 seeds each; both comparisons find the returns similar within the registered margin. Results has two more comparisons (one inconclusive) and the speed of each side; the protocol says how they are run.
Also in the box
| Extensions Thirty-four research features, passed as extensions=(...) |
Recurrent memory GRU, LSTM, transformer or Mamba, with sequence replay |
Differentiable simulation APG back-propagates the return through gymnax dynamics |
| Environments gymnax, Brax and MuJoCo Playground by id, many copies at once |
Networks and the PID policy A CNN encoder; a PID controller as the actor |
Logging Every evaluation as arrays; Weights & Biases or TensorBoard |
| Comparing agents AdaStop, which adds seeds only while the answer is unclear |
Checkpoints Save a run and resume it in another process |
Tests Unit tests, probes with known answers, conformance checks |
The documentation site has the user guide, one page per agent, the API reference and the developer guide.
Related projects
gymnax, Brax and MuJoCo Playground provide the environments, flashbax most replay buffers. TargetGym has setpoint-tracking tasks with PID and MPC baselines, and ProbingEnvironments the small environments with known answers that Ajax's probes train on.
Contributing, citing, license
Bug reports, new agents and new extensions are welcome; see CONTRIBUTING.md. Ajax is MIT-licensed (LICENSE).
@misc{ajax2025,
title = {Ajax: Reinforcement Learning Agents in Jax},
author = {Yann Berthelot},
year = {2025},
url = {https://github.com/YannBerthelot/Ajax},
}
Metadata
Release files for ajax-rl 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ajax_rl-0.5.0.tar.gz | 507.0 kB | Without provenance | Details for ajax_rl-0.5.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ajax_rl-0.5.0-py3-none-any.whl | Python 3 | none | any | Details for ajax_rl-0.5.0-py3-none-any.whl |
Total release size: 1.1 MB
Release files / ajax_rl-0.5.0.tar.gz
| Download URL | ajax_rl-0.5.0.tar.gz |
|---|---|
| Size | 507.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b456786bab6695c2efa3e4351666d53ea9bb07d31a1df56d0a1682bd41d654cb
|
|
BLAKE2b-256 checksum How to use checksums |
93e6426565582f46c996b00d6382428f685739b136e2946123d65fc0653c840d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / ajax_rl-0.5.0-py3-none-any.whl
| Download URL | ajax_rl-0.5.0-py3-none-any.whl |
|---|---|
| Size | 593.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59e42e5d749baad32c3ef29f069a8ff75fe94cedb7e5a9f04f19dd44ea95ea66
|
|
BLAKE2b-256 checksum How to use checksums |
c295be8c145cf3c0fc7001c48132992a754d0cb46f94a1ecec7e2b536ba882be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for ajax-rl 0.5.0
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.