Implementation:Google deepmind Mujoco MJWarp Viewer
| Knowledge Sources | |
|---|---|
| Domains | Physics_Simulation, GPU_Computing, NVIDIA_Warp |
| Last Updated | 2026-02-15 04:00 GMT |
Overview
MJWarp Viewer is a command-line application that loads MJCF models and runs interactive simulation using MuJoCo Warp with the MuJoCo passive viewer.
Description
This module implements the mjwarp-viewer command-line tool for loading and interactively simulating MJCF/MJB models using MuJoCo Warp. It supports CUDA graph capture for optimized step replay, hot-recompilation when simulation options change in the viewer UI, keyframe initialization, model overrides via command-line flags, trajectory replay from keyframe sequences, and both Warp GPU and MuJoCo C engine backends. The viewer synchronizes GPU-computed state back to MuJoCo's native viewer for visualization, with space bar pause/resume and period for single-step.
Usage
Run from the command line as mjwarp-viewer <path_to_mjcf.xml> with optional flags for engine selection, contact limits, device override, model overrides, and keyframe selection.
Code Reference
Source Location
- Repository: Google_deepmind_Mujoco
- File: mjx/mujoco/mjx/third_party/mujoco_warp/viewer.py
- Lines: 1-221
Key Functions
# Engine selection enum
class EngineOptions(enum.IntEnum):
WARP = 0
C = 1
# Main application entry point
def main()
def _main(argv: Sequence[str]) -> None
# Model loading
def _load_model(path: epath.Path) -> mujoco.MjModel
# CUDA graph compilation
def _compile_step(m, d) -> graph
# Keyboard callback for pause/step
def key_callback(key: int) -> None
# Command-line flags
_CLEAR_WARP_CACHE, _ENGINE, _NCONMAX, _NJMAX, _NCCDMAX
_OVERRIDE, _KEYFRAME, _DEVICE, _REPLAY
Import
from mujoco.mjx.third_party.mujoco_warp.viewer import main
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| argv[1] | str | Yes | Path to MJCF XML or MJB binary model file |
| --engine | EngineOptions | No | Simulation engine: WARP (default) or C |
| --nconmax | int | No | Maximum number of contacts |
| --njmax | int | No | Maximum number of constraints per world |
| --override / -o | str | No | Model overrides (e.g., "opt.solver=cg") |
| --keyframe | int | No | Keyframe index to initialize from (default 0) |
| --device | str | No | Warp device override |
| --replay | str | No | Keyframe name prefix for trajectory replay |
Outputs
| Name | Type | Description |
|---|---|---|
| (interactive) | viewer window | Real-time visualization of MuJoCo Warp simulation in MuJoCo viewer |