Table of Contents

Class MjModel

Namespace
Gym.MuJoCo
Assembly
Gym.Environments.dll

A compiled MuJoCo model, what mujoco.MjModel is to Gymnasium's MuJoCo envs: one of Gymnasium's 14 bundled models as MuJoCo 4.0.0 compiled it, embedded in Gym.Environments (DR-63), so every number is MuJoCo's own and Gym.NET needs no MJCF compiler. It holds what the eleven envs need (HalfCheetah, Hopper, Walker2d, Ant, Humanoid, HumanoidStandup, InvertedPendulum, InvertedDoublePendulum, Reacher, Swimmer, Pusher) and Gymnasium's custom-env test model, point.xml: kinematic trees of hinge and slide joints, each under an optional free root; a ground plane with spheres, capsules, cylinders and point.xml's box (tested against the plane, refused if it would touch); motors on joints; Euler or RK4; pyramidal and frictionless contacts; the dense Newton or PGS solver; inert fixed tendons; sites; and the inertia-box fluid model.

public sealed class MjModel : IDisposable
Inheritance
MjModel
Implements
Inherited Members
Extension Methods

Remarks

Its public members are what Gymnasium's envs, utils and tests read of mujoco.MjModel, under .NET names, each [PyName]d to Python's (DR-68); the internal fields keep MuJoCo's names and layouts (row-major, 3*i, 4*i, 9*i strides), which MjData's engine reads.

Load(byte[]) refuses any model that uses a feature the engine does not reproduce (ball joints, springs on free joints, active tendons, equality constraints, frictionloss, colliding geoms of other types, elliptic cones, the ellipsoid fluid model, stateful actuators, PGS over several kinematic trees, other integrators or solvers), so a model that loads is one the engine steps exactly, as MuJoCo 4.0.0 does on win-x64 (DR-64). The bundled models use none of them.

Properties

ActuatorCtrlrange

The actuators' control ranges (actuator_ctrlrange), shape (nu, 2), float64: the bounds of an env's action space after their cast to float32. A writable view of the model's own array: the caller owns the view (dispose it), and writes reach the model, as in Python.

[PyName("actuator_ctrlrange")]
public NDArray ActuatorCtrlrange { get; }

Property Value

NDArray

BodyMass

The bodies' masses (body_mass), shape (nbody,), float64, as Humanoid's mass_center weighs them. A writable view: writing a mass changes what the env computes from it, but not the derived quantities MuJoCo's compiler set (subtree masses, inertias), exactly as writing it in Python does without mj_setConst.

[PyName("body_mass")]
public NDArray BodyMass { get; }

Property Value

NDArray

GeomRgba

The geoms' colours (geom_rgba), shape (ngeom, 4), float32 as in MuJoCo, red, green, blue and alpha in [0, 1]. A writable view; Gymnasium's renderer fades the geoms by writing their alpha.

[PyName("geom_rgba")]
public NDArray GeomRgba { get; }

Property Value

NDArray

Na

Number of activation states (na): 0 for every bundled model, which has no stateful actuator.

[PyName("na")]
public int Na { get; }

Property Value

int

Nbody

Number of bodies (nbody), the world body included.

[PyName("nbody")]
public int Nbody { get; }

Property Value

int

Nbvh

Number of nodes of the collision midphase's bounding-volume hierarchies (nbvh), as MuJoCo compiled them; Gymnasium's tests use it to tell the xml_file variants apart. The engine itself does not read it.

[PyName("nbvh")]
public int Nbvh { get; }

Property Value

int

Ncam

Number of cameras (ncam) the model defines (Humanoid's two, Ant's one, none elsewhere).

[PyName("ncam")]
public int Ncam { get; }

Property Value

int

Ngeom

Number of geoms (ngeom).

[PyName("ngeom")]
public int Ngeom { get; }

Property Value

int

Njnt

Number of joints (njnt).

[PyName("njnt")]
public int Njnt { get; }

Property Value

int

Nq

Number of position coordinates (nq): a free joint has 7 for its 6 degrees of freedom.

[PyName("nq")]
public int Nq { get; }

Property Value

int

Ntendon

Number of tendons (ntendon): Humanoid's and HumanoidStandup's two fixed tendons, 0 elsewhere.

[PyName("ntendon")]
public int Ntendon { get; }

Property Value

int

Nu

Number of actuators (nu), the length of Ctrl and of an env's action.

[PyName("nu")]
public int Nu { get; }

Property Value

int

Nv

Number of degrees of freedom (nv), the length of Qvel.

[PyName("nv")]
public int Nv { get; }

Property Value

int

Opt

The physics options (opt): the time step Gymnasium reads.

[PyName("opt")]
public MjOption Opt { get; }

Property Value

MjOption

Stat

The model statistics (stat): the extent the free camera's distance starts from.

[PyName("stat")]
public MjStatistic Stat { get; }

Property Value

MjStatistic

Vis

The visualization options (vis): the offscreen buffer's size Gymnasium's envs grow.

[PyName("vis")]
public MjVisual Vis { get; }

Property Value

MjVisual

Methods

Dispose()

Releases the views' roots, which pin the model's arrays; views the caller still holds keep working until disposed. The model's own numbers stay usable by the engine; only the public views end.

public void Dispose()

FromXmlPath(string)

Loads one of Gymnasium's bundled models by its file name (mujoco.MjModel.from_xml_path as Gymnasium's MujocoEnv calls it): "ant.xml", "walker2d_v5.xml" and the other twelve, each compiled once by MuJoCo 4.0.0 and embedded (DR-63). Every call returns a new model with its own arrays, as Python's does, so writing one model's colours or options never reaches another env's.

[PyName("from_xml_path")]
public static MjModel FromXmlPath(string filename)

Parameters

filename string

A bundled file name, with no folder ("hopper.xml").

Returns

MjModel

The model.

Remarks

Footgun: the XML files themselves are not in the package, only their compiled form, so a path to a copy of Gymnasium's own ant.xml is refused like any other path; pass the bare name.

Exceptions

ArgumentNullException

filename is null.

NotSupportedException

Any other name or path: Gym.NET has no MJCF compiler, so a custom model cannot be loaded; the message lists the names it has. Gymnasium would compile the file (or raise OSError for a missing one).