Skip to main content

Short description

Project description

MINIMAL-MJX

This repository represents starter code for MJX-based RL from the Dynamic Mobility Lab. The code has been built of off MuJoCo Playground and tailored to make policy training, saving, and evaluation easy and implements some nice-to-haves.

  1. Swappable backend, allowing for fast evaluation using numpy/C++ MuJoCo and fast training using JaX/MJX
  2. Base environment class that contains generic reward functions and useful functions
  3. Configuration files that allow you to set parameters for your envs + for PPO

There exists a requirements.txt in the home directory which includes the packages needed to run this code.

Steps to take to 'do RL'!

We will work of off the Cheetah environment from Deepmind's "DM Control". This guide is not meant to be comprehensive, but is hopefully enough information to fill in the gaps as you develop and look around the codebase.

  1. The setup basics

    Each environment has a reset and step function, which primarily operate off of a Markov Decision Process (MDP) state. In our case, this is represented as a class that looks like this

        @dataclass
        class MujocoState:
            data: mujoco.MjData
            obs: np.ndarray
            reward: float
            done: bool
            metrics: dict
            info: dict
    

    Note that you should treat info as a 'carry' variable between consecutive step functions. Store things here you need to use in future timesteps that are not ordinarily stored in data (i.e. store a history of system states x).

  2. Simulate your environment to make sure things look good

    Environments should be simulated and inspected before training. Once you are done developing your env, make a configuration file to specify variables specific to training runs, like PPO or reward weight parameters.

    For the Cheetah, one is already created. To simulate the environment, run

    python3 -m envs.simulate envs/dmcontrol/config/cheetah.yaml
    

    Under visualization, you should see a metrics plot as well as a video of your environment. Note that the policy here is simulated to output all zeros (see envs/simulate.py). Inspect these files to make sure things look good.

    For extra good measure, change the backend parameter in your config file to jnp to make sure your environment is JaX compatible.

  3. Train a policy

    Once your environment is ready and JaX compatible, you can train by running

    python3 -m learning.training.begin_run envs/dmcontrol/config/cheetah.yaml
    

    Note that this will train directly in your terminal session. A bash script has been provided at learning/training/train.sh that opens a tmux terminal for this (useful if you want to train for long periods of time). Make sure to change your conda environment name in this script.

    Within your save directory mentioned in your config file, a new directory will be created in which intermediate and final training results will be saved.

  4. Rollout your trained policy

    Once your policy is finished training, simply run

    python3 -m eval.rollout_policy envs/dmcontrol/config/cheetah.yaml
    

    This will rollout your policy, plot metrics of your reward function, and save a video of your result. Make sure to use an np backend for quick evaluation!

    If you would like to rollout older policies, check the directory of your past training runs. There should be a config there, and you can simply replace the config above with that one (running that specific older policy). Note that your code might have changed, so this config holds a git commit that references when the training was run.

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

minimal_mjx-0.1.11.tar.gz (18.8 kB view details)

Uploaded Source

Built Distribution

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

minimal_mjx-0.1.11-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file minimal_mjx-0.1.11.tar.gz.

File metadata

  • Download URL: minimal_mjx-0.1.11.tar.gz
  • Upload date:
  • Size: 18.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for minimal_mjx-0.1.11.tar.gz
Algorithm Hash digest
SHA256 3cf26ebd9dae4676cd8669a75cb9b7fb4bcb443206fe20bd514e07a10f4740bf
MD5 c31c2b53c908a4606d4f4b37da1a7683
BLAKE2b-256 fe2fa79a37be59dfbb2fda2c1282f97ee58e5a63723d721aaed5b5ec66fc9871

See more details on using hashes here.

Provenance

The following attestation bundles were made for minimal_mjx-0.1.11.tar.gz:

Publisher: publish.yml on dynamicmobility/minimal-mjx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file minimal_mjx-0.1.11-py3-none-any.whl.

File metadata

  • Download URL: minimal_mjx-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for minimal_mjx-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 5eabd71adbaa95aa38b10f79f2e0cace80cdc76e9fc50b5b7f1615828800a5dc
MD5 ac1821dd846a65319696b7c6aad869a5
BLAKE2b-256 73f283251aabaaf4253e0ee3a4fdb29408f8a9937a09382d4d93a0ef9a8616fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for minimal_mjx-0.1.11-py3-none-any.whl:

Publisher: publish.yml on dynamicmobility/minimal-mjx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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