Class RecordEpisodeStatisticsVector<TObs, TAct>
Records each sub-env's episode return, length and duration, as Gymnasium's vector RecordEpisodeStatistics
does: a step that ends episodes adds infos["episode"] = {"r", "l", "t"} (zeros for the sub-envs that did not
end) and infos["_episode"] (which did), and the last buffer_length episodes stay in the queues.
[PyName("RecordEpisodeStatistics")]
public class RecordEpisodeStatisticsVector<TObs, TAct> : VectorWrapper<TObs, TAct>, IVectorEnv, IDisposable
Type Parameters
TObsThe batched observation type, passed through.
TActThe batched action type, passed through.
- Inheritance
-
VectorEnv<TObs, TAct>VectorWrapper<TObs, TAct, TObs, TAct>VectorWrapper<TObs, TAct>RecordEpisodeStatisticsVector<TObs, TAct>
- Implements
- Inherited Members
- Extension Methods
Remarks
With NEXT_STEP the autoreset step after an episode's end starts the next episode's statistics instead of
counting; with SAME_STEP every step counts and an ended episode's statistics restart at once. A
reset_mask resets only the masked sub-envs' statistics, after Gymnasium's checks of the mask. The time is
wall-clock seconds (Python's time.perf_counter(), rounded to 6 digits), so it differs between runs: parity
comparisons leave the t entry out.
Reference: gymnasium/wrappers/vector/common.py.
Constructors
RecordEpisodeStatisticsVector(VectorEnv<TObs, TAct>, int, string)
Wraps env.
public RecordEpisodeStatisticsVector(VectorEnv<TObs, TAct> env, int bufferLength = 100, string statsKey = "episode")
Parameters
envVectorEnv<TObs, TAct>The vector env.
bufferLengthintHow many episodes the queues keep.
statsKeystringThe info key for the statistics.
Exceptions
- TypeError
Thrown when the env's autoreset mode is not an AutoresetMode, with Gymnasium's message, or
envis null.- ValueError
Thrown for a negative
bufferLength:maxlen must be non-negative.
Properties
EpisodeCount
The number of episodes ended so far (episode_count).
public long EpisodeCount { get; }
Property Value
EpisodeLengths
Each sub-env's length so far, int64 (episode_lengths).
public NDArray EpisodeLengths { get; }
Property Value
EpisodeReturns
Each sub-env's return so far, float64 (episode_returns).
public NDArray EpisodeReturns { get; }
Property Value
EpisodeStartTimes
When each sub-env's episode began, in perf_counter seconds (episode_start_times).
public NDArray EpisodeStartTimes { get; }
Property Value
LengthQueue
The lengths of the last episodes (length_queue).
public Deque<long> LengthQueue { get; }
Property Value
PrevDones
Which sub-envs ended at the last step (prev_dones).
public NDArray PrevDones { get; }
Property Value
ReturnQueue
The returns of the last episodes (return_queue).
public Deque<double> ReturnQueue { get; }
Property Value
TimeQueue
The durations of the last episodes (time_queue).
public Deque<double> TimeQueue { get; }
Property Value
Methods
Dispose(bool)
Releases the statistics' arrays, then disposes as every vector wrapper does.
protected override void Dispose(bool disposing)
Parameters
Reset(IReadOnlyList<BigInteger?>, IReadOnlyDictionary<string, object?>?)
Resets the env with one seed per sub-env, and the statistics as Reset(BigInteger?, IReadOnlyDictionary<string, object?>?) does.
public override VectorResetResult<TObs> Reset(IReadOnlyList<BigInteger?> seeds, IReadOnlyDictionary<string, object?>? options = null)
Parameters
seedsIReadOnlyList<BigInteger?>The seeds, passed on.
optionsIReadOnlyDictionary<string, object>The options, passed on.
Returns
- VectorResetResult<TObs>
The env's reset.
Exceptions
- TypeError
Thrown for a mask that is not a bool array.
- ValueError
Thrown for a mask of the wrong shape or with no true value.
Reset(BigInteger?, IReadOnlyDictionary<string, object?>?)
Resets the env and the statistics: all of them, or only the masked sub-envs' for a reset_mask.
public override VectorResetResult<TObs> Reset(BigInteger? seed = null, IReadOnlyDictionary<string, object?>? options = null)
Parameters
seedBigInteger?The seed, passed on.
optionsIReadOnlyDictionary<string, object>The options, passed on.
Returns
- VectorResetResult<TObs>
The env's reset.
Exceptions
- TypeError
Thrown for a mask that is not a bool array, with Gymnasium's messages.
- ValueError
Thrown for a mask of the wrong shape or with no true value, with Gymnasium's messages.
Step(TAct)
Steps the env, updates the statistics, and adds them to the infos of a step that ends episodes.
public override VectorStepResult<TObs> Step(TAct actions)
Parameters
actionsTActThe actions, passed on.
Returns
- VectorStepResult<TObs>
The env's transition, its infos extended when episodes ended.
Exceptions
- ValueError
Thrown when the infos already hold the statistics key, with Gymnasium's message.