Table of Contents

Class ReacherEnvV4

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

Reacher-v4: the two-joint arm of ReacherEnvV5 with v4's fixed model and frame skip, a reward measured before the step (the distance and the action's cost as they stand when the action arrives), unweighted, and the fingertip's full 3D offset in the observation. Byte for byte what Gymnasium's Reacher-v4 computes on MuJoCo 4.0.0 (DR-61, DR-64).

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

Remarks

Observation (float64, 11 values): the cosines and sines of the arm angles, the target's coordinates, the arm's angular velocities and the fingertip's offset from the target in x, y and z. Reward: -|fingertip - target| - sum(action**2) before the physics runs, the control term in the action's own dtype (an integer action's an np.int64, as there). Info: reward_dist, reward_ctrl; the reset's info is empty; make warns that the id is out of date.

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

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

Constructors

ReacherEnvV4(ReacherEnvV4Options)

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

public ReacherEnvV4(ReacherEnvV4Options options)

Parameters

options ReacherEnvV4Options

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

ReacherEnvV4(RenderMode, 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 ReacherEnvV4(string?, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?) builds it from the mode's string: new ReacherEnvV4(RenderMode.RgbArray) builds what new ReacherEnvV4(renderMode: "rgb_array") builds, the member reaching the env as Gymnasium's string (Name(RenderMode)), which its RenderMode property then holds.

public ReacherEnvV4(RenderMode renderMode, 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.

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 ReacherEnvV4() 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).

ValueError

Both a camera id and a camera name.

ReacherEnvV4(string?, int, int, int?, string?, int, IReadOnlyDictionary<int, bool>?, EnvViewerFactory?)

Creates the env (Gymnasium's ReacherEnv.init): reacher.xml with a frame skip of 2.

public ReacherEnvV4(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

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

ValueError

Both a camera id and a camera name.

Properties

ClassMetadata

Gymnasium's class attribute metadata: the four render modes at 50 frames per second. A new dict on every read.

public static Metadata ClassMetadata { get; }

Property Value

Metadata

Goal

The target the last reset drew (goal), float64 (2,), or null before the first reset. Owned by the env, replaced by each reset: do not dispose it.

[NDBorrowed]
public NDArray? Goal { get; }

Property Value

NDArray

Methods

Dispose(bool)

Closes, then releases the last target array and everything MujocoEnv holds.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose().

ResetModel()

The episode's start (reset_model): positions uniform(-0.1, 0.1, nq) + init_qpos; the target drawn as uniform(-0.2, 0.2, 2) until its norm is below 0.2, into the last two positions; velocities init_qvel + uniform(-0.005, 0.005, nv) with the target's zeroed.

protected override NDArray ResetModel()

Returns

NDArray

The first observation.

Step(NDArray)

Prices action in the current state, then applies it for 2 physics steps and reports the transition (step; Gymnasium's a).

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).

KeyError

The model lacks the body fingertip or target (MuJoCo's message).