Table of Contents

Class RecordEpisodeStatistics<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Records each episode's return, length and duration: the step that ends an episode gets info["episode"] = {"r": return, "l": length, "t": seconds}, and the last buffer_length episodes stay in ReturnQueue, LengthQueue and TimeQueue.

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

Remarks

The statistics go into the info the env returned, which is edited in place. The time is wall-clock seconds since the reset (Python's time.perf_counter(), rounded to 6 digits), so it differs between runs: parity and golden comparisons leave the t entry out.

Reference: gymnasium/wrappers/common.py.

Constructors

RecordEpisodeStatistics(Env<TObs, TAct>, RecordEpisodeStatisticsOptions)

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

public RecordEpisodeStatistics(Env<TObs, TAct> env, RecordEpisodeStatisticsOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options RecordEpisodeStatisticsOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

RecordEpisodeStatistics(Env<TObs, TAct>, int, string)

Wraps env.

public RecordEpisodeStatistics(Env<TObs, TAct> env, int bufferLength = 100, string statsKey = "episode")

Parameters

env Env<TObs, TAct>

The env whose episodes to record.

bufferLength int

How many episodes the queues keep (Python's deque(maxlen=buffer_length)).

statsKey string

The info key for the statistics.

Exceptions

TypeError

Thrown when env is null.

ValueError

Thrown for a negative bufferLength: maxlen must be non-negative.

Properties

EpisodeCount

The number of episodes finished (episode_count).

public long EpisodeCount { get; set; }

Property Value

long

EpisodeLengths

The current episode's length so far (episode_lengths).

public long EpisodeLengths { get; set; }

Property Value

long

EpisodeReturns

The current episode's return so far (episode_returns).

public double EpisodeReturns { get; set; }

Property Value

double

EpisodeStartTime

When the current episode began, in perf_counter seconds (episode_start_time); -1 before the first reset.

public double EpisodeStartTime { get; set; }

Property Value

double

LengthQueue

The lengths of the last episodes, oldest first (length_queue).

public Deque<long> LengthQueue { get; }

Property Value

Deque<long>

ReturnQueue

The returns of the last episodes, oldest first (return_queue).

public Deque<double> ReturnQueue { get; }

Property Value

Deque<double>

SavedKwargs

The recorded constructor arguments, {'buffer_length': 100, 'stats_key': 'episode'} (Python's _saved_kwargs).

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

Property Value

Info

TimeQueue

The durations of the last episodes, oldest first (time_queue).

public Deque<double> TimeQueue { get; }

Property Value

Deque<double>

Methods

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

Resets the env and starts a new episode's statistics.

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 and counts the step; the step that ends an episode records it and adds the statistics to the info.

public override StepResult<TObs> Step(TAct action)

Parameters

action TAct

The action, passed on.

Returns

StepResult<TObs>

The env's transition, its info extended when the episode ended.

Exceptions

AssertionError

Thrown, empty as Python's bare assert, when the info already has the statistics key.