Installation¶
This page installs Ajax, the extras some environments and tools need, and
CUDA for a GPU. Ajax is on PyPI as ajax-rl and imports as ajax. It needs
Python 3.12 or newer:
That is enough for the quickstart: gymnax's environments,
such as "CartPole-v1", come with Ajax.
Extras¶
Other environments and some tools come with an extra, such as
pip install "ajax-rl[playground]". Without it, building such an
environment raises an error that names the extra.
| Extra | What it adds |
|---|---|
cuda |
JAX with CUDA, on Linux (below) |
brax |
Brax, for Brax environments such as "ant" |
playground |
MuJoCo Playground and Brax, for Playground environments such as "CartpoleBalance" |
gymnasium |
Gymnasium with MuJoCo, for Gymnasium environments such as "gymnasium:HalfCheetah-v5", which step in Python |
gymnasium-mjx |
gymnasium-mjx and the playground extra, for Gymnasium's MuJoCo tasks in JAX such as "mujoco:HalfCheetah-v5" |
render |
matplotlib and Gymnasium's classic-control drawings (pygame), for agent.render on gymnax tasks |
compare |
the adastop package, whose confidence sequence ajax.compare.estimate uses; AdaStop itself needs no extra |
reproduction |
Hugging Face Hub, pandas and pyarrow, for ajax.reproduction.load (Reproduction) |
manifolds |
umap-learn, M-PHATE and matplotlib, for embedding a recorded run (Representations during training) |
wandb |
Weights & Biases, for logging with WandbBackend |
Until an adastop release includes the confidence sequence, a checkout's
uv sync takes adastop from the commit that
pyproject.toml names in [tool.uv.sources]. pip
does not read that table: with pip, install adastop from that commit
yourself.
CPU or GPU¶
Ajax installs JAX for the CPU: without the cuda extra, JAX runs on the CPU
even on a machine with an NVIDIA GPU. On Linux, the extra adds CUDA:
From the CUDA 12.9 runtime on, XLA records each step of a rollout as one
CUDA graph. pip installs the newest runtime, and uv.lock holds 12.9. On
the 12.6 runtime, the on-policy agents trained 8-19% slower on an L40S,
from PQN to PPO (Performance).
To keep a run on the CPU of a machine with a GPU, set JAX_PLATFORMS=cpu;
CUDA_VISIBLE_DEVICES="" hides the GPU from CUDA as well:
Performance says when a GPU pays off.
From source¶
pip installs main, the development version, from the repository:
pip takes the newest versions of the dependencies that pyproject.toml
allows; a weekly CI job tests those, and another the oldest allowed. For a
checkout, uv installs the versions in
uv.lock, which CI tests:
git clone https://github.com/YannBerthelot/Ajax.git
cd Ajax
uv sync
uv run python -c "import ajax; print(ajax.__version__)"
uv sync creates .venv: prefix commands with uv run, or activate it
with source .venv/bin/activate. It also installs the dev group, with
the test tools and the extras the tests need;
Contributing lists the
groups and the checks a change runs.
Using Ajax from another project¶
A project that depends on Ajax names ajax-rl with the extras it needs:
[project]
dependencies = ["ajax-rl"] # "ajax-rl[cuda]" for CUDA, "ajax-rl[playground]" for Brax and Playground envs
[tool.uv.sources]
ajax-rl = { git = "https://github.com/YannBerthelot/Ajax.git" } # optional: main instead of a release
Its installer picks versions within Ajax's bounds; Ajax's uv.lock applies
only to a checkout of Ajax. A project that declared ajax from git or a
path renames it ajax-rl; the import stays import ajax.
The compile cache¶
import ajax turns on JAX's persistent compile cache, in
~/.cache/ajax/jax_compile_cache: a second process that runs the same
program loads it from disk instead of compiling it again.
| Variable | Effect |
|---|---|
AJAX_JAX_COMPILE_CACHE_DIR |
puts the cache somewhere else |
AJAX_NO_COMPILE_CACHE=1 |
turns the cache off and leaves the disk untouched |
Performance explains what it saves and when it does not apply.
Weights & Biases¶
Logging to Weights & Biases needs the wandb extra, a WandbBackend in the
LoggingConfig, and a login once, with
wandb login, before the first run. A run that keeps its evaluations in
memory, as in the quickstart, or writes TensorBoard files needs no account.
Next¶
The quickstart trains a first agent, reads its results, acts with it and saves it.