Table of Contents

Class HumanRendering<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Shows an env that renders images in a window, as Gymnasium's HumanRendering does: every reset and step renders the env and shows the frame at metadata["render_fps"], so the wrapper's render mode is human. make adds it when render_mode="human" is asked of an env that only renders images.

public class HumanRendering<TObs, TAct> : Wrapper<TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TObs

The observation type, passed through.

TAct

The action type, passed through.

Inheritance
Env<TObs, TAct>
Wrapper<TObs, TAct, TObs, TAct>
Wrapper<TObs, TAct>
HumanRendering<TObs, TAct>
Implements
Inherited Members
Extension Methods

Remarks

The window is a viewer from the wrapper's own factory, else Gymnasium.HumanViewerFactory (DR-20, DR-89), opened at the first frame's size; without either the first frame raises DependencyNotInstalled, as Gymnasium does without pygame. Frames are paced by Clock, which sleeps to hold the frame rate. A frame of another size than the first fails the assertion Gymnasium makes; frames of another dtype than uint8 are cast.

In a *_list render mode the env's own render() returns an empty list afterwards, since this wrapper takes every frame (Gymnasium's warning).

Reference: gymnasium/wrappers/rendering.py.

Constructors

HumanRendering(Env<TObs, TAct>)

Wraps env.

public HumanRendering(Env<TObs, TAct> env)

Parameters

env Env<TObs, TAct>

The env; its render mode must be one of AcceptedRenderModes and its metadata must have render_fps.

Exceptions

ValueError

Thrown for another render mode, or metadata without render_fps, with Gymnasium's messages.

TypeError

Thrown when env is null.

HumanRendering(Env<TObs, TAct>, HumanRenderingOptions)

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

public HumanRendering(Env<TObs, TAct> env, HumanRenderingOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options HumanRenderingOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

Fields

AcceptedRenderModes

The render modes the wrapper can show (ACCEPTED_RENDER_MODES).

public static readonly IReadOnlyList<string> AcceptedRenderModes

Field Value

IReadOnlyList<string>

Properties

RenderMode

Always human.

public override string? RenderMode { get; protected set; }

Property Value

string

Exceptions

AttributeError

Thrown when assigned, as for every wrapper.

SavedKwargs

The recorded constructor arguments, {} (Python's _saved_kwargs).

[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }

Property Value

Info

ScreenSize

The window's size, the first frame's (width, height) (screen_size), or null before it.

public (int Width, int Height)? ScreenSize { get; }

Property Value

(int Width, int Height)?

ViewerFactory

Gym.NET's viewer factory for this wrapper's window (DR-20, DR-89): set it before the first frame, as new HumanRendering<TObs, TAct>(env) { ViewerFactory = factory } or as make does with the factory its render-mode overloads were given; null (the default) uses Gymnasium.HumanViewerFactory, read when the window opens. A property, not a constructor argument, so the constructor and the arguments it records stay Gymnasium's: a spec never carries the delegate.

public EnvViewerFactory? ViewerFactory { get; set; }

Property Value

EnvViewerFactory

Remarks

Set after the window opened, it takes effect only if the window is closed and opens again.

Methods

Close()

Closes the window, then the env.

public override void Close()

Render()

public override RenderResult Render()

Returns

RenderResult

None.

Reset(BigInteger?, IReadOnlyDictionary<string, object?>?)

Resets the env, then shows its frame.

public override ResetResult<TObs> Reset(BigInteger? seed = null, IReadOnlyDictionary<string, object?>? options = null)

Parameters

seed BigInteger?

The seed, passed on.

options IReadOnlyDictionary<string, object>

The options, passed on.

Returns

ResetResult<TObs>

The env's reset.

Exceptions

Error

Thrown for a negative seed.

DependencyNotInstalled

Thrown at the first frame when no viewer factory is set.

Step(TAct)

Steps the env, then shows its frame.

public override StepResult<TObs> Step(TAct action)

Parameters

action TAct

The action, passed on.

Returns

StepResult<TObs>

The env's transition.

Exceptions

DependencyNotInstalled

Thrown at the first frame when no viewer factory is set.