Table of Contents

Class MujocoUtils

Namespace
Gym.Environments.Envs.MuJoCo
Assembly
Gym.Environments.dll

Gymnasium's MuJoCo utilities (gymnasium.envs.mujoco.utils), mainly for tests: a MuJoCo env's whole state as one vector, restoring it, and the check that a seeded reset is deterministic. They reach the simulation through the env's unwrapped MujocoEnv, so any wrapper stack works.

[PyName("utils")]
public static class MujocoUtils
Inheritance
MujocoUtils
Inherited Members

Remarks

Methods

CheckMujocoResetState(IEnv, int, MjtState)

Asserts that a seeded reset restores the same state whatever ran before it (check_mujoco_reset_state): reset with seed, record the state, take one sampled step, reset with the same seed, and compare.

[PyName("check_mujoco_reset_state")]
public static void CheckMujocoResetState(IEnv env, int seed = 1234, MjtState stateType = MjtState.Integration)

Parameters

env IEnv

A MuJoCo env, wrapped or not; it is reset and stepped.

seed int

The reset and action-space seed.

stateType MjtState

The elements compared; Integration by default.

Exceptions

ArgumentNullException

env is null.

AttributeError

The unwrapped env is not a MuJoCo env.

AssertionError

The two states differ (reset is not deterministic).

GetState(IEnv, MjtState)

The env's state as one float64 vector (get_state): the elements stateType selects, in MuJoCo's order (MjGetState(MjModel, MjData, NDArray, MjtState)). A new array the caller owns.

[PyName("get_state")]
public static NDArray GetState(IEnv env, MjtState stateType = MjtState.FullPhysics)

Parameters

env IEnv

A MuJoCo env, wrapped or not.

stateType MjtState

The elements: FullPhysics (time, positions, velocities) by default, Integration for everything a step reads.

Returns

NDArray

The state vector.

Exceptions

ArgumentNullException

env is null.

AttributeError

The unwrapped env is not a MuJoCo env (it has no model).

SetState(IEnv, NDArray, MjtState)

Restores the env's state from a vector GetState(IEnv, MjtState) made (set_state); nothing is recomputed until the next step or forward pass, as in MuJoCo.

[PyName("set_state")]
public static NDArray SetState(IEnv env, NDArray state, MjtState stateType = MjtState.FullPhysics)

Parameters

env IEnv

A MuJoCo env, wrapped or not.

state NDArray

The state vector, of the same stateType.

stateType MjtState

The elements the vector holds.

Returns

NDArray

state itself, as Gymnasium returns it.

Exceptions

ArgumentNullException

A null env or state.

AttributeError

The unwrapped env is not a MuJoCo env.

TypeError

The vector is not float64 or not of the signature's size.

NotSupportedException

The vector holds nonzero applied forces, which the engine does not take.