Class TimeAwareObservation<TObs, TAct>
Adds the episode's elapsed steps to every observation, as Gymnasium's TimeAwareObservation does: a
Dict observation gets a time key, a Tuple one a last item, anything else becomes
{"obs": obs, "time": time}, and by default the result is flattened into one array.
public class TimeAwareObservation<TObs, TAct> : ObservationWrapper<object?, TObs, TAct>, IDynamicAttributes, IWrapper, IEnv, IDisposable, IRecordConstructorArgs
Type Parameters
TObsThe env's observation type.
TActThe action type, passed through.
- Inheritance
-
ObservationWrapper<object, TObs, TAct>TimeAwareObservation<TObs, TAct>
- Implements
- Inherited Members
- Extension Methods
Remarks
The time is the step count since the last reset, as an int32 array [t], or with normalize_time a
float32 [t / max_episode_steps]; the limit comes from the env's spec or, failing that, a TimeLimit in
the stack. The observation type depends on flatten at run time (an array when flattened, a dict or tuple
otherwise), so the wrapper's observations are objects.
Reference: gymnasium/wrappers/stateful_observation.py.
Constructors
TimeAwareObservation(Env<TObs, TAct>, TimeAwareObservationOptions)
Builds the instance from its options record: the properties set, the constructor's defaults for the rest.
public TimeAwareObservation(Env<TObs, TAct> env, TimeAwareObservationOptions options)
Parameters
envEnv<TObs, TAct>The env to wrap.
optionsTimeAwareObservationOptionsThe options.
Exceptions
- ArgumentNullException
Thrown when
optionsis null.
TimeAwareObservation(Env<TObs, TAct>, bool, bool, string)
Wraps env.
public TimeAwareObservation(Env<TObs, TAct> env, bool flatten = true, bool normalizeTime = false, string dictTimeKey = "time")
Parameters
envEnv<TObs, TAct>The env; its spec or a
TimeLimitin its stack must give the step limit.flattenboolWhether the observation and the time are flattened into one array (Gymnasium's default).
normalizeTimeboolWhether the time is the fraction of the limit elapsed (float32) instead of the step count (int32).
dictTimeKeystringThe time's key in a
Dictobservation.
Exceptions
- TypeError
Thrown when
envis null.- ValueError
Thrown when no step limit is known, or
dictTimeKeyalready is a key of the env'sDictspace, with Gymnasium's messages.
Properties
DictTimeKey
The time's key in a Dict observation.
public string DictTimeKey { get; }
Property Value
Flatten
Whether observations are flattened (flatten).
public bool Flatten { get; }
Property Value
MaxTimesteps
The step limit the time is measured against (max_timesteps).
public long MaxTimesteps { get; }
Property Value
NormalizeTime
Whether the time is normalized by the limit (normalize_time).
public bool NormalizeTime { get; }
Property Value
SavedKwargs
The recorded constructor arguments (Python's _saved_kwargs).
[PyName("_saved_kwargs")]
public Info SavedKwargs { get; }
Property Value
Timesteps
The steps since the last reset (timesteps).
public long Timesteps { get; set; }
Property Value
Methods
Dispose(bool)
Disposes the unflattened space with the stack.
protected override void Dispose(bool disposing)
Parameters
Observation(TObs)
Adds the time to an observation (observation(observation)), then flattens when Flatten is set.
public override object? Observation(TObs observation)
Parameters
observationTObsThe env's observation.
Returns
- object
A new array when flattening; otherwise a new dict or tuple holding the observation and the time array.
Reset(BigInteger?, IReadOnlyDictionary<string, object?>?)
Resets the env and the step count.
public override ResetResult<object?> Reset(BigInteger? seed = null, IReadOnlyDictionary<string, object?>? options = null)
Parameters
seedBigInteger?The seed, passed on.
optionsIReadOnlyDictionary<string, object>The options, passed on.
Returns
- ResetResult<object>
The first observation with time 0.
Exceptions
- Error
Thrown for a negative seed.
Step(TAct)
Steps the env and counts the step before the observation is built.
public override StepResult<object?> Step(TAct action)
Parameters
actionTActThe action, passed on.
Returns
- StepResult<object>
The transition with the time added to its observation.