Table of Contents

Class RenderModes

Namespace
Gym.Envs
Assembly
Gym.dll

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

public static class RenderModes
Inheritance
RenderModes
Inherited Members

Remarks

An env renders only the modes its metadata["render_modes"] lists: CartPole lists Human and RgbArray, the toy_text grids add Ansi, CarRacing adds StatePixels. The _list modes are not an env's own: make wraps an env in RenderCollection for them, which collects the base mode's frames between resets.

The strings stay the canonical form (DR-93): an env's mode is any string Gymnasium accepts, including modes no constant here names (a user's env's own, or make's "no-render-mode" test), so TryParse(string?) answers null for those rather than failing.

Reference: gymnasium/core.py (Env.render).

Fields

Ansi

"ansi": Render() returns the frame as text (RenderResult.Ansi), FrozenLake's, CliffWalking's and Taxi's grids.

public const string Ansi = "ansi"

Field Value

string

AnsiList

"ansi_list": every Ansi frame since the last Render() or reset, collected by RenderCollection.

public const string AnsiList = "ansi_list"

Field Value

string

DepthArray

"depth_array": Render() returns a depth image (RenderResult.Depth), the MuJoCo envs' mode.

public const string DepthArray = "depth_array"

Field Value

string

DepthArrayList

"depth_array_list": every DepthArray frame since the last Render() or reset, collected by RenderCollection.

public const string DepthArrayList = "depth_array_list"

Field Value

string

Human

"human": the env draws into a window during Step and Reset, and Render() returns None.

public const string Human = "human"

Field Value

string

RgbArray

"rgb_array": Render() returns the frame, an (H, W, 3) uint8 array (RenderResult.Rgb).

public const string RgbArray = "rgb_array"

Field Value

string

RgbArrayList

"rgb_array_list": every RgbArray frame since the last Render() or reset, collected by RenderCollection (RenderResult.Frames).

public const string RgbArrayList = "rgb_array_list"

Field Value

string

RgbdTuple

"rgbd_tuple": Render() returns the frame and its depth image together (RenderResult.RgbDepth), the MuJoCo envs' mode.

public const string RgbdTuple = "rgbd_tuple"

Field Value

string

RgbdTupleList

"rgbd_tuple_list": every RgbdTuple frame since the last Render() or reset, collected by RenderCollection.

public const string RgbdTupleList = "rgbd_tuple_list"

Field Value

string

StatePixels

"state_pixels": CarRacing's 96×96 frame, the image its observations are, rather than the 600×400 RgbArray view.

public const string StatePixels = "state_pixels"

Field Value

string

StatePixelsList

"state_pixels_list": every StatePixels frame since the last Render() or reset, collected by RenderCollection.

public const string StatePixelsList = "state_pixels_list"

Field Value

string

Properties

All

Every RenderMode member, in the order the enum declares them (the order of the constants above).

public static IReadOnlyList<RenderMode> All { get; }

Property Value

IReadOnlyList<RenderMode>

Remarks

A shared, read-only list.

Methods

Name(RenderMode)

Gymnasium's string for a member: RenderMode.RgbArray is "rgb_array". The env constructors that take the enum pass it on through this, so both spellings build the same env.

public static string Name(RenderMode mode)

Parameters

mode RenderMode

The mode.

Returns

string

The string, one of this class's constants.

Exceptions

ArgumentOutOfRangeException

Thrown for a value RenderMode does not declare ((RenderMode)99).

Parse(string?)

The member for Gymnasium's string: "rgb_array" is RenderMode.RgbArray. Only Gymnasium's strings are accepted, not the members' C# names ("RgbArray"), as Python's Enum(value) accepts values only.

public static RenderMode Parse(string? name)

Parameters

name string

The string.

Returns

RenderMode

The member.

Exceptions

ValueError

Thrown for a string no member stands for ('no-render-mode' is not a valid RenderMode), which Gymnasium may still accept as a render mode: use TryParse(string?) on an env's own mode.

TryParse(string?)

The member for Gymnasium's string, or null when no member stands for it: a custom mode, or no mode at all. RenderModes.TryParse(env.RenderMode) == RenderMode.RgbArray compares an env's mode with a member without failing on modes the enum does not list.

public static RenderMode? TryParse(string? name)

Parameters

name string

The string, typically RenderMode; null gives null.

Returns

RenderMode?

The member, or null.

TryParse(string?, out RenderMode)

The .NET TryParse pattern of TryParse(string?): the member for Gymnasium's string, if one stands for it.

public static bool TryParse(string? name, out RenderMode mode)

Parameters

name string

The string; null matches no member.

mode RenderMode

The member, when true is returned; Human (the enum's default) otherwise.

Returns

bool

true when a member stands for name.