Table of Contents

Class RenderCollection<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Collects a frame after every reset and step, so render() returns the list of frames since the last call (RenderResult.Frames) instead of the current one: the *_list render modes. make adds it when render_mode="rgb_array_list" is asked of an env that renders rgb_array itself.

public class RenderCollection<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>
RenderCollection<TObs, TAct>
Implements
Inherited Members
Extension Methods

Remarks

Every reset and step renders the env once more, which costs a frame's drawing each. The render mode reads as the env's with _list appended, and the metadata is the env's (a deep copy) with that mode added.

Ownership (D19): with PopFrames (the default) Render() hands the collected frames over and the caller owns them; without it the frames stay the wrapper's, returned again by every render, and the caller must not dispose them. Frames still held are released when the wrapper is disposed.

Reference: gymnasium/wrappers/rendering.py.

Constructors

RenderCollection(Env<TObs, TAct>, RenderCollectionOptions)

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

public RenderCollection(Env<TObs, TAct> env, RenderCollectionOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options RenderCollectionOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

RenderCollection(Env<TObs, TAct>, bool, bool)

Wraps env, whose render mode must be a single-frame one.

public RenderCollection(Env<TObs, TAct> env, bool popFrames = true, bool resetClean = true)

Parameters

env Env<TObs, TAct>

The env to collect frames of.

popFrames bool

Clear the collection whenever Render() returns it.

resetClean bool

Clear the collection on every reset.

Exceptions

TypeError

Thrown when env is null.

ValueError

Thrown when the env has no render mode (Expected env.render_mode to be not None) or already collects (Expected env.render_mode to not end with '_list', got 'rgb_array_list').

Properties

FrameList

The frames collected since the last render or reset (frame_list), oldest first, owned by the wrapper.

public List<RenderResult> FrameList { get; }

Property Value

List<RenderResult>

PopFrames

Whether Render() clears the collection (pop_frames).

public bool PopFrames { get; set; }

Property Value

bool

RenderMode

The env's render mode with _list appended (rgb_array_list).

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

Property Value

string

Exceptions

AttributeError

Thrown when assigned, as for every wrapper.

ResetClean

Whether a reset clears the collection (reset_clean).

public bool ResetClean { get; set; }

Property Value

bool

SavedKwargs

The recorded constructor arguments, {'pop_frames': True, 'reset_clean': True} (Python's _saved_kwargs).

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

Property Value

Info

Methods

Dispose(bool)

Releases the frames still collected, then closes and disposes the env as every wrapper does.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose().

Render()

The frames collected so far, as one RenderResult.Frames; with PopFrames the collection then starts over and the caller owns the returned frames.

public override RenderResult Render()

Returns

RenderResult

The frames.

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

Resets the env, clears the collection when ResetClean, then collects the first 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 first observation and info.

Exceptions

Error

Thrown for a negative seed.

Step(TAct)

Steps the env, then collects a frame.

public override StepResult<TObs> Step(TAct action)

Parameters

action TAct

The action, passed on.

Returns

StepResult<TObs>

The env's transition.