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 saveModel

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

Overview

Concrete tool for saving a compiled MuJoCo model to binary MJB format provided by the MuJoCo C API.

Description

The mj_saveModel function serializes a compiled mjModel to either a binary file or a memory buffer. It writes a standard header with version checks, then all size fields, options, visual settings, statistics, and all data arrays using X-macro iteration.

Usage

Call after successful model compilation to save the binary for fast future loading.

Code Reference

Source Location

  • Repository: mujoco
  • File: src/engine/engine_io.c
  • Lines: 481-533

Signature

void mj_saveModel(const mjModel* m, const char* filename,
                  void* buffer, int buffer_sz);

Import

#include <mujoco/mujoco.h>

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Compiled model to save
filename const char* No Output MJB file path (NULL if using buffer)
buffer void* No Memory buffer alternative (NULL if using file)
buffer_sz int No Buffer size in bytes

Outputs

Name Type Description
file/buffer binary MJB binary data with header and all model arrays

Usage Examples

#include <mujoco/mujoco.h>

// Load from XML, save as binary
mjModel* m = mj_loadXML("humanoid.xml", NULL, error, 1000);
if (m) {
    mj_saveModel(m, "humanoid.mjb", NULL, 0);
    mj_deleteModel(m);
}

Related Pages

Implements Principle

Page Connections

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