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 · Coming from SB3 · Why Ajax · Agents · Expert and data · Documentation
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[gymnasium-mjx]" # adds Gymnasium's MuJoCo tasks (HalfCheetah-v5, ...) in JAX
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
agent = PPO("CartPole-v1", n_envs=8, n_steps=128)
state, evaluations = agent.train(seed=[1, 2, 3], n_timesteps=40_960)
print(evaluations.timesteps) # when each evaluation ran
print(evaluations.returns) # one row per seed, one column per evaluation
print(agent.evaluate(state, episodes=20).mean(axis=1)) # each seed's score now
train prints a line per evaluation, with the mean return over the seeds,
and on a terminal or in a notebook a progress bar with the time left.
The three seeds train together, in under a minute on a laptop CPU,
compilation included.
agent.predict(state, obs) returns the trained policy's action for an
observation, and agent.save(state, path) and ajax.load(path) keep it
for later (Train, evaluate, deploy).
Coming from Stable-Baselines3? The calls side by side.
"CartPole-v1" here is gymnax's
CartPole, written in JAX. That is the intended use: with a JAX environment
(gymnax, Brax, MuJoCo Playground) the environment, the agent and every seed
compile into one program that stays on the CPU or the GPU from start to
end. Gymnasium's MuJoCo tasks also run in JAX, with the gymnasium-mjx
extra: SAC("mujoco:HalfCheetah-v5")
(Environments).
On an NVIDIA GPU, mujoco: and Playground tasks step MuJoCo Warp by
default, which trained about five times faster than MJX's pure-JAX physics
on an L40S; to keep pure JAX, build the environment with
build_env_from_id(env_id, n_envs=..., physics="jax") and pass it to the
agent with the same n_envs
(MuJoCo Warp on a GPU).
Any Gymnasium environment runs too, with
PPO("gymnasium:CartPole-v1"); it steps in Python, so training is slower
and a GPU does not help
(Environments).
A notebook trains, acts and saves step by step: notebooks/quickstart.ipynb
(open in Colab).
Complete scripts are in examples/.
Why Ajax
Ajax has twenty agents, each from a published paper. Compared with Stable-Baselines3 and SBX, it offers:
- Faster: the environment steps beside the agent on a CPU or a GPU, with no Python in the loop, and every seed and environment copy trains in the same program.
- More experiments per run: several seeds and several values of a hyperparameter train in one compiled program, so ten seeds of three learning rates are one call.
- Variations in one argument, parts that compose: recurrent PPO is PPO with a memory, and memories, CNN encoders, a PID policy and forty-four extensions (cloning, an expert's transitions in the replay, diagnostics) add up in one constructor. The compatibility table shows which go together.
- Trustworthy: each agent follows the code behind its paper's results, and its page lists where it departs. Unit tests check each update's maths, probes with known answers check that agents learn, and conformance tests compare updates with the original implementations. Comparisons of learning results with reference libraries are in progress (Reproduction).
- Multi-paradigm: discounted and average-reward agents (ASAC, RVI-SAC, APO), model-free and model-based, online and offline.
- Expert-guided: cloning, imitation, prior data and offline training.
- World models: DreamerV3 and TD-MPC2, which their papers run on over a hundred tasks with one set of hyperparameters.
Why Ajax compares it with SB3, SBX, PureJaxRL, Brax, Stoix, Rejax, TorchRL and Tianshou, including when to use them instead.
Speed
The environment, the agent and every seed compile into one program, so many seeds train at once on one device. With few seeds, a library stepping C MuJoCo can be faster: on HalfCheetah, SB3 trains PPO faster with up to ten seeds, Ajax on one L40S from about a dozen. With 10 seeds on CheetahRun, one NVIDIA L40S ran SAC 26 times as fast as four CPU cores, and REDQ, CrossQ and TD-MPC2 65 to 101 times (speeds).
Ajax's speed over the fastest other library on each task, each library on its faster device (four CPU cores or one NVIDIA L40S): with 10 seeds, SAC and TD3 8.3 to 76.7 times, PPO 0.9 to 1.1 times, DQN and PQN 1.0 to 1.3 times; with 50 seeds, SAC and TD3 8.3 to 81.6 times, PPO 1.0 times, DQN and PQN 0.8 to 1.2 times. On HalfCheetah, Ajax, Brax and PureJaxRL step MuJoCo Warp on the GPU and MJX's pure JAX on the CPU, the others C MuJoCo (figure and settings).
Research in a few lines
Several seeds and several values of a hyperparameter train in one compiled program: here 30 runs, 10 seeds for each of 3 learning rates.
from ajax import PPO
agent = PPO("CartPole-v1", n_envs=8, n_steps=128)
state, evaluations = agent.train(
seed=list(range(10)),
n_timesteps=40_960,
sweep={"actor_learning_rate": [1e-4, 3e-4, 1e-3]},
)
for configuration, returns in agent.by_configuration(evaluations.returns):
print(configuration, returns[:, -1].mean()) # mean final return over the 10 seeds
A variation is one argument, and parts add up in one constructor:
import jax.numpy as jnp
from ajax import PPO, SAC
from ajax.extensions.instrumentation import CriticDiagnostics
from ajax.extensions.pretrain import CloningPretrain, ExpertPrefill
# A variation is one argument: recurrent PPO is PPO with a memory.
agent = PPO("CartPole-v1", memory={"kind": "lstm", "hidden_size": 64})
def pd_expert(obs):
"""A PD controller on Pendulum's angle, a torque in the env's range."""
theta = jnp.arctan2(obs[..., 1], obs[..., 0])
return jnp.clip(-(2.0 * theta + 0.5 * obs[..., 2]), -2.0, 2.0)[..., None]
# Parts add up in one constructor: the actor cloned from the expert before
# training, the expert's transitions in the replay, and at each evaluation
# whether the critic's features are degrading (how many directions they
# span, how many units went silent).
agent = SAC(
"Pendulum-v1",
extensions=(
CloningPretrain(pd_expert, n_steps=1_000),
ExpertPrefill(n_steps=1_000, expert=pd_expert),
CriticDiagnostics(),
),
)
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), REINFORCE (the plain policy gradient)
- 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, REINFORCE, DAgger, UDRL and
DreamerV3 take both; the others continuous ones. SAC, TD3, REDQ, TQC, CrossQ, ASAC, RVI-SAC,
DQN, IQL and DAgger 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.
Also in the box
| Extensions Forty-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 tests |
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.7.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.7.0.tar.gz | 670.1 kB | Without provenance | Details for ajax_rl-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ajax_rl-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for ajax_rl-0.7.0-py3-none-any.whl |
Total release size: 1.4 MB
Release files / ajax_rl-0.7.0.tar.gz
| Download URL | ajax_rl-0.7.0.tar.gz |
|---|---|
| Size | 670.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e429f74f9d1570ad8d1c7a4381ad8882ea4027ce68975afe12c9688e96e486c7
|
|
BLAKE2b-256 checksum How to use checksums |
5266d220e15b72364492d7418cf0b85eeffbfa9f2e5af554b8f0571d2dd8d7d2
|
| 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":"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 / ajax_rl-0.7.0-py3-none-any.whl
| Download URL | ajax_rl-0.7.0-py3-none-any.whl |
|---|---|
| Size | 768.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d10af62f0fc47a5e0fb13fe40ce1f9027cba841ad9428779f2b04b0f3b0e145
|
|
BLAKE2b-256 checksum How to use checksums |
224ad291a066fac577a84effd497c29d498628b038786c905665f55aaa028588
|
| 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":"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 ajax-rl 0.7.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.