Table of Contents

Namespace Gym.Envs

Classes

ActionWrapper<TObs, TWAct, TAct>

Transforms every action through Action(TWAct) before the env sees it. If the wrapper takes actions from another space, assign it to ActionSpace in the constructor.

EnvInfo

The base of the typed info records (DR-91, DR-94, DR-95): a built-in env's info read as a record with a .NET-typed property per key, HalfCheetahInfoV5 info = step.Info; then info.XPosition, while the dict's own values stay readable through the indexer, (double)(NDArray)info["x_position"], as on step.Info.

Env<TObs, TAct>

The base class of every environment: an MDP driven through Step(TAct) and Reset(BigInteger?, IReadOnlyDictionary<string, object?>?), with spaces, metadata, a render mode, a lazily created generator and the attribute protocol (GetWrapperAttr(string), ...).

Info

The info dict of resets and steps (and the base of Metadata): a string → object map that behaves like a Python dict. Iteration follows insertion order and re-assigning a key keeps its place. Keys keep Gymnasium's spelling byte for byte ("TimeLimit.truncated", "episode"). Typed reads go through Get<T>(IReadOnlyDictionary<string, object?>, string) (info.Get<double>("x_position")), and the built-in envs' infos convert to typed records (EnvInfo, DR-91).

InfoExtensions

Typed reads of an info dict (DR-78): info.Get<double>("x_position") reads a value as the .NET type the caller wants, converting what Gymnasium's envs store (NumPy scalars, which arrive as 0-d arrays, and Python numbers) where a plain cast would throw.

Metadata

An env's metadata dict: an Info with the keys Gym reads spelled as they are in Python ("render_modes", "render_fps"), plus typed accessors for them. Iteration order, equality and repr are a dict's, so {'render_modes': ['human', 'rgb_array'], 'render_fps': 50} prints and compares as in Python.

ObservationWrapper<TWObs, TObs, TAct>

Transforms every observation Reset(BigInteger?, IReadOnlyDictionary<string, object?>?) and Step(TAct) return through Observation(TObs). If the transformation changes the observation space, assign the new one to ObservationSpace in the constructor.

RenderModes

The render modes as constants, so render_mode values are discoverable and checked by the compiler instead of typed as strings: Gymnasium.Make("CartPole-v1", new { render_mode = RenderModes.RgbArray }). Each constant is Gymnasium's own string, so a constant and the literal are interchangeable everywhere (a spec, metadata, RenderMode). Name(RenderMode), Parse(string?) and TryParse(string?) convert between these strings and the RenderMode enum (DR-84, DR-93).

RenderResult

What render() returns, Gymnasium's RenderFrame | list[RenderFrame] | None as a closed union: nothing (None, human mode and envs without a render mode), one RGB frame (RenderResult.Rgb, rgb_array), one depth frame (RenderResult.Depth, depth_array), an RGB-D pair (RenderResult.RgbDepth, rgbd_tuple), text (RenderResult.Ansi, ansi), or the frames collected since the last call (RenderResult.Frames, the *_list modes). Switch on the case: if (env.Render() is RenderResult.Rgb rgb).

RenderResult.Ansi

An ansi frame: text, possibly with newlines and ANSI escape sequences (toy_text).

RenderResult.Depth

A depth_array frame: a (height, width) float array of depths (MuJoCo).

RenderResult.Frames

The frames collected since the previous call, what the *_list render modes return (Gymnasium's RenderCollection): a Python list of frames, each itself a RenderResult case.

RenderResult.NoneResult

Python's None: nothing was rendered for the caller (human mode draws to a window instead).

RenderResult.Rgb

An rgb_array frame: a (height, width, 3) uint8 array, rows top to bottom, as Gymnasium returns it after np.transpose(..., axes=(1, 0, 2)).

RenderResult.RgbDepth

An rgbd_tuple frame: the RGB frame and the depth frame of the same view (MuJoCo), Python's (rgb, depth).

RewardWrapper<TObs, TAct>

Transforms every reward Step(TAct) returns through Reward(double).

Wrapper<TObs, TAct>

A wrapper that keeps its env's observation and action types (Wrapper[ObsType, ActType, ObsType, ActType]), the base of wrappers such as TimeLimit and OrderEnforcing.

Wrapper<TWObs, TWAct, TObs, TAct>

Wraps an env to change parts of its behaviour while forwarding the rest. Every member forwards to Env unless the wrapper overrides it; spaces and metadata can be replaced on the wrapper alone, without touching the env beneath.

Structs

KeyCombination

Keys pressed together, as key codes: the key of a keyboard mapping (GetKeysToAction()), Python's tuple of ints such as MountainCar's (275, 276). A code is an SDL keycode, which for a printable key is Python's ord of its character (97 for a), so a mapping written with characters ({"wa": 1}, which play also accepts) becomes FromText(string)'s codes.

Interfaces

IEnv

The env contract over object: what code that holds envs of any observation and action type (wrappers over unknown envs, the registry, vector envs, the legacy adapter) programs against. Every env is an Env<TObs, TAct>, which implements it; its typed members are the ones to call when the types are known.

IWrapper

A wrapper of any observation and action types, Python's isinstance(env, gymnasium.Wrapper): lets code walk a stack of wrappers (Env down to Unwrapped) without knowing each layer's types.

Enums

RenderMode

The render modes Gymnasium's envs know, as an enum (DR-84, DR-93): what the env constructors, Make and MakeVec take beside Gymnasium's string, new CartPoleEnv(RenderMode.RgbArray) being new CartPoleEnv(renderMode: "rgb_array"). Each member stands for its Gymnasium string (Name(RenderMode)), and Parse(string?) and TryParse(string?) read a string back.