Class Mujoco
The mujoco module's functions that Gymnasium's MuJoCo envs, its utils and its tests call (DR-68),
under .NET names, each [PyName]d to Python's: stepping, the forward dynamics, resetting, the post-step
forces, kinematics alone, name lookup and the state vector. Each runs Gym.NET's own engine, bit for bit with
MuJoCo 4.0.0 on win-x64 for Gymnasium's bundled models (DR-61, DR-64).
[PyName("mujoco")]
public static class Mujoco
- Inheritance
-
Mujoco
- Inherited Members
Remarks
Every function takes the model and the data as MuJoCo's do, and refuses a data made for another model (ArgumentException), where MuJoCo's C would read past its arrays.
Methods
MjForward(MjModel, MjData)
The forward dynamics at the current state, without integrating (mj_forward): positions, velocities,
forces, the unconstrained and the constrained accelerations. Gymnasium's set_state calls it after
writing the positions and velocities.
[PyName("mj_forward")]
public static void MjForward(MjModel model, MjData data)
Parameters
Exceptions
- ArgumentNullException
A null model or data.
- ArgumentException
The data was made for another model.
- NotSupportedException
The engine met a path it does not reproduce (the message names it).
MjGetState(MjModel, MjData, NDArray, MjtState)
Copies the state elements a signature selects into state (mj_getState), in MuJoCo's
element order: time, positions, velocities, activations, history, warm start, controls, applied forces, the
rest (empty for the bundled models).
[PyName("mj_getState")]
public static void MjGetState(MjModel model, MjData data, NDArray state, MjtState spec)
Parameters
modelMjModelThe model.
dataMjDataThe data, made for
model.stateNDArrayA float64 array of MjStateSize(MjModel, MjtState) values, written in place.
specMjtStateThe signature.
Exceptions
- ArgumentNullException
A null argument.
- ArgumentException
The data was made for another model.
- TypeError
The array is not float64, or not of the signature's size (MuJoCo's message).
- ArgumentOutOfRangeException
A signature below 0 or from 2^15 on.
MjKinematics(MjModel, MjData)
The frames alone from the positions (mj_kinematics): bodies, centers of mass, joints, geoms and sites,
without the dynamics. Gymnasium's tests call it to read positions without stepping.
[PyName("mj_kinematics")]
public static void MjKinematics(MjModel model, MjData data)
Parameters
Exceptions
- ArgumentNullException
A null model or data.
- ArgumentException
The data was made for another model.
MjName2Id(MjModel, MjtObj, string)
The index of a named element (mj_name2id): a body (also as XBody), joint, geom,
site, camera, light, actuator, tendon, material or texture of the model.
[PyName("mj_name2id")]
public static int MjName2Id(MjModel model, MjtObj type, string name)
Parameters
modelMjModelThe model.
typeMjtObjThe element kind.
namestringThe name; an empty name matches nothing.
Returns
- int
The index, or -1 when no element of that kind has the name (or the model has no such kind).
Exceptions
- ArgumentNullException
A null model or name.
MjResetData(MjModel, MjData)
Resets the data to the model's defaults (mj_resetData): every array cleared, the positions at the
reference configuration, at rest, time 0. Nothing is computed from that state until the next
MjForward(MjModel, MjData) or MjStep(MjModel, MjData, int).
[PyName("mj_resetData")]
public static void MjResetData(MjModel model, MjData data)
Parameters
Exceptions
- ArgumentNullException
A null model or data.
- ArgumentException
The data was made for another model.
MjRnePostConstraint(MjModel, MjData)
The forces the forward dynamics leaves out (mj_rnePostConstraint): the bodies' external contact forces
(CfrcExt) from the last solve. Gymnasium's envs call it after each step's physics.
[PyName("mj_rnePostConstraint")]
public static void MjRnePostConstraint(MjModel model, MjData data)
Parameters
Exceptions
- ArgumentNullException
A null model or data.
- ArgumentException
The data was made for another model.
MjSetState(MjModel, MjData, NDArray, MjtState)
Writes the state elements a signature selects from state (mj_setState), in
MjGetState(MjModel, MjData, NDArray, MjtState)'s order. Nothing is recomputed until the next MjForward(MjModel, MjData) or step.
[PyName("mj_setState")]
public static void MjSetState(MjModel model, MjData data, NDArray state, MjtState spec)
Parameters
modelMjModelThe model.
dataMjDataThe data, made for
model.stateNDArrayThe float64 values, MjStateSize(MjModel, MjtState) of them.
specMjtStateThe signature.
Exceptions
- ArgumentNullException
A null argument.
- ArgumentException
The data was made for another model.
- TypeError
The array is not float64, or not of the signature's size (MuJoCo's message).
- ArgumentOutOfRangeException
A signature below 0 or from 2^15 on.
- NotSupportedException
A nonzero applied force (QfrcApplied, XfrcApplied): the engine steps without applied forces, so it refuses them rather than ignore them.
MjStateSize(MjModel, MjtState)
The length of the state vector a signature selects (mj_stateSize), its elements' sizes summed.
[PyName("mj_stateSize")]
public static int MjStateSize(MjModel model, MjtState spec)
Parameters
modelMjModelThe model.
specMjtStateThe signature: one element or a union (FullPhysics, Integration).
Returns
- int
The number of values.
Exceptions
- ArgumentNullException
A null model.
- ArgumentOutOfRangeException
A signature below 0 or from 2^15 on, with MuJoCo's message.
MjStep(MjModel, MjData, int)
Advances the simulation nstep time steps (mj_step): each the forward dynamics at the
current state, then the model's integrator, which updates the positions, velocities and time.
[PyName("mj_step")]
public static void MjStep(MjModel model, MjData data, int nstep = 1)
Parameters
modelMjModelThe model.
dataMjDataThe data, made for
model.nstepintThe number of steps (Gymnasium passes its frame skip); MuJoCo's Python default is 1, and 0 or a negative count steps nothing, as there.
Remarks
A NaN or a value beyond 1e10 in the positions, velocities or accelerations resets the data first, as MuJoCo does (its warning is not recorded). Footgun: the external contact forces (CfrcExt) are not updated by a step; call MjRnePostConstraint(MjModel, MjData) after it, as Gymnasium's envs do.
Exceptions
- ArgumentNullException
A null model or data.
- ArgumentException
The data was made for another model.
- NotSupportedException
The engine met a path it does not reproduce (the message names it).