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 Engine IO Header

From Leeroopedia
Knowledge Sources
Domains Physics Simulation, Model I/O, Memory Management
Last Updated 2026-02-15 04:00 GMT

Overview

Header file declaring the model and data I/O interface for MuJoCo, including allocation, copying, saving, loading, and deallocation of mjModel and mjData structures.

Description

This header declares the comprehensive I/O and memory management API for MuJoCo's two primary data structures. For mjModel, it provides mj_makeModel (allocation with detailed size parameters for all model arrays), mj_copyModel and mjv_copyModel (full and visualization-only copies), mj_saveModel and mj_loadModelBuffer (binary serialization), mj_deleteModel (deallocation), mj_sizeModel (buffer size computation), and mj_validateReferences (reference integrity checking). For mjData, it provides mj_makeData (allocation and initialization), mj_copyData and mjv_copyData (full and visualization-only copies), mj_resetData and mj_resetDataKeyframe (state reset), mj_initPlugin (plugin initialization), and mj_deleteData (deallocation). It also declares sparse matrix construction functions (mj_makeDofDofSparse, mj_makeBSparse, mj_makeDofDofMaps) and default option setters. The mjLOAD_MULTIPLE constant (value 2) controls the hash map load factor for name lookups.

Usage

Included by any code that needs to create, copy, save, load, reset, or destroy MuJoCo model and data objects.

Code Reference

Source Location

Key Functions

// Initialization defaults
MJAPI void mj_defaultLROpt(mjLROpt* opt);
MJAPI void mj_defaultOption(mjOption* opt);
MJAPI void mj_defaultVisual(mjVisual* vis);

// mjModel management
MJAPI mjModel* mj_copyModel(mjModel* dest, const mjModel* src);
MJAPI void mj_saveModel(const mjModel* m, const char* filename, void* buffer, int buffer_sz);
MJAPI mjModel* mj_loadModelBuffer(const void* buffer, int buffer_sz);
MJAPI void mj_deleteModel(mjModel* m);
MJAPI mjtSize mj_sizeModel(const mjModel* m);
MJAPI const char* mj_validateReferences(const mjModel* m);

// mjData management
MJAPI mjData* mj_makeData(const mjModel* m);
MJAPI mjData* mj_copyData(mjData* dest, const mjModel* m, const mjData* src);
MJAPI void mj_resetData(const mjModel* m, mjData* d);
MJAPI void mj_resetDataKeyframe(const mjModel* m, mjData* d, int key);
MJAPI void mj_deleteData(mjData* d);

// Sparse matrix construction
MJAPI void mj_makeDofDofSparse(int nv, int nC, int nD, int nM, ...);
MJAPI void mj_makeBSparse(int nv, int nbody, int nB, ...);

Import

#include "engine/engine_io.h"

I/O Contract

Inputs

Name Type Required Description
m const mjModel* Yes Source model for data creation, copying, or saving
src const mjData* Yes Source data for copying
filename const char* No File path for saving model
buffer const void* No Binary buffer for loading model
key int No Keyframe index for resetting data

Outputs

Name Type Description
return value mjModel* or mjData* Newly allocated or copied model/data structure
dest mjModel* or mjData* Destination for copy operations (allocated if NULL)

Related Pages

Page Connections

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