Table of Contents

Class FrameStackObservation<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Stacks the last stack_size observations along a new first axis, as Gymnasium's FrameStackObservation does: the space is batch_space(env.observation_space, stack_size), and after a reset the stack is padded with the reset's observation ("reset", the default), the space's zero ("zero"), or a given element. Use it to give a memoryless agent motion (velocities from frames).

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

Type Parameters

TObs

The env's observation type, which the stacks share: an array space stacks into an array, a Dict into a dict, a Tuple into a tuple. A space whose stack is of another type (a Text space stacks into a tuple of strings) needs the untyped form, object; the constructor refuses the typed one.

TAct

The action type, passed through.

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

Remarks

Every stack returned is a deep copy of the wrapper's buffer, so the caller owns it and later steps never change it. The wrapper keeps the env's last stack_size observations (Python's deque) and releases only what it created: the buffer, and the zero padding (when the reset's padding replaces it, or with the wrapper). The env's observations that fall out of the stack are left to NumSharp's finalizer, since the env's info may hold them; a custom padding stays the caller's.

Gymnasium refuses a non-integer stack_size with TypeError; here it is a long.

Reference: gymnasium/wrappers/stateful_observation.py.

Constructors

FrameStackObservation(Env<TObs, TAct>, FrameStackObservationOptions)

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

public FrameStackObservation(Env<TObs, TAct> env, FrameStackObservationOptions options)

Parameters

env Env<TObs, TAct>

The env to wrap.

options FrameStackObservationOptions

The options.

Exceptions

ArgumentNullException

Thrown when options is null.

TypeError

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

FrameStackObservation(Env<TObs, TAct>, long, object?)

Wraps env.

public FrameStackObservation(Env<TObs, TAct> env, long stackSize, object? paddingType = null)

Parameters

env Env<TObs, TAct>

The env.

stackSize long

The number of observations stacked; positive.

paddingType object

"reset" (null, the default: pad with each episode's first observation), "zero" (pad with the space's zero), or an element of the env's observation space to pad with, which stays the caller's.

Exceptions

ValueError

Thrown for a stack size below 1 (The stack_size needs to be greater than zero, actual value: 0), or a padding that is neither a mode nor an element of the space (Unexpected padding_type, ...).

TypeError

Thrown when the stacks are not of TObs, or env is null.

Properties

ObsQueue

The last StackSize observations, oldest first (obs_queue, a deque of fixed length).

public LinkedList<object?> ObsQueue { get; }

Property Value

LinkedList<object>

PaddingType

The padding mode: reset, zero, or _custom for a given element (padding_type).

public string PaddingType { get; }

Property Value

string

PaddingValue

The element the stack is padded with (padding_value): the space's zero, the given one, or the last reset's observation.

public object? PaddingValue { get; }

Property Value

object

SavedKwargs

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

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

Property Value

Info

StackSize

The number of observations stacked (stack_size).

public long StackSize { get; }

Property Value

long

Methods

Dispose(bool)

Releases the buffer and the zero padding this wrapper created, then disposes the wrapper as every wrapper does.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose().

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

Resets the env and returns stack_size - 1 paddings followed by the first observation.

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>

A new stack and the env's info.

Exceptions

Error

Thrown for a negative seed.

Step(TAct)

Steps the env and returns the stack with its new observation last.

public override StepResult<TObs> Step(TAct action)

Parameters

action TAct

The action, passed on.

Returns

StepResult<TObs>

A new stack (a deep copy), and the env's reward, flags and info.