Table of Contents

Class InvertedPendulumEnvV4

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

InvertedPendulum-v4: the cart and pole of InvertedPendulumEnvV5 with v4's fixed model, frame skip and noise, a reward of 1.0 on every step (the step the pole falls included) and an empty info. Byte for byte what Gymnasium's InvertedPendulum-v4 computes on MuJoCo 4.0.0 (DR-61, DR-64).

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

Remarks

Observation (float64): the cart's position, the pole's angle, then their velocities. A non-finite state or an angle beyond 0.2 rad ends the episode. make warns that the id is out of date.

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

Its info is always {}, as Gymnasium's, so it has no typed info record (DR-95).

Constructors

InvertedPendulumEnvV4(InvertedPendulumEnvV4Options)

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

public InvertedPendulumEnvV4(InvertedPendulumEnvV4Options options)

Parameters

options InvertedPendulumEnvV4Options

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

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

public InvertedPendulumEnvV4(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 InvertedPendulumEnvV4() 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.

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

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

public InvertedPendulumEnvV4(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 25 frames per second. A new dict on every read.

public static Metadata ClassMetadata { get; }

Property Value

Metadata

Methods

ResetModel()

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

protected override NDArray ResetModel()

Returns

NDArray

The first observation.

Step(NDArray)

Applies action (Gymnasium's a) for 2 physics steps and reports the transition (step).

public override StepResult<NDArray> Step(NDArray action)

Parameters

action NDArray

The force on the cart, shape (1,), any real dtype (stored as float64).

Returns

StepResult<NDArray>

The observation, the reward 1.0, whether the pole fell, truncated=False and an empty info.

Exceptions

ArgumentNullException

action is null.

ValueError

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