Skip to content

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.

pip install ajax-rl  # imports as ajax; Python 3.12 or newer
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:

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

  1. Installation: pip, the extras, a GPU.
  2. Quickstart: train an agent, read its results, act with it and save it.
  3. Why Ajax: what Ajax offers, and when another library fits better.
  4. 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

Ajax is MIT-licensed. Its sibling project TargetGym provides JAX environments for holding a setpoint.