Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Google deepmind Mujoco mj loadModel

From Leeroopedia
Knowledge Sources
Domains Physics_Simulation, Model_IO, Serialization
Last Updated 2026-02-15 06:00 GMT

Overview

Concrete tool for loading a pre-compiled MuJoCo model from a binary MJB file provided by the MuJoCo C API.

Description

The mj_loadModel function loads a MuJoCo model from a binary MJB file that was previously saved with mj_saveModel. It reads the file via the resource system, validates the binary header (version, precision, struct sizes), and reconstructs the mjModel in memory. An optional VFS allows loading from memory buffers.

Usage

Use this function when loading a pre-compiled binary model file (.mjb). This is faster than mj_loadXML since it skips parsing and compilation.

Code Reference

Source Location

  • Repository: mujoco
  • File: src/xml/xml_api.cc
  • Lines: 136-155

Signature

mjModel* mj_loadModel(const char* filename, const mjVFS* vfs);

Import

#include <mujoco/mujoco.h>

I/O Contract

Inputs

Name Type Required Description
filename const char* Yes Path to binary MJB model file
vfs const mjVFS* No Virtual file system (NULL for disk)

Outputs

Name Type Description
return mjModel* Loaded model from binary (NULL on failure)

Usage Examples

#include <mujoco/mujoco.h>

// Load pre-compiled binary model
mjModel* m = mj_loadModel("humanoid.mjb", NULL);
if (!m) {
    printf("Failed to load binary model\n");
    return 1;
}

// Use the model...
mj_deleteModel(m);

Related Pages

Implements Principle

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment