Skip to main content

JAX implementation of Vectorized Multi-Agent Simulator

Project description

JaxVMAS 🚀

PyPI version License JAX Coverage Tests MacOS Tests Ubuntu

JAX implementation of VMAS - A vectorized differentiable multi-agent simulator for MARL. This project is a direct port of the original PyTorch-based VMAS developed by the Prorok Lab, rewritten in JAX to provide JIT compilation support and enhanced performance on GPUs/TPUs.

Features ✨

  • JAX-native - GPU/TPU support with jax.jit compatibility
  • Vectorized - Batch thousands of environments simultaneously
  • Differentiable - End-to-end gradients through physics simulations
  • Interactive rendering - Visualize agent behaviors and interactions

Installation ⚙️

pip install jaxvmas

For GPU support, first install JAX with CUDA support.

Quick Start 🏃

import equinox as eqx
import jax
import jax.numpy as jnp
from jaxvmas.make_env import make_env
from jaxvmas.simulator.environment.environment import RenderObject

# Create a random key for initialization
key = jax.random.PRNGKey(0)

# Create vectorized environments
num_envs = 32
env = make_env(
    scenario="football",  # or "simple" from MPE scenarios
    num_envs=num_envs,
    PRNG_key=key,
    continuous_actions=True,
)
n_steps = 100

# Reset environment
env, obs = env.reset(PRNG_key=key)

actions = [None] * len(obs)
for i in range(len(obs)):
    n_envs = obs[i].shape[0]
    actions[i] = jnp.zeros((n_envs, 2))


render_object = RenderObject()
total_reward = 0
step = 0
for _ in range(n_steps):
    PRNG_key, key_step = jax.random.split(key)
    step += 1
    actions = [None] * len(obs)
    for i in range(len(obs)):
        key_step, key_step_i = jax.random.split(key_step)
        actions[i] = jnp.zeros((n_envs, 2))

    jitted_step = eqx.filter_jit(env.step)
    PRNG_key, key_step_i = jax.random.split(PRNG_key)
    env, (obs, rews, dones, info) = jitted_step(PRNG_key=key_step_i, actions=actions)

    rewards = jnp.stack(rews, axis=1)
    global_reward = rewards.mean(axis=1)
    mean_global_reward = global_reward.mean(axis=0)
    total_reward += mean_global_reward
    render_object, rgb_array = env.render(
        render_object=render_object,
        mode="rgb_array",
        agent_index_focus=None,
        visualize_when_rgb=True,
    )

Performance 🚀

Note: The following benchmarks are preliminary and not comprehensive. Your results may vary depending on hardware and specific scenarios.

Preliminary Benchmarking on Google Colab GPU

Configuration VMAS (original) JaxVMAS
1 environment, 200 steps ~24.63 seconds ~0.22 seconds simulation time
(+~222.87 seconds compile time)
Total: ~233 seconds
32 environments, 100,000 steps 25+ minutes (test stopped) ~75.20 seconds simulation time
(+~302.10 seconds compile time)
Total: ~387.05 seconds

JaxVMAS demonstrates significant speedup in actual simulation time after the initial compilation overhead.

Supported Scenarios 🎮

  • Football
  • MPE (Multi-Particle Environment):
    • Simple

Citing JaxVMAS 📖

If you use JaxVMAS in your research, please cite both JaxVMAS and the original VMAS:

@misc{jaxvmas2024,
  title={JaxVMAS: Multi-Agent Simulation of VMAS scenarios in JAX},
  author={Joseph Selvaraaj},
  year={2024},
  url = {https://github.com/jselvaraaj/JaxVMAS},
}

Please also cite the original VMAS paper:

@article{bettini2022vmas,
  title = {VMAS: A Vectorized Multi-Agent Simulator for Collective Robot Learning},
  author = {Bettini, Matteo and Kortvelesy, Ryan and Blumenkamp, Jan and Prorok, Amanda},
  year = {2022},
  journal={The 16th International Symposium on Distributed Autonomous Robotic Systems},
  publisher={Springer}
}

Related Projects

  • VMAS - Original PyTorch implementation by the Prorok Lab, on which JaxVMAS is based

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

jaxvmas-0.0.1a1.tar.gz (134.1 kB view details)

Uploaded Source

Built Distribution

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

jaxvmas-0.0.1a1-py3-none-any.whl (155.7 kB view details)

Uploaded Python 3

File details

Details for the file jaxvmas-0.0.1a1.tar.gz.

File metadata

  • Download URL: jaxvmas-0.0.1a1.tar.gz
  • Upload date:
  • Size: 134.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jaxvmas-0.0.1a1.tar.gz
Algorithm Hash digest
SHA256 5753c66da7706f026cdc2aece8d658c6d2aad60109121c402b074014658f8cfd
MD5 0f0ab0cddd7ef193ff291ec7487879d0
BLAKE2b-256 6046c8a4b2bde08c38bae01390382fd5d588953356d6c140ca51893a4a68f412

See more details on using hashes here.

Provenance

The following attestation bundles were made for jaxvmas-0.0.1a1.tar.gz:

Publisher: release.yml on jselvaraaj/JaxVMAS

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

File details

Details for the file jaxvmas-0.0.1a1-py3-none-any.whl.

File metadata

  • Download URL: jaxvmas-0.0.1a1-py3-none-any.whl
  • Upload date:
  • Size: 155.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for jaxvmas-0.0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 6391f68aea1446d479395076759708dd0cbea73a9c9eaacc5191581148a236a6
MD5 e26aa14ab8697b42f4a91202bb0b01cc
BLAKE2b-256 084c416656f849c5332373dc82086b723b2931a1d25919a6658a3796acd4f38a

See more details on using hashes here.

Provenance

The following attestation bundles were made for jaxvmas-0.0.1a1-py3-none-any.whl:

Publisher: release.yml on jselvaraaj/JaxVMAS

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