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 Platform Model Holder

From Leeroopedia
Revision as of 12:46, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Google_deepmind_Mujoco_Platform_Model_Holder.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains Model Management, Resource Ownership
Last Updated 2026-02-15 04:00 GMT

Overview

Provides a RAII container that owns an mjModel, mjData, mjSpec, and mjVFS, with factory methods for loading models from specs, files, or memory buffers.

Description

model_holder.h declares the ModelHolder class which manages the lifecycle of MuJoCo model resources. It provides three static factory methods: FromSpec (takes ownership of an existing mjSpec), FromFile (parses a model file), and FromBuffer (decodes from a memory buffer with a content type). The class stores an mjVFS for virtual file system state, an mjSpec for the model specification, and the compiled mjModel and mjData pair. The ok() method checks for successful loading, and error() returns any load error message. The class is non-copyable.

Usage

Used by Studio's App class and other applications as the primary mechanism for loading and owning MuJoCo models. The holder ensures proper cleanup of all MuJoCo resources (spec deletion, model/data freeing) on destruction.

Code Reference

Source Location

Key Functions

class ModelHolder {
  static std::unique_ptr<ModelHolder> FromSpec(mjSpec* spec);
  static std::unique_ptr<ModelHolder> FromFile(std::string_view filepath);
  static std::unique_ptr<ModelHolder> FromBuffer(std::span<const std::byte> buffer, std::string_view content_type, std::string_view filename);
  mjVFS* vfs();  mjSpec* spec();  mjData* data();  mjModel* model();
  bool ok() const;
  std::string_view error() const;
};

Import

#include "experimental/platform/model_holder.h"

I/O Contract

Inputs

Name Type Required Description
spec mjSpec* No Existing spec (FromSpec takes ownership)
filepath std::string_view No Path to .xml, .mjb, or .mjz file (FromFile)
buffer std::span<const std::byte> No In-memory model data (FromBuffer)
content_type std::string_view No MIME type of buffer contents (FromBuffer)

Outputs

Name Type Description
ModelHolder std::unique_ptr<ModelHolder> Owned container with mjModel, mjData, mjSpec, mjVFS
error std::string_view Error message if loading failed

Related Pages

Page Connections

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