Ajax¶
Ajax is a library of reinforcement-learning agents written in JAX. A training run, with its environment and all its seeds, compiles into one program that runs on a CPU or a GPU. These pages show how to install it, train and use its agents, and extend them.
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) # prints a line per evaluation
print(evaluations.returns) # one row per seed, one column per evaluation
Get started → Coming from SB3 → Choose an algorithm →
Why Ajax¶
Ajax has twenty agents, each following the code behind its paper's results. Next to Stable-Baselines3 and its JAX version SBX, it offers:
- Speed: the environment steps inside the compiled program, beside the agent, with no Python between two steps.
- Many runs in one call: every seed, and every value of a hyperparameter sweep, trains in the same program.
- Variations that combine: a memory, an image encoder, a PID policy or an extension is an argument of the same agent, and an agent refuses, when built, one it cannot run.
- Checked against the original code: unit tests of each update's maths, probes with known answers, and conformance tests against the original implementations.
- Average reward, world models and offline training beside the usual discounted, model-free agents.
- Learning from an expert: start from a controller you already have, or from recorded transitions.
Why Ajax explains each, with examples, compares Ajax with SB3, SBX, PureJaxRL, Brax, Stoix, Rejax, TorchRL and Tianshou, and says when one of them fits better.
Getting started¶
- Installation: pip, the extras, a GPU.
- Quickstart: train an agent, read its results, act with it and save it.
- Why Ajax: what Ajax offers, and when another library fits better.
- Coming from SB3: Stable-Baselines3's calls and defaults beside Ajax's.
The agents¶
| Kind | Agents |
|---|---|
| Off-policy actor-critic | SAC, ASAC and RVI-SAC (average reward), REDQ, CrossQ, TQC, TD3 |
| Offline, then online | IQL |
| Incremental, no replay | AVG |
| Value-based, discrete actions | DQN, PQN |
| On-policy | PPO, APO (average reward), REINFORCE (the plain policy gradient) |
| Supervised, command-conditioned | UDRL |
| Imitation of an expert, no reward | DAgger |
| Differentiable simulation | APG |
| World models | DreamerV3, TD-MPC2 and its multi-task variant |
Each agent's page gives its paper, its defaults and where it departs from the original.
What else is in the box¶
| Feature | What it gives |
|---|---|
| Presets | the settings an agent's reference code tunes for a task: Agent.preset(task, env_id) |
| Hyperparameter sweeps | train(sweep=...): several configurations, each with every seed, in one program |
| Expert guidance | cloning, imitation, prior data and hand-over, from a controller in the environment's own units |
| Memory | GRU, LSTM, transformer or Mamba blocks, with R2D2-style sequence replay |
| Networks | hidden layers, initialisers, CNN encoders, a shared encoder, layers per head |
| The PID policy | a PID controller as the actor, whose learned gains deploy as a plain PID |
| Environments | gymnax, Brax and MuJoCo Playground by id, wrappers, and any Gymnasium environment ("gymnasium:<id>") |
| Gymnasium's MuJoCo tasks in JAX | "mujoco:<id>", and MuJoCo Warp physics on an NVIDIA GPU |
| Normalisation | running observation statistics, and rewards divided by the spread of the discounted return |
| Differentiable simulation | APG through gymnax dynamics, across distributions of physical parameters |
| Logging | evaluations as arrays, Weights & Biases or TensorBoard, evaluation on another device |
| Checkpoints | save a run and resume it in another process |
| Performance | seeds, CPU or GPU, and the persistent compile cache |
| Comparing agents | AdaStop, which trains more seeds only while the answer is unclear, and confidence intervals |
| Reproduction | Ajax agents trained beside reference implementations, under a written protocol |
Documentation¶
-
Use it
Training an agent · Train, evaluate, deploy · Environments · Extensions · Algorithms
-
Look it up
API reference · Training loop · Extensions API · Compatibility
-
Change it
Architecture · Contributing · Writing an extension · Testing and probing · Performance checks
-
Check the world models
Ajax is MIT-licensed. Its sibling project TargetGym provides JAX environments for holding a setpoint.