Table of Contents

Class DelayObservation<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Delays every observation by delay steps, as Gymnasium's DelayObservation does: until the delay has passed, the wrapper returns the space's zero (CreateZeroArray(Space)), then the observation the env returned delay steps earlier. Use it to test an agent's tolerance of stale observations.

public class DelayObservation<TObs, TAct> : ObservationWrapper<TObs, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs

Type Parameters

TObs

The observation type, unchanged.

TAct

The action type, passed through.

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

Remarks

The reset's observation is delayed too: with a delay of 2, the reset and the first step return zeros. A delayed observation is the env's own object, handed on when its turn comes; each zero is a new element the caller owns. The observations still queued at a reset are dropped, not released: the env's info may hold them, so they are left to NumSharp's finalizer, as elsewhere in Gym.NET.

Gymnasium refuses a non-integer delay with TypeError; here the parameter is a long, so the compiler refuses it instead.

Reference: gymnasium/wrappers/stateful_observation.py.

Constructors

DelayObservation(Env<TObs, TAct>, DelayObservationOptions)

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

public DelayObservation(Env<TObs, TAct> env, DelayObservationOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options DelayObservationOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

TypeError

Thrown when a required argument is unset, with Python's missing-argument message.

DelayObservation(Env<TObs, TAct>, long)

Wraps env.

public DelayObservation(Env<TObs, TAct> env, long delay)

Parameters

env Env<TObs, TAct>

The env.

delay long

The number of steps observations are delayed; 0 delays nothing.

Exceptions

ValueError

Thrown for a negative delay: The delay needs to be greater than zero, actual value: -1.

TypeError

Thrown when env is null.

Properties

Delay

The delay in steps (delay).

public long Delay { get; }

Property Value

long

ObservationQueue

The observations not returned yet, oldest first (observation_queue); the reset clears it.

public Queue<TObs> ObservationQueue { get; }

Property Value

Queue<TObs>

SavedKwargs

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

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

Property Value

Info

Methods

Observation(TObs)

Queues the env's observation and returns the one Delay steps old, or the space's zero before then.

public override TObs Observation(TObs observation)

Parameters

observation TObs

The env's observation; the wrapper holds it until its turn.

Returns

TObs

The delayed observation (the env's own object), or a new zero element.

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

Clears the queued observations, then resets the env.

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 space's zero (the env's first observation when the delay is 0) and the env's info.

Exceptions

Error

Thrown for a negative seed.