Skip to main content

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.

Documentation CI PyPI License

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. 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). 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 10 seeds, one NVIDIA L40S ran SAC about 7 times as fast as four CPU cores, and CrossQ and REDQ over 50 times (speeds).

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

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 the DAgger agent.
  • 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.

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.6.0

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

Source distribution (sdist)

Source distribution for ajax-rl 0.6.0
File Size Uploaded Provenance Actions
ajax_rl-0.6.0.tar.gz 655.9 kB Without provenance Details for ajax_rl-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ajax-rl 0.6.0
File Interpreter ABI Platform Actions
ajax_rl-0.6.0-py3-none-any.whl Python 3 none any Details for ajax_rl-0.6.0-py3-none-any.whl

Total release size: 1.4 MB

Release files / ajax_rl-0.6.0.tar.gz

Download URL ajax_rl-0.6.0.tar.gz
Size 655.9 kB
Tags Source
SHA-256 checksum
How to use checksums
52004dd6430cf274f18ccb8bdb619b34bd58edc17149f618d335bf4b434a5eab
BLAKE2b-256 checksum
How to use checksums
14132258e930f38ef91cdfe34e8ddc626dab570a1cb8691d2c4eb0619acc1ee4
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.6.0-py3-none-any.whl

Download URL ajax_rl-0.6.0-py3-none-any.whl
Size 754.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27293677fd86c3603a94a4c0373a47612b71e272684638acd7e0488e6f52600a
BLAKE2b-256 checksum
How to use checksums
72beb281fdf0934fe9995314927499d097b4f1212574a6fe8451f6771efc1594
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.6.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.

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