Table of Contents

Class SwimmerEnvV5

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

Swimmer-v5: a three-link swimmer in a viscous fluid, driven by 2 joint torques in [-1, 1]. The reward pays the forward velocity and charges the squared torques; the episode never ends on its own (make's 1000-step limit truncates it). Byte for byte what Gymnasium's Swimmer-v5 computes on MuJoCo 4.0.0 (DR-61, DR-64).

[PyName("SwimmerEnv")]
public class SwimmerEnvV5 : MujocoEnv, IEnv, IDisposable, IDynamicAttributes
Inheritance
SwimmerEnvV5
Implements
Inherited Members
Extension Methods

Remarks

Observation (float64): the positions without the root's x and y (unless asked for), then the velocities, 8 values by default. Reward: forward_reward_weight * x_velocity - ctrl_cost_weight * sum(action**2). Info: x_position, y_position, distance_from_origin, x_velocity, y_velocity, reward_forward, reward_ctrl; the reset's info holds the first three. Its default camera configuration is none (MuJoCo's free camera as the model sets it).

Not thread-safe. Reference: gymnasium/envs/mujoco/swimmer_v5.py.

Its info reads typed (DR-91): SwimmerInfoV5 info = step.Info; (SwimmerInfoV5), with the dict's own values still behind the indexer.

Constructors

SwimmerEnvV5(SwimmerEnvV5Options)

Builds the instance from its options record: the properties set, the constructor's defaults for the rest.

public SwimmerEnvV5(SwimmerEnvV5Options options)

Parameters

options SwimmerEnvV5Options

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

SwimmerEnvV5(RenderMode, string, int, IReadOnlyDictionary<string, object?>?, double, double, double, bool, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?)

Builds the env with the render mode given as the RenderMode enum (DR-84, DR-93), as SwimmerEnvV5(string, int, IReadOnlyDictionary<string, object?>?, double, double, double, bool, string?, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?) builds it from the mode's string: new SwimmerEnvV5(RenderMode.RgbArray) builds what new SwimmerEnvV5(renderMode: "rgb_array") builds, the member reaching the env as Gymnasium's string (Name(RenderMode)), which its RenderMode property then holds.

public SwimmerEnvV5(RenderMode renderMode, string xmlFile = "swimmer.xml", int frameSkip = 4, IReadOnlyDictionary<string, object?>? defaultCameraConfig = null, double forwardRewardWeight = 1, double ctrlCostWeight = 0.0001, double resetNoiseScale = 0.1, bool excludeCurrentPositionsFromObservation = true, int width = 480, int height = 480, int? cameraId = null, string? cameraName = null, int maxGeom = 1000, IReadOnlyDictionary<int, bool>? visualOptions = null, EnvViewerFactory? viewerFactory = null)

Parameters

renderMode RenderMode

The render mode, which the env must list in its metadata["render_modes"] as for the string; it behaves exactly as its Gymnasium string does in the other constructor.

xmlFile string

The model: a bundled file name (xml_file, DR-63).

frameSkip int

Physics steps per env step (frame_skip).

defaultCameraConfig IReadOnlyDictionary<string, object>

The free camera's settings (default_camera_config); none by default.

forwardRewardWeight double

The weight of the forward velocity (forward_reward_weight).

ctrlCostWeight double

The weight of the squared torques (ctrl_cost_weight).

resetNoiseScale double

The scale of the reset's noise (reset_noise_scale).

excludeCurrentPositionsFromObservation bool

Whether the root's x and y leave the observation (exclude_current_positions_from_observation).

width int

The rendered frame's width (width).

height int

The rendered frame's height (height).

cameraId int?

The camera to render from (camera_id).

cameraName string

The camera to render from by name (camera_name).

maxGeom int

The most geoms a frame draws (max_geom).

visualOptions IReadOnlyDictionary<int, bool>

MuJoCo visual flags to switch (visual_options).

viewerFactory EnvViewerFactory

Gym.NET's viewer_factory (DR-20) for human mode.

Remarks

The mode is required and comes first, so new SwimmerEnvV5() keeps meaning the other constructor, without a mode; leave the mode out there for no rendering. Every other parameter means what it means there.

Exceptions

ArgumentOutOfRangeException

Thrown for a value RenderMode does not declare (a cast integer such as (RenderMode)99).

NotSupportedException

xmlFile is not a bundled model.

OverflowError

A frame skip of 0 (Python's OverflowError deriving the frame rate).

ValueError

Both a camera id and a camera name.

SwimmerEnvV5(string, int, IReadOnlyDictionary<string, object?>?, double, double, double, bool, string?, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?)

Creates the env (Gymnasium's SwimmerEnv.init): the model, its spaces and the frame rate the time step gives.

public SwimmerEnvV5(string xmlFile = "swimmer.xml", int frameSkip = 4, IReadOnlyDictionary<string, object?>? defaultCameraConfig = null, double forwardRewardWeight = 1, double ctrlCostWeight = 0.0001, double resetNoiseScale = 0.1, bool excludeCurrentPositionsFromObservation = true, string? renderMode = null, int width = 480, int height = 480, int? cameraId = null, string? cameraName = null, int maxGeom = 1000, IReadOnlyDictionary<int, bool>? visualOptions = null, EnvViewerFactory? viewerFactory = null)

Parameters

xmlFile string

The model: a bundled file name (xml_file, DR-63).

frameSkip int

Physics steps per env step (frame_skip).

defaultCameraConfig IReadOnlyDictionary<string, object>

The free camera's settings (default_camera_config); none by default.

forwardRewardWeight double

The weight of the forward velocity (forward_reward_weight).

ctrlCostWeight double

The weight of the squared torques (ctrl_cost_weight).

resetNoiseScale double

The scale of the reset's noise (reset_noise_scale).

excludeCurrentPositionsFromObservation bool

Whether the root's x and y leave the observation (exclude_current_positions_from_observation).

renderMode string

Gymnasium's render_mode: human, rgb_array, depth_array, rgbd_tuple or null.

width int

The rendered frame's width (width).

height int

The rendered frame's height (height).

cameraId int?

The camera to render from (camera_id).

cameraName string

The camera to render from by name (camera_name).

maxGeom int

The most geoms a frame draws (max_geom).

visualOptions IReadOnlyDictionary<int, bool>

MuJoCo visual flags to switch (visual_options).

viewerFactory EnvViewerFactory

Gym.NET's viewer_factory (DR-20) for human mode.

Exceptions

NotSupportedException

xmlFile is not a bundled model.

OverflowError

A frame skip of 0 (Python's OverflowError deriving the frame rate).

ValueError

Both a camera id and a camera name.

Properties

ClassMetadata

Gymnasium's class attribute metadata: the four render modes, the frame rate set per instance. A new dict on every read.

public static Metadata ClassMetadata { get; }

Property Value

Metadata

CtrlCostWeight

The weight of the squared torques (_ctrl_cost_weight), read every step.

[PyName("_ctrl_cost_weight")]
public double CtrlCostWeight { get; set; }

Property Value

double

ExcludeCurrentPositionsFromObservation

Whether the root's x and y leave the observation (_exclude_current_positions_from_observation). Footgun: changing it after construction changes the observation's length but not the observation space, as in Gymnasium.

[PyName("_exclude_current_positions_from_observation")]
public bool ExcludeCurrentPositionsFromObservation { get; set; }

Property Value

bool

ForwardRewardWeight

The weight of the forward velocity (_forward_reward_weight), read every step.

[PyName("_forward_reward_weight")]
public double ForwardRewardWeight { get; set; }

Property Value

double

ObservationStructure

How the observation is laid out (observation_structure): skipped_qpos, qpos and qvel counts.

public Info ObservationStructure { get; }

Property Value

Info

ResetNoiseScale

The scale of the reset's noise (_reset_noise_scale), read every reset.

[PyName("_reset_noise_scale")]
public double ResetNoiseScale { get; set; }

Property Value

double

Methods

ControlCost(NDArray)

The control cost of action (control_cost): ctrl_cost_weight * sum(action**2), computed in the action's dtype and returned widened exactly.

[PyName("control_cost")]
public double ControlCost(NDArray action)

Parameters

action NDArray

The action.

Returns

double

The cost.

Exceptions

ArgumentNullException

action is null.

NotSupportedException

An action of a dtype whose cost NumPy keeps in that dtype (float16, complex).

GetResetInfo()

The reset's info (_get_reset_info): x_position, y_position and distance_from_origin, np.float64s.

protected override Info GetResetInfo()

Returns

Info

The info.

ResetModel()

The episode's start (reset_model): positions init_qpos + uniform(-scale, scale, nq), then velocities init_qvel + uniform(-scale, scale, nv), drawn in that order.

protected override NDArray ResetModel()

Returns

NDArray

The first observation.

Step(NDArray)

Applies action for FrameSkip physics steps and reports the transition (step).

public override StepResult<NDArray> Step(NDArray action)

Parameters

action NDArray

The 2 torques, float32 (the action space's samples) or any real dtype.

Returns

StepResult<NDArray>

The observation, the float64 reward, terminated=False, truncated=False and the info.

Exceptions

ArgumentNullException

action is null.

ValueError

The action is not of shape (2,), with Gymnasium's message.

NotSupportedException

An action of a dtype whose cost NumPy keeps in that dtype (float16, complex).