Skip to main content

A lightweight utility library for reinforcement learning projects in JAX and Equinox.

Project description

Jaxnasium: A Lightweight Utility Library for JAX-based RL Projects

PyPI version Python 3.11+ Ruff Documentation Status

Jaxnasium lets you

  1. 🕹️ Import your favourite environments from various libraries with a single API and automatically wrap them to a common standard.
  2. 🚀 Bootstrap new JAX RL projects with a single CLI command and get started instantly with a complete codebase.
  3. 🤖 Jaxnasium comes equiped with standard general RL implementations based on a near-single-file philosophy. You can either import these as off-the-shelf algorithms or copy over the code and tweak them for your problem. These algorithms follow the ideas of PureJaxRL for extremely fast end-to-end RL training in JAX.

For more details, see the 📖 Documentation.

🚀 Getting started

Jaxnasium lets you bootstrap your new reinforcement learning projects directly from the command line. As such, for new projects, the easiest way to get started is via uv:

uvx jaxnasium <projectname>
uv run example_train.py

# ... or via pipx
pipx run jaxnasium <projectname>
# activate a virtual environment in your preferred way, e.g. conda
python example_train.py

This will set up a Python project folder structure with (optionally) an environment template and (optionally) algorithm code for you to tailor to your problem.

For existing projects, you can simply install Jaxnasium via pip and import the required functionality.

pip install jaxnasium
import jax
import jaxnasium as jym
from jaxnasium.algorithms import PPO

env = jym.make("CartPole-v1")
env = jaxnasium.LogWrapper(env)
rng = jax.random.PRNGKey(0)
agent = PPO(total_timesteps=5e5, learning_rate=2.5e-3)
agent = agent.train(rng, env)

🏠 Environments

Jaxnasium is not aimed at delivering a full environment suite. However, it does come equipped with a jym.make(...) command to import environments from existing suites (provided that these are installed) and wrap them appropriately to the Jaxnasium API standard. For example, using environments from Gymnax:

import jaxnasium as jym
from jaxnasium.algorithms import PPO
import jax

env = jym.make("Breakout-MinAtar")
env = jym.FlattenObservationWrapper(env)
env = jym.LogWrapper(env)

agent = PPO(**some_good_hyperparameters)
agent = agent.train(jax.random.PRNGKey(0), env)

# > Using an environment from Gymnax via gymnax.make(Breakout-MinAtar).
# > Wrapping Gymnax environment with GymnaxWrapper
# >  Disable this behavior by passing wrapper=False
# > Wrapping environment in VecEnvWrapper
# > ... training results

!!!info For convenience, Jaxnasium does include the 5 classic-control environments.

See the Environments page for a complete list of available environments.

Environment API

The Jaxnasium API stays close to the somewhat established Gymnax API for the reset() and step() functions, but allows for truncated episodes in a manner closer to Gymnasium.

env = jym.make(...)

obs, env_state = env.reset(key) # <-- Mirroring Gymnax

# env.step(): Gymnasium Timestep tuple with state information
(obs, reward, terminated, truncated, info), env_state = env.step(key, state, action)

🤖 Algorithms

Algorithms in jaxnasium.algorithms are built following a near-single-file implementation philosophy in mind. In contrast to implementations in CleanRL or PureJaxRL, Jaxnasium algorithms are built in Equinox and follow a class-based design with a familiar Stable-Baselines API.

from jaxnasium.algorithms import PPO
import jax

env = ...
agent = PPO(**some_good_hyperparameters)
agent = agent.train(jax.random.PRNGKey(0), env)

See the Algorithms for more details on the included algorithms..

Available Algorithms

Algorithm Multi-Agent1 Observation Spaces Action Spaces Composite (nested) Spaces2
PPO Box, Discrete, MultiDiscrete Box, Discrete, MultiDiscrete
DQN Box, Discrete, MultiDiscrete Discrete, MultiDiscrete3
PQN Box, Discrete, MultiDiscrete Discrete, MultiDiscrete3
SAC Box, Discrete, MultiDiscrete Box, Discrete, MultiDiscrete

1 All algorithms support automatic multi-agent transformation through the auto_upgrade_multi_agent parameter. See Multi-Agent documentation for more information.

2 Algorithms support composite (nested) spaces. See Spaces documentation for more information.

3 MultiDiscrete action spaces in PQN and DQN are only supported when flattening to a Discrete action space. E.g. via the FlattenActionSpaceWrapper.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jaxnasium-0.0.27.tar.gz (58.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jaxnasium-0.0.27-py3-none-any.whl (83.9 kB view details)

Uploaded Python 3

File details

Details for the file jaxnasium-0.0.27.tar.gz.

File metadata

  • Download URL: jaxnasium-0.0.27.tar.gz
  • Upload date:
  • Size: 58.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for jaxnasium-0.0.27.tar.gz
Algorithm Hash digest
SHA256 c49f069753885ad433e1329b72d37f6e1b66a155ddbbee1aa5bd6f75de84d91e
MD5 5c0ad3b2adb3e0f5b49bb71a6c986d95
BLAKE2b-256 21122a1aabb42e8bd7755ad19b01a07f9eed79637fd4cab9f93df1a13eba035f

See more details on using hashes here.

File details

Details for the file jaxnasium-0.0.27-py3-none-any.whl.

File metadata

  • Download URL: jaxnasium-0.0.27-py3-none-any.whl
  • Upload date:
  • Size: 83.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for jaxnasium-0.0.27-py3-none-any.whl
Algorithm Hash digest
SHA256 0f16f9ca64ddc92f5913d42d03c4fc641cf3ff606ba497aed0178fe501d579d7
MD5 28e5e59d2767f6dfe57d825e7fc2b011
BLAKE2b-256 4e67703587558904b2793fea00a0121105130aabae2cb5f404d1e3d3aea975c9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page