Implementation:Google deepmind Mujoco mjx get data
Appearance
| Knowledge Sources | |
|---|---|
| Domains | GPU_Computing, Physics_Simulation, JAX |
| Last Updated | 2026-02-15 06:00 GMT |
Overview
Concrete tools for retrieving MJX simulation data from a JAX device to CPU provided by the MJX I/O module.
Description
mjx.get_data_into writes device data into pre-allocated CPU MjData objects (in-place, zero allocation). mjx.get_data allocates new MjData objects and fills them. Both handle single and batched data, dispatching to the appropriate backend (JAX, C, CPP, Warp).
Usage
Use get_data_into in render loops for zero-allocation retrieval. Use get_data for one-time retrieval when allocation cost is acceptable.
Code Reference
Source Location
- Repository: mujoco
- File: mjx/mujoco/mjx/_src/io.py
- Lines (get_data_into): 1727-1753
- Lines (get_data): 1756-1770
Signature
def get_data_into(
result: Union[mujoco.MjData, List[mujoco.MjData]],
m: mujoco.MjModel,
d: types.Data,
) -> None:
def get_data(
m: mujoco.MjModel,
d: types.Data,
) -> Union[mujoco.MjData, List[mujoco.MjData]]:
Import
import mujoco.mjx as mjx
I/O Contract
Inputs (get_data_into)
| Name | Type | Required | Description |
|---|---|---|---|
| result | MjData or List[MjData] | Yes | Pre-allocated destination |
| m | mujoco.MjModel | Yes | CPU model |
| d | types.Data | Yes | Device data to retrieve |
Inputs (get_data)
| Name | Type | Required | Description |
|---|---|---|---|
| m | mujoco.MjModel | Yes | CPU model |
| d | types.Data | Yes | Device data to retrieve |
Outputs
| Name | Type | Description |
|---|---|---|
| get_data_into | None | Modifies result in-place |
| get_data | MjData or List[MjData] | New MjData with CPU data |
Usage Examples
import mujoco
import mujoco.mjx as mjx
m = mujoco.MjModel.from_xml_path("humanoid.xml")
mx = mjx.put_model(m)
dx = mjx.make_data(mx)
# Run simulation on GPU
step_fn = jax.jit(mjx.step)
for _ in range(100):
dx = step_fn(mx, dx)
# Retrieve to CPU for visualization
d = mujoco.MjData(m)
mjx.get_data_into(d, m, dx)
# Or allocate new
d = mjx.get_data(m, dx)
# Now use d with MuJoCo renderer
print(f"Time: {d.time}, qpos: {d.qpos[:3]}")
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment