ajax-rl 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. ajax_rl-0.4.0/LICENSE +21 -0
  2. ajax_rl-0.4.0/PKG-INFO +365 -0
  3. ajax_rl-0.4.0/README.md +318 -0
  4. ajax_rl-0.4.0/pyproject.toml +210 -0
  5. ajax_rl-0.4.0/src/ajax/__init__.py +43 -0
  6. ajax_rl-0.4.0/src/ajax/_compile_cache.py +148 -0
  7. ajax_rl-0.4.0/src/ajax/agents/APG/APG.py +262 -0
  8. ajax_rl-0.4.0/src/ajax/agents/APG/__init__.py +5 -0
  9. ajax_rl-0.4.0/src/ajax/agents/APG/curriculum.py +91 -0
  10. ajax_rl-0.4.0/src/ajax/agents/APG/networks.py +168 -0
  11. ajax_rl-0.4.0/src/ajax/agents/APG/state.py +28 -0
  12. ajax_rl-0.4.0/src/ajax/agents/APG/train_APG.py +467 -0
  13. ajax_rl-0.4.0/src/ajax/agents/APO/APO.py +190 -0
  14. ajax_rl-0.4.0/src/ajax/agents/APO/__init__.py +0 -0
  15. ajax_rl-0.4.0/src/ajax/agents/APO/state.py +35 -0
  16. ajax_rl-0.4.0/src/ajax/agents/APO/train_APO.py +437 -0
  17. ajax_rl-0.4.0/src/ajax/agents/ASAC/ASAC.py +198 -0
  18. ajax_rl-0.4.0/src/ajax/agents/ASAC/__init__.py +0 -0
  19. ajax_rl-0.4.0/src/ajax/agents/ASAC/state.py +29 -0
  20. ajax_rl-0.4.0/src/ajax/agents/ASAC/train_ASAC.py +491 -0
  21. ajax_rl-0.4.0/src/ajax/agents/ASAC/utils.py +20 -0
  22. ajax_rl-0.4.0/src/ajax/agents/AVG/AVG.py +152 -0
  23. ajax_rl-0.4.0/src/ajax/agents/AVG/__init__.py +0 -0
  24. ajax_rl-0.4.0/src/ajax/agents/AVG/state.py +39 -0
  25. ajax_rl-0.4.0/src/ajax/agents/AVG/train_AVG.py +463 -0
  26. ajax_rl-0.4.0/src/ajax/agents/AVG/utils.py +49 -0
  27. ajax_rl-0.4.0/src/ajax/agents/DAgger/DAgger.py +104 -0
  28. ajax_rl-0.4.0/src/ajax/agents/DAgger/__init__.py +0 -0
  29. ajax_rl-0.4.0/src/ajax/agents/DAgger/state.py +22 -0
  30. ajax_rl-0.4.0/src/ajax/agents/DAgger/train_DAgger.py +289 -0
  31. ajax_rl-0.4.0/src/ajax/agents/DQN/DQN.py +150 -0
  32. ajax_rl-0.4.0/src/ajax/agents/DQN/__init__.py +0 -0
  33. ajax_rl-0.4.0/src/ajax/agents/DQN/networks.py +208 -0
  34. ajax_rl-0.4.0/src/ajax/agents/DQN/state.py +29 -0
  35. ajax_rl-0.4.0/src/ajax/agents/DQN/train_DQN.py +550 -0
  36. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/DreamerV3.py +383 -0
  37. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/__init__.py +21 -0
  38. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/actor_critic.py +288 -0
  39. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/distributions.py +297 -0
  40. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/learner.py +554 -0
  41. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/networks.py +503 -0
  42. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/optim.py +158 -0
  43. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/replay.py +402 -0
  44. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/state.py +382 -0
  45. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/train_DreamerV3.py +638 -0
  46. ajax_rl-0.4.0/src/ajax/agents/DreamerV3/world_model.py +257 -0
  47. ajax_rl-0.4.0/src/ajax/agents/IQL/IQL.py +130 -0
  48. ajax_rl-0.4.0/src/ajax/agents/IQL/__init__.py +0 -0
  49. ajax_rl-0.4.0/src/ajax/agents/IQL/state.py +20 -0
  50. ajax_rl-0.4.0/src/ajax/agents/IQL/train_IQL.py +272 -0
  51. ajax_rl-0.4.0/src/ajax/agents/PPO/PPO.py +216 -0
  52. ajax_rl-0.4.0/src/ajax/agents/PPO/__init__.py +0 -0
  53. ajax_rl-0.4.0/src/ajax/agents/PPO/core.py +161 -0
  54. ajax_rl-0.4.0/src/ajax/agents/PPO/state.py +55 -0
  55. ajax_rl-0.4.0/src/ajax/agents/PPO/train_PPO.py +919 -0
  56. ajax_rl-0.4.0/src/ajax/agents/PPO/utils.py +121 -0
  57. ajax_rl-0.4.0/src/ajax/agents/PQN/PQN.py +135 -0
  58. ajax_rl-0.4.0/src/ajax/agents/PQN/__init__.py +0 -0
  59. ajax_rl-0.4.0/src/ajax/agents/PQN/networks.py +76 -0
  60. ajax_rl-0.4.0/src/ajax/agents/PQN/state.py +27 -0
  61. ajax_rl-0.4.0/src/ajax/agents/PQN/train_PQN.py +246 -0
  62. ajax_rl-0.4.0/src/ajax/agents/PQN/utils.py +51 -0
  63. ajax_rl-0.4.0/src/ajax/agents/REDQ/REDQ.py +229 -0
  64. ajax_rl-0.4.0/src/ajax/agents/REDQ/__init__.py +0 -0
  65. ajax_rl-0.4.0/src/ajax/agents/REDQ/state.py +17 -0
  66. ajax_rl-0.4.0/src/ajax/agents/REDQ/train_REDQ.py +460 -0
  67. ajax_rl-0.4.0/src/ajax/agents/SAC/SAC.py +314 -0
  68. ajax_rl-0.4.0/src/ajax/agents/SAC/__init__.py +0 -0
  69. ajax_rl-0.4.0/src/ajax/agents/SAC/action_pipeline.py +361 -0
  70. ajax_rl-0.4.0/src/ajax/agents/SAC/core.py +340 -0
  71. ajax_rl-0.4.0/src/ajax/agents/SAC/expert.py +66 -0
  72. ajax_rl-0.4.0/src/ajax/agents/SAC/state.py +36 -0
  73. ajax_rl-0.4.0/src/ajax/agents/SAC/train_SAC.py +895 -0
  74. ajax_rl-0.4.0/src/ajax/agents/TD3/TD3.py +180 -0
  75. ajax_rl-0.4.0/src/ajax/agents/TD3/__init__.py +0 -0
  76. ajax_rl-0.4.0/src/ajax/agents/TD3/networks.py +135 -0
  77. ajax_rl-0.4.0/src/ajax/agents/TD3/state.py +22 -0
  78. ajax_rl-0.4.0/src/ajax/agents/TD3/train_TD3.py +503 -0
  79. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/TDMPC2.py +448 -0
  80. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/TDMPC2MultiTask.py +543 -0
  81. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/__init__.py +18 -0
  82. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/buffer.py +624 -0
  83. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/core.py +920 -0
  84. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/dataset.py +494 -0
  85. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/multitask.py +290 -0
  86. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/networks.py +401 -0
  87. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/planner.py +567 -0
  88. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/state.py +294 -0
  89. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/train_TDMPC2.py +618 -0
  90. ajax_rl-0.4.0/src/ajax/agents/TDMPC2/train_TDMPC2MultiTask.py +292 -0
  91. ajax_rl-0.4.0/src/ajax/agents/UDRL/UDRL.py +100 -0
  92. ajax_rl-0.4.0/src/ajax/agents/UDRL/__init__.py +0 -0
  93. ajax_rl-0.4.0/src/ajax/agents/UDRL/buffer.py +233 -0
  94. ajax_rl-0.4.0/src/ajax/agents/UDRL/state.py +62 -0
  95. ajax_rl-0.4.0/src/ajax/agents/UDRL/train_UDRL.py +593 -0
  96. ajax_rl-0.4.0/src/ajax/agents/UDRL/utils.py +56 -0
  97. ajax_rl-0.4.0/src/ajax/agents/__init__.py +0 -0
  98. ajax_rl-0.4.0/src/ajax/agents/base.py +570 -0
  99. ajax_rl-0.4.0/src/ajax/agents/cloning.py +211 -0
  100. ajax_rl-0.4.0/src/ajax/agents/loop.py +822 -0
  101. ajax_rl-0.4.0/src/ajax/agents/recurrent.py +442 -0
  102. ajax_rl-0.4.0/src/ajax/buffers/__init__.py +0 -0
  103. ajax_rl-0.4.0/src/ajax/buffers/dataset.py +295 -0
  104. ajax_rl-0.4.0/src/ajax/buffers/utils.py +219 -0
  105. ajax_rl-0.4.0/src/ajax/checkpoint.py +485 -0
  106. ajax_rl-0.4.0/src/ajax/compare.py +420 -0
  107. ajax_rl-0.4.0/src/ajax/deprecation.py +19 -0
  108. ajax_rl-0.4.0/src/ajax/distributional.py +265 -0
  109. ajax_rl-0.4.0/src/ajax/environments/__init__.py +0 -0
  110. ajax_rl-0.4.0/src/ajax/environments/create.py +474 -0
  111. ajax_rl-0.4.0/src/ajax/environments/differentiable.py +172 -0
  112. ajax_rl-0.4.0/src/ajax/environments/interaction.py +1236 -0
  113. ajax_rl-0.4.0/src/ajax/environments/model_reference.py +298 -0
  114. ajax_rl-0.4.0/src/ajax/environments/obs_norm.py +86 -0
  115. ajax_rl-0.4.0/src/ajax/environments/pid_terms.py +188 -0
  116. ajax_rl-0.4.0/src/ajax/environments/row_collector.py +600 -0
  117. ajax_rl-0.4.0/src/ajax/environments/system_class.py +163 -0
  118. ajax_rl-0.4.0/src/ajax/environments/utils.py +453 -0
  119. ajax_rl-0.4.0/src/ajax/evaluate.py +845 -0
  120. ajax_rl-0.4.0/src/ajax/extensions/__init__.py +15 -0
  121. ajax_rl-0.4.0/src/ajax/extensions/adversarial.py +126 -0
  122. ajax_rl-0.4.0/src/ajax/extensions/base.py +712 -0
  123. ajax_rl-0.4.0/src/ajax/extensions/capabilities.py +186 -0
  124. ajax_rl-0.4.0/src/ajax/extensions/ensemble.py +82 -0
  125. ajax_rl-0.4.0/src/ajax/extensions/expert.py +669 -0
  126. ajax_rl-0.4.0/src/ajax/extensions/exploration.py +452 -0
  127. ajax_rl-0.4.0/src/ajax/extensions/instrumentation.py +541 -0
  128. ajax_rl-0.4.0/src/ajax/extensions/offline.py +203 -0
  129. ajax_rl-0.4.0/src/ajax/extensions/pretrain.py +1072 -0
  130. ajax_rl-0.4.0/src/ajax/extensions/target_mods.py +527 -0
  131. ajax_rl-0.4.0/src/ajax/log.py +360 -0
  132. ajax_rl-0.4.0/src/ajax/logging/__init__.py +0 -0
  133. ajax_rl-0.4.0/src/ajax/logging/wandb_logging.py +352 -0
  134. ajax_rl-0.4.0/src/ajax/modules/__init__.py +1 -0
  135. ajax_rl-0.4.0/src/ajax/modules/pid_actor.py +194 -0
  136. ajax_rl-0.4.0/src/ajax/modules/pid_head.py +128 -0
  137. ajax_rl-0.4.0/src/ajax/networks/__init__.py +0 -0
  138. ajax_rl-0.4.0/src/ajax/networks/blocks.py +184 -0
  139. ajax_rl-0.4.0/src/ajax/networks/distributions.py +144 -0
  140. ajax_rl-0.4.0/src/ajax/networks/memory.py +634 -0
  141. ajax_rl-0.4.0/src/ajax/networks/networks.py +882 -0
  142. ajax_rl-0.4.0/src/ajax/networks/utils.py +331 -0
  143. ajax_rl-0.4.0/src/ajax/normalizers.py +155 -0
  144. ajax_rl-0.4.0/src/ajax/perf_utils.py +177 -0
  145. ajax_rl-0.4.0/src/ajax/reproduction.py +37 -0
  146. ajax_rl-0.4.0/src/ajax/schedule.py +39 -0
  147. ajax_rl-0.4.0/src/ajax/state.py +344 -0
  148. ajax_rl-0.4.0/src/ajax/types.py +52 -0
  149. ajax_rl-0.4.0/src/ajax/utils.py +99 -0
  150. ajax_rl-0.4.0/src/ajax/wrappers.py +907 -0
ajax_rl-0.4.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 YannBerthelot
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
ajax_rl-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,365 @@
1
+ Metadata-Version: 2.4
2
+ Name: ajax-rl
3
+ Version: 0.4.0
4
+ Summary: Agents in JAX: Jax based implementations of RL algorithms
5
+ Keywords: reinforcement-learning,jax,flax,gymnax,brax
6
+ Author: Yann Berthelot
7
+ Author-email: Yann Berthelot <yannberthelot1@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Requires-Dist: tqdm>=4.65.0,<5
17
+ Requires-Dist: jax>=0.10.0
18
+ Requires-Dist: flax>=0.12.8
19
+ Requires-Dist: chex>=0.1.91,<0.2
20
+ Requires-Dist: numpy>=2.1,<3
21
+ Requires-Dist: optax>=0.2.6,<0.3
22
+ Requires-Dist: flashbax>=0.1.3,<0.2
23
+ Requires-Dist: gymnax>=1.0.1,<2
24
+ Requires-Dist: distrax>=0.1.9
25
+ Requires-Dist: tensorboardx>=2.6.4,<3
26
+ Requires-Dist: brax>=0.14.2 ; extra == 'brax'
27
+ Requires-Dist: adastop ; extra == 'compare'
28
+ Requires-Dist: jax[cuda]>=0.10.0 ; sys_platform == 'linux' and extra == 'cuda'
29
+ Requires-Dist: ajax-rl[brax] ; extra == 'playground'
30
+ Requires-Dist: playground>=0.2.0,<0.3 ; extra == 'playground'
31
+ Requires-Dist: huggingface-hub>=0.30,<2 ; extra == 'reproduction'
32
+ Requires-Dist: pandas>=2.2,<3 ; extra == 'reproduction'
33
+ Requires-Dist: pyarrow>=15 ; extra == 'reproduction'
34
+ Requires-Dist: wandb>=0.19.9 ; extra == 'wandb'
35
+ Requires-Python: >=3.12
36
+ Project-URL: Homepage, https://github.com/YannBerthelot/Ajax
37
+ Project-URL: Documentation, https://yannberthelot.github.io/Ajax/
38
+ Project-URL: Repository, https://github.com/YannBerthelot/Ajax
39
+ Project-URL: Issues, https://github.com/YannBerthelot/Ajax/issues
40
+ Provides-Extra: brax
41
+ Provides-Extra: compare
42
+ Provides-Extra: cuda
43
+ Provides-Extra: playground
44
+ Provides-Extra: reproduction
45
+ Provides-Extra: wandb
46
+ Description-Content-Type: text/markdown
47
+
48
+ <h1 align="center">Ajax</h1>
49
+
50
+ <h3 align="center">
51
+ Reinforcement-learning agents in JAX, compiled end to end with the environment,<br/>
52
+ including average-reward, expert-guided and world-model agents.
53
+ </h3>
54
+
55
+ <p align="center"><i>A whole training run, environment and every seed included, one compiled program.</i></p>
56
+
57
+ <p align="center">
58
+ <a href="https://yannberthelot.github.io/Ajax/"><img alt="Documentation" src="https://img.shields.io/badge/docs-yannberthelot.github.io%2FAjax-blue"></a>
59
+ <a href="https://github.com/YannBerthelot/Ajax/actions/workflows/ci.yml"><img alt="CI" src="https://img.shields.io/github/actions/workflow/status/YannBerthelot/Ajax/ci.yml?branch=main&label=CI"></a>
60
+ <img alt="Python" src="https://img.shields.io/badge/python-3.12%20%7C%203.13%20%7C%203.14-blue">
61
+ <a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-green"></a>
62
+ <img alt="JAX" src="https://img.shields.io/badge/JAX-jit%20%7C%20vmap%20%7C%20grad-orange">
63
+ </p>
64
+
65
+ Ajax is a library of reinforcement-learning agents written in
66
+ [JAX](https://github.com/jax-ml/jax). Compared with
67
+ [Stable-Baselines3](https://github.com/DLR-RM/stable-baselines3) and its JAX
68
+ version [SBX](https://github.com/araffin/sbx), it differs in four ways:
69
+
70
+ - **[End to end on the accelerator](docs/guide/performance.md)**: the
71
+ environment and the training loop compile into one JAX program, as in
72
+ [PureJaxRL](https://github.com/luchris429/purejaxrl),
73
+ [Rejax](https://github.com/keraJLi/rejax),
74
+ [Stoix](https://github.com/EdanToledo/Stoix) and
75
+ [Brax](https://github.com/google/brax)'s training agents, with no Python
76
+ step between them, on a CPU or a GPU.
77
+ - **Average-reward agents**: [ASAC](docs/algorithms/asac.md) and
78
+ [APO](docs/algorithms/apo.md) maximise the reward per step, with no
79
+ discount, for tasks that never end.
80
+ - **[Expert-guided agents](docs/guide/expert-guidance.md)**: learn from a
81
+ controller you already have, or from recorded transitions, by cloning,
82
+ imitation, residual policies, hand-over, prior data in the replay or
83
+ offline training ([methods below](#learning-from-an-expert-or-from-data)).
84
+ - **[World models](docs/guide/world-models.md)**: DreamerV3 and TD-MPC2,
85
+ following the code behind their papers' results.
86
+
87
+ [Why Ajax](docs/getting-started/why-ajax.md) shows each with an example and
88
+ compares Ajax with SB3, SBX, PureJaxRL, Brax, Stoix and Rejax, including
89
+ when to use them instead.
90
+
91
+ It has sixteen agents, from SAC and PPO to DreamerV3 and TD-MPC2, each
92
+ implementing a published paper, with the places where it departs from that
93
+ paper written down. Several seeds train side by side in one program, on a CPU
94
+ or a GPU. Research features (learning from an expert, exploration rules,
95
+ diagnostics) are *extensions*, passed as `extensions=(...)` rather than added
96
+ as new arguments to the agents. An agent refuses, when built, an extension
97
+ it cannot run; the [compatibility table](docs/guide/compatibility.md) shows
98
+ which agent runs which.
99
+
100
+ ---
101
+
102
+ ## Installation
103
+
104
+ Ajax is on PyPI as `ajax-rl`, for Python 3.12 or newer, and imports as
105
+ `ajax`:
106
+
107
+ ```bash
108
+ pip install ajax-rl
109
+ pip install "ajax-rl[playground]" # with Brax and MuJoCo Playground
110
+ ```
111
+
112
+ JAX comes for the CPU; on a Linux machine with an NVIDIA GPU, add CUDA with
113
+ `ajax-rl[cuda]`. Brax and MuJoCo Playground environments need an extra:
114
+ `ajax-rl[playground]`, which brings Brax, or `ajax-rl[brax]` alone
115
+ ([Installation](docs/getting-started/installation.md#extras)). pip takes the
116
+ newest versions that `pyproject.toml` allows; main installs with
117
+ `pip install "ajax-rl @ git+https://github.com/YannBerthelot/Ajax.git"`.
118
+
119
+ From source, [uv](https://docs.astral.sh/uv/) installs the versions in
120
+ `uv.lock`, which CI tests, with the development tools and the `playground`
121
+ extra (`uv sync --extra cuda` adds CUDA):
122
+
123
+ ```bash
124
+ git clone https://github.com/YannBerthelot/Ajax.git
125
+ cd Ajax
126
+ uv sync # creates .venv with the locked dependencies
127
+ ```
128
+
129
+ [Installation](docs/getting-started/installation.md) covers the extras
130
+ (`cuda`, `compare`, `reproduction`) and the dependency groups.
131
+
132
+ ## Quickstart
133
+
134
+ ```python
135
+ from ajax import PPO
136
+ from ajax.logging.wandb_logging import LoggingConfig
137
+
138
+ agent = PPO("CartPole-v1") # 4 environments x 2048-step rollouts: one update per 8,192 steps
139
+ # Evaluate after every update; use_wandb=False keeps the results in memory only.
140
+ logging = LoggingConfig(config={}, log_frequency=8_192, use_wandb=False)
141
+ state, evaluations = agent.train(seed=[1, 2, 3], n_timesteps=40_960, logging_config=logging)
142
+
143
+ print(evaluations["timestep"][0]) # when each evaluation ran
144
+ print(evaluations["Eval/episodic mean reward"]) # one row per seed, one column per evaluation
145
+ ```
146
+
147
+ The three seeds train together, and the run takes about fifteen seconds on a
148
+ laptop CPU, compilation included. `evaluations` maps each logged name to an
149
+ array of shape `(seeds, evaluations)`; `"Eval/episodic mean reward"` is the
150
+ mean return of 10 test episodes (`num_episode_test`). With `use_wandb=True` (the default) or
151
+ `use_tensorboard=True`, the same records also go to Weights & Biases or
152
+ TensorBoard. To train further, pass the state back:
153
+ `agent.train(seed=[1, 2, 3], n_timesteps=more, initial_state=state)`.
154
+
155
+ Features are arguments of the same agents:
156
+
157
+ ```python
158
+ from ajax import PPO, SAC
159
+ from ajax.extensions.instrumentation import ConditioningMetrics
160
+
161
+ # A recurrent actor and critic, for when one observation is not enough.
162
+ agent = SAC("Pendulum-v1", memory={"kind": "lstm", "hidden_size": 64})
163
+
164
+ # A research feature as an extension: the critic's health at each evaluation.
165
+ agent = PPO("CartPole-v1", expose_recent_rollout=True, extensions=(ConditioningMetrics(),))
166
+
167
+ # Brax and MuJoCo Playground environments by id (their extras), here 8 copies in parallel.
168
+ agent = PPO("ant", n_envs=8)
169
+ ```
170
+
171
+ The [quickstart guide](docs/getting-started/quickstart.md) goes on from here.
172
+
173
+ ---
174
+
175
+ ## Agents
176
+
177
+ | Agent | Kind | Paper | Actions | Memory |
178
+ | --- | --- | --- | --- | --- |
179
+ | [`SAC`](docs/algorithms/sac.md) | off-policy | Haarnoja et al., *Soft Actor-Critic*, 2018 ([arXiv:1801.01290](https://arxiv.org/abs/1801.01290)) | continuous | yes |
180
+ | [`ASAC`](docs/algorithms/asac.md) | off-policy, average reward | Adamczyk et al., *Average-Reward Soft Actor-Critic*, 2025 ([arXiv:2501.09080v2](https://arxiv.org/abs/2501.09080v2)) | continuous | yes |
181
+ | [`REDQ`](docs/algorithms/redq.md) | off-policy | Chen et al., *Randomized Ensembled Double Q-Learning*, 2021 ([arXiv:2101.05982](https://arxiv.org/abs/2101.05982)) | continuous | yes |
182
+ | [`TD3`](docs/algorithms/td3.md) | off-policy | Fujimoto et al., *Addressing Function Approximation Error in Actor-Critic Methods*, 2018 ([arXiv:1802.09477](https://arxiv.org/abs/1802.09477)) | continuous | yes |
183
+ | [`AVG`](docs/algorithms/avg.md) | incremental, no replay | Vasan et al., *Deep Policy Gradient Methods Without Batch Updates, Target Networks, or Replay Buffers*, 2024 ([arXiv:2411.15370](https://arxiv.org/abs/2411.15370)) | continuous | no |
184
+ | [`IQL`](docs/algorithms/iql.md) | offline | Kostrikov, Nair & Levine, *Offline Reinforcement Learning with Implicit Q-Learning*, ICLR 2022 ([arXiv:2110.06169](https://arxiv.org/abs/2110.06169)) | continuous | no |
185
+ | [`DQN`](docs/algorithms/dqn.md) | off-policy, value-based | Mnih et al., *Human-level control through deep reinforcement learning*, Nature 2015 | discrete | no |
186
+ | [`PQN`](docs/algorithms/pqn.md) | on-policy, value-based | Gallici et al., *Simplifying Deep Temporal Difference Learning*, 2024 | discrete | no |
187
+ | [`PPO`](docs/algorithms/ppo.md) | on-policy | Schulman et al., *Proximal Policy Optimization Algorithms*, 2017 ([arXiv:1707.06347](https://arxiv.org/abs/1707.06347)) | both | yes |
188
+ | [`APO`](docs/algorithms/apo.md) | on-policy, average reward | Ma et al., *Average-Reward Reinforcement Learning with Trust Region Methods*, 2021 ([arXiv:2106.03442](https://arxiv.org/abs/2106.03442)) | both | no |
189
+ | [`UDRL`](docs/algorithms/udrl.md) | supervised, command-conditioned | Schmidhuber, *Reinforcement Learning Upside Down*, 2019 ([arXiv:1912.02875](https://arxiv.org/abs/1912.02875)) | both | no |
190
+ | [`DAgger`](docs/algorithms/dagger.md) | imitation, supervised | Ross, Gordon & Bagnell, *A Reduction of Imitation Learning and Structured Prediction to No-Regret Online Learning*, AISTATS 2011 ([arXiv:1011.0686](https://arxiv.org/abs/1011.0686)) | both | no |
191
+ | [`APG`](docs/algorithms/apg.md) | differentiable simulation | Analytic policy gradient through the simulator; `APG.contextual_controller` is Busetto et al., *One controller to rule them all*, 2024 ([arXiv:2411.06482](https://arxiv.org/abs/2411.06482)) | continuous | yes |
192
+ | [`DreamerV3`](docs/algorithms/dreamerv3.md) | world model | Hafner et al., *Mastering Diverse Domains through World Models*, 2023, Nature 2025 ([arXiv:2301.04104v2](https://arxiv.org/abs/2301.04104v2)) | both | built in |
193
+ | [`TDMPC2`](docs/algorithms/tdmpc2.md) | world model, planning | Hansen, Su & Wang, *TD-MPC2: Scalable, Robust World Models for Continuous Control*, ICLR 2024 ([arXiv:2310.16828](https://arxiv.org/abs/2310.16828)) | continuous | no |
194
+ | [`TDMPC2MultiTask`](docs/algorithms/tdmpc2.md) | world model, offline | The same paper's multi-task agent: one model trained offline on the data of several tasks | continuous | no |
195
+
196
+ *Memory* says whether the agent accepts `memory=`; DreamerV3's world model is
197
+ recurrent by design. Every agent is importable from `ajax`
198
+ (`from ajax import TD3`). The [algorithms overview](docs/algorithms/index.md)
199
+ helps choose one.
200
+
201
+ ---
202
+
203
+ ## Learning from an expert or from data
204
+
205
+ Each method is an extension or an agent option. The last column lists the
206
+ agents that accept it, as the [compatibility table](docs/guide/compatibility.md),
207
+ generated from the code, does.
208
+
209
+ | Method | In Ajax | Agents |
210
+ | --- | --- | --- |
211
+ | Behaviour cloning before training | `CloningPretrain` | SAC, TD3, REDQ, ASAC, AVG, APO, DAgger |
212
+ | TD3+BC's actor term (Fujimoto and Gu, 2021); kickstarting (Schmitt et al., 2018) with `anneal_frac` | `ImitationLoss` | SAC, TD3, REDQ, ASAC, AVG, APO, DAgger; PPO, APG, UDRL with a stateless expert; continuous actions only |
213
+ | Q-filtered behaviour cloning (Nair et al., 2018) | `ImitationLoss(q_filter=True)` | SAC, TD3, REDQ, ASAC, AVG |
214
+ | IBRL targets (Hu et al., 2023) | `IBRL` | SAC, TD3, REDQ, AVG |
215
+ | Residual RL (Johannink et al., 2019) | `ResidualPolicy` | SAC |
216
+ | Jump-start RL hand-over (Uchendu et al., 2023) | `JSRLCurriculum` | SAC |
217
+ | Expert transitions in the replay before training | `expert_buffer_n_steps` | SAC |
218
+ | Prior data in the replay, as RLPD (Ball et al., 2023) without its symmetric sampling, then optional offline updates | `PriorData` with a transition dataset (`ajax.buffers.dataset`) | SAC, TD3, REDQ, ASAC, DQN |
219
+ | Offline training on a transition dataset, then online fine-tuning | `agent.train_offline(dataset, n_updates)` | SAC, TD3, REDQ, ASAC, DQN, IQL |
220
+ | Implicit Q-learning, offline then online (IQL, Kostrikov et al., 2022) | [`IQL`](docs/algorithms/iql.md) with `train_offline` | its own agent |
221
+ | Conservative Q-learning, offline (CQL, Kumar et al., 2020); calibrated (Cal-QL, Nakamoto et al., 2023) | [`ConservativeQ`, `CalQL`](docs/algorithms/sac.md#cql-and-cal-ql-offline) on SAC, trained with `train_offline` | CQL: SAC, REDQ, ASAC, IQL; Cal-QL: SAC, REDQ, IQL |
222
+ | ReBRAC, offline (Tarasov et al., 2023) | [`TD3` with TD3+BC's term and `TargetBC`](docs/algorithms/td3.md#rebrac-offline), trained with `train_offline` | TD3 |
223
+ | Adversarial imitation from demonstrations, with no reward (GAIL, Ho and Ermon, 2016) | [`AdversarialReward`](docs/algorithms/ppo.md#gail-imitation-by-a-discriminator) with a transition dataset | PPO, continuous actions |
224
+ | TD3+BC, offline (Fujimoto and Gu, 2021) | [`TD3` with `ImitationLoss(None, target="replay", alpha=2.5)`](docs/algorithms/td3.md#td3bc-offline), trained with `train_offline` | TD3; the term on SAC, REDQ, ASAC too |
225
+ | Offline multi-task training on pooled datasets (TD-MPC2, Hansen et al., 2024) | `TDMPC2MultiTask` | its own agent |
226
+ | Interactive imitation by dataset aggregation, with no reward (DAgger, Ross et al., 2011) | `DAgger` | its own agent |
227
+ | Features developed with Ajax, with no external reference: EDGE exploration, LCB-gated targets, a value-gated hand-over, an expert critic fitted to Monte-Carlo returns and the extensions that read it | `EDGEExploration`, `LCBGatedBootstrap`, `ValueBox`, `MCPretrain`, ... | SAC (LCB: SAC, TD3, REDQ) |
228
+
229
+ [Expert guidance](docs/guide/expert-guidance.md) explains the expert's
230
+ conventions and how the pieces combine.
231
+
232
+ ---
233
+
234
+ ## What else is in the box
235
+
236
+ - **[Extensions](docs/guide/extensions.md)**: twenty-four of them, for expert
237
+ guidance, exploration, critic-target changes, actor and critic
238
+ pre-training, prior data, offline RL, adversarial imitation, ensemble
239
+ diversity and critic diagnostics, passed as `extensions=(...)`; the [compatibility table](docs/guide/compatibility.md)
240
+ says which agents run each one.
241
+ - **[Expert guidance](docs/guide/expert-guidance.md)**: the expert reads the
242
+ environment's raw observations and answers in the environment's action
243
+ units; an expert with a state, such as a PID's integral, gets it back at
244
+ every step.
245
+ - **[Recurrent memory](docs/guide/memory.md)**: a GRU, LSTM, transformer or
246
+ Mamba block for PPO, SAC, TD3, REDQ, ASAC and APG, with R2D2-style sequence
247
+ replay (burn-in, stored state) for the replay agents.
248
+ - **[Differentiable simulation](docs/guide/differentiable-simulation.md)**: APG
249
+ back-propagates the return through gymnax dynamics, across *system classes*
250
+ (distributions over physical parameters), with Busetto et al.'s in-context
251
+ controller and its staged curriculum.
252
+ - **[World models](docs/guide/world-models.md)**: DreamerV3 and TD-MPC2
253
+ (single- and multi-task), following the paper-era official code, with
254
+ [specifications, deviations and parity tests](docs/world_models/README.md)
255
+ against that code.
256
+ - **[Networks and the PID policy](docs/guide/networks.md)**: layers and
257
+ initialisers named by strings, a CNN encoder for image observations (PPO,
258
+ DQN, PQN, UDRL), and a PID controller as the actor of SAC, TD3, REDQ, ASAC,
259
+ AVG, PPO or APO, with learned fixed gains that deploy as a plain PID, or
260
+ gains scheduled on the observation. Where an agent starts from its
261
+ reference code's initialisation and optimiser settings, its algorithm page
262
+ says so and cites the code.
263
+ - **[Environments](docs/guide/environments.md)**: gymnax, Brax and MuJoCo
264
+ Playground by id, `n_envs` copies in parallel, terminations kept apart from
265
+ time limits (a truncated episode still bootstraps), `episode_length` and
266
+ `action_repeat` on every agent, and wrappers for normalisation, observation
267
+ noise, fixed initial states, model-reference tracking and PID error terms.
268
+ Every continuous agent acts in `[-1, 1]`, mapped onto the environment's
269
+ action bounds.
270
+ - **[Logging](docs/guide/logging.md)**: `train` returns every evaluation as
271
+ arrays, with training diagnostics (gradient norms, PPO's approximate KL,
272
+ explained variance, ...) and each extension's own metrics, and a background
273
+ worker sends them to Weights & Biases or TensorBoard.
274
+ - **[Comparing agents](docs/guide/comparing-agents.md)**: `ajax.compare` runs
275
+ AdaStop (Mathieu et al., 2024), which trains more seeds only while the
276
+ answer is unclear, and `ajax.compare.estimate` gives one agent's metrics
277
+ confidence intervals that stay valid however many seeds are added.
278
+ - **[Reproduction](docs/reproduction/index.md)**: Ajax agents trained beside
279
+ a reference implementation (Stable-Baselines3, Brax, the authors' code) on
280
+ the same JAX environment, run on demand from
281
+ [`benchmarks/reference`](benchmarks/reference/README.md), under a written
282
+ protocol; the results so far cover PPO and PQN.
283
+ - **[Checkpoints and resuming](docs/guide/checkpoints.md)**: pass a state back
284
+ to train further, or save it and resume in another process; the tests
285
+ check that a split run matches the run left whole.
286
+ - **[Tests](docs/developer/testing.md)**: unit tests check one component
287
+ against an exact contract with no learning, written once for every agent or
288
+ extension that shares the contract. Probes are tiny generic environments
289
+ with known answers: each agent trains on them briefly, and each probe checks
290
+ one capability of the whole agent. A catalogue of planted bugs lists the
291
+ probes that should catch each one; CI checks that every bug still applies
292
+ to the code, and planting them to run the probes is done by hand.
293
+ Conformance checks run one update of an agent and of its original
294
+ implementation from the same state and compare them (PQN, TD3, TD3+BC,
295
+ REDQ and AVG so far).
296
+ - **[Performance](docs/guide/performance.md)**: seeds vectorised with
297
+ `jax.vmap`, a persistent compile cache, one per machine and JAX version, and
298
+ a per-agent benchmark script, run by hand, that flags slowdowns over 10%
299
+ against a recorded baseline.
300
+
301
+ ---
302
+
303
+ ## Documentation
304
+
305
+ | | |
306
+ | --- | --- |
307
+ | **[Getting started](docs/getting-started/installation.md)** | Installation and a guided quickstart |
308
+ | **[User guide](docs/guide/training.md)** | Training, environments, networks, memory, logging, checkpoints, performance |
309
+ | **[Research features](docs/guide/extensions.md)** | Extensions, compatibility, expert guidance, comparing agents, differentiable simulation, world models |
310
+ | **[Reproduction](docs/reproduction/index.md)** | Ajax against reference implementations: protocol, specifications, results |
311
+ | **[Algorithms](docs/algorithms/index.md)** | One page per agent: the paper, when to use it, an example, its parameters and deviations |
312
+ | **[API reference](https://yannberthelot.github.io/Ajax/api/agents/)** | Generated from the docstrings |
313
+ | **[Developer guide](docs/developer/architecture.md)** | Architecture, contributing, writing an extension, testing, performance |
314
+ | **[World model design notes](docs/world_models/README.md)** | DreamerV3 and TD-MPC2 specifications, deviations and validation |
315
+
316
+ The site, with search and navigation, is at
317
+ **[yannberthelot.github.io/Ajax](https://yannberthelot.github.io/Ajax/)**. The
318
+ links above point at the Markdown in this repository, which also reads on
319
+ GitHub.
320
+
321
+ ---
322
+
323
+ ## Related projects
324
+
325
+ - **[TargetGym](https://github.com/YannBerthelot/TargetGym)**: JAX environments
326
+ for reaching and holding a setpoint, with tuned PID and MPC baselines. A
327
+ scenario of Ajax's `benchmarks/perf_bench.py` trains on one of its aircraft
328
+ tasks (`uv sync --group plane`).
329
+ - **[ProbingEnvironments](https://github.com/YannBerthelot/ProbingEnvironments)**:
330
+ small environments with known answers, used by Ajax's probing tests.
331
+ - **[gymnax](https://github.com/RobertTLange/gymnax)**,
332
+ **[Brax](https://github.com/google/brax)** and
333
+ **[MuJoCo Playground](https://github.com/google-deepmind/mujoco_playground)**:
334
+ the environment libraries Ajax trains on.
335
+ - **[flashbax](https://github.com/instadeepai/flashbax)**: the replay buffers of
336
+ SAC, ASAC, REDQ, TD3, DQN, IQL and DAgger (UDRL and the world models keep
337
+ their own).
338
+
339
+ ---
340
+
341
+ ## Contributing
342
+
343
+ Bug reports, new agents and new extensions are welcome. After installing, run
344
+ `uv run pre-commit install` once, so ruff and mypy check every commit.
345
+ [CONTRIBUTING.md](CONTRIBUTING.md) explains where the code lives, how to add an
346
+ agent or an extension, and how the tests check them. Every pull request
347
+ runs pre-commit, the tests, the conformance checks and a strict build of the
348
+ documentation site in CI; the slow tier, every test that trains, also runs
349
+ daily on main, on a pull request labelled `run-slow-tier`, and before each
350
+ release. `make ci` runs the checks locally (about an hour of CPU).
351
+
352
+ ## Citation
353
+
354
+ ```bibtex
355
+ @misc{ajax2025,
356
+ title = {Ajax: Reinforcement Learning Agents in Jax},
357
+ author = {Yann Berthelot},
358
+ year = {2025},
359
+ url = {https://github.com/YannBerthelot/Ajax},
360
+ }
361
+ ```
362
+
363
+ ## License
364
+
365
+ MIT, see [LICENSE](LICENSE).