Skip to main content

mujax

Gumbel MuZero and Stochastic MuZero for Gymnasium environments, built on JAX, mctx and flashbax.

  • Two algorithms, one pipeline: GMZ (Gumbel MuZero) and SMZ (Stochastic MuZero with afterstates and a VQ chance codebook) share replay, reanalyze, actor, learner and checkpointing.
  • Single process: actors and evaluator run in threads on CPU, the learner runs on GPU when available. The CPU search releases the GIL, so num_actors actor threads (--num-actors) scale env throughput with the core count.
  • Reanalyze: a fraction of every batch is re-searched with the latest parameters.
  • Categorical value/reward with HL-Gauss targets in symlog space.
  • Symlog observations: raw observations enter the networks through signed_logp1 (DreamerV3), so no per-dimension normalization is needed.
  • Checkpoints: best parameters by evaluation score plus full training state for resuming (Orbax), optional W&B upload.

The design is inspired by DeepMind's Acme: the split into actor, learner, replay and environment loop, the observers and the counter follow Acme's structure, reduced to a small single-process library.

Requirements: 1-D Box observations and Discrete actions (use gym.wrappers.FlattenObservation otherwise). Illegal actions can be masked through info["invalid_actions"].

Installation

pip install mujax                 # CPU
pip install "mujax[cuda12]"       # NVIDIA GPU
pip install "mujax[wandb]"        # Weights & Biases logging

Command line

mujax --env CartPole-v1 --num-steps 20000 gmz --num-simulations  16
mujax --env Acrobot-v1 smz --batch-size 1024
mujax --help          # all options; `mujax gmz --help`, `mujax smz --help` for algorithm options

Checkpoints are written to checkpoints/<algo>_<timestamp>/.

Python API

import gymnasium as gym
from mujax import CheckpointingConfig, ExperimentConfig, GMZConfig, load_actor, run_experiment


def make_env(num_envs):
    return gym.make_vec(
        "CartPole-v1", num_envs=num_envs, vectorization_mode="sync", vector_kwargs={"autoreset_mode": gym.vector.AutoresetMode.SAME_STEP}
    )


run_experiment(
    ExperimentConfig(
        config=GMZConfig(batch_size=256).with_num_steps(20_000),
        environment_factory=lambda seed: make_env(16),
        eval_environment_factory=lambda seed: make_env(1),
        max_num_learner_steps=20_000,
        checkpointing=CheckpointingConfig(directory="checkpoints/cartpole"),
    )
)

actor, metadata = load_actor("checkpoints/cartpole")

Environments must use AutoresetMode.SAME_STEP. See examples/ for complete training (cartpole.py) and evaluation (evaluate.py) scripts.

Logging

create_writer sends metrics to the terminal and, optionally, Weights & Biases; learner, actor and evaluator metrics are written under learner/, actor/ and evaluator/ with learner_steps as the step:

writer = create_writer(console=True, wandb_project="mujax")
ExperimentConfig(..., writer=writer)

Any object with write(step, scalars), write_config(config) and close() works as a writer (mujax.Writer). Without a writer only the progress bar is shown.

On the command line metrics are printed to the terminal (--no-console turns it off); add --wandb (--wandb-project) for W&B.

Layout

Module Contents
config.py MuZeroConfig, shared hyperparameters
algorithm.py Algorithm, SearchPolicy: the contract between the infrastructure and an algorithm
algorithms/__init__.py ALGORITHMS registry, algorithm_for
algorithms/muzero.py shared math of the MuZero family: Support, network blocks, loss skeleton
algorithms/smz.py, algorithms/gmz.py algorithms: config, networks, search, loss
replay.py, reanalyze.py flashbax replay and reanalyze iterator
actor.py, learner.py, loop.py environment interaction, gradient step, environment loop
observers.py, loggers.py, checkpoint.py metrics, terminal and W&B writers, Orbax checkpoints
experiment.py ExperimentConfig, run_experiment, load_actor

Development

uv sync
uv run pytest

References

  • Schrittwieser et al., Mastering Atari, Go, Chess and Shogi by Planning with a Learned Model (2020)
  • Antonoglou et al., Planning in Stochastic Environments with a Learned Model (2022)
  • Danihelka et al., Policy Improvement by Planning with Gumbel (2022)
  • Hoffman et al., Acme: A Research Framework for Distributed Reinforcement Learning (2020)

License

Apache-2.0

Metadata

Release files for mujax 0.1.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 mujax 0.1.0
File Size Uploaded
mujax-0.1.0.tar.gz 45.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mujax 0.1.0
File Interpreter ABI Platform
mujax-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 90.5 kB

Release files / mujax-0.1.0.tar.gz

Download URL mujax-0.1.0.tar.gz
Size 45.2 kB
Tags Source
SHA-256 checksum
How to use checksums
90d713316acda2cd0e8b0131e4379deb75370a6f304cd40418fe4d3ede3bdbf9
BLAKE2b-256 checksum
How to use checksums
9328deeede80ddd68d28833f4074d5eb7fead8279e48b42fc36d77d3046330cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release files / mujax-0.1.0-py3-none-any.whl

Download URL mujax-0.1.0-py3-none-any.whl
Size 45.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dcbfe7b303765039540e0365010b46aa1e371c064c8a07f28c5faeef72539759
BLAKE2b-256 checksum
How to use checksums
37b5b34bc374701f60549525881f11f97f13e7dcac12ca54ed40f11cab9fd16a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

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