Table of Contents

Struct StepResult<TObs>

Namespace
Gym.Observations
Assembly
Gym.dll

One environment transition, (observation, reward, terminated, truncated, info). Deconstructs like a tuple: var (obs, reward, terminated, truncated, info) = env.Step(action);.

public readonly record struct StepResult<TObs> : INDArrayCarrier, IDisposable, IEquatable<StepResult<TObs>>

Type Parameters

TObs

The observation type, an element of the env's observation space.

Implements
Inherited Members
Extension Methods

Remarks

Equality is exact and never broadcasts: observations that are arrays must have the same shape, the same dtype and identical elements (a NaN element equals nothing, not even itself); any other observation compares as Python's == does (PyEquality), and so does the info. The reward compares with Equals(double), which, unlike Python's ==, treats NaN as equal to NaN so equality stays reflexive. Reference: gymnasium/core.py (Env.step).

Constructors

StepResult(TObs, double, bool, bool, Info)

One environment transition, (observation, reward, terminated, truncated, info). Deconstructs like a tuple: var (obs, reward, terminated, truncated, info) = env.Step(action);.

public StepResult(TObs Observation, double Reward, bool Terminated, bool Truncated, Info Info)

Parameters

Observation TObs

The observation after the action; owned by the caller (envs return a fresh array).

Reward double

The reward as float64, the precision of Gymnasium's Python floats; a float32 reward would change every accumulated return.

Terminated bool

The MDP reached a terminal state: the value of what follows is zero, so do not bootstrap past it. Call Reset before stepping again.

Truncated bool

Something outside the MDP ended the episode, typically a TimeLimit: bootstrapping from the final observation stays valid. Call Reset before stepping again.

Info Info

Diagnostics with Python dict semantics (insertion order is observable); never null from Gym's own envs.

Remarks

Equality is exact and never broadcasts: observations that are arrays must have the same shape, the same dtype and identical elements (a NaN element equals nothing, not even itself); any other observation compares as Python's == does (PyEquality), and so does the info. The reward compares with Equals(double), which, unlike Python's ==, treats NaN as equal to NaN so equality stays reflexive. Reference: gymnasium/core.py (Env.step).

Properties

Info

Diagnostics with Python dict semantics (insertion order is observable); never null from Gym's own envs.

public Info Info { get; init; }

Property Value

Info

Information

0.2's name for Info (0.2's Step.Information), kept so 0.2 code compiles until 2.0 (DR-78): the same dict, never null from Gym's own envs where 0.2's could be.

[Obsolete("0.2's name: read Info (or deconstruct the info). Removed in 2.0.")]
public Info Information { get; }

Property Value

Info

Observation

The observation after the action; owned by the caller (envs return a fresh array).

public TObs Observation { get; init; }

Property Value

TObs

Reward

The reward as float64, the precision of Gymnasium's Python floats; a float32 reward would change every accumulated return.

public double Reward { get; init; }

Property Value

double

Terminated

The MDP reached a terminal state: the value of what follows is zero, so do not bootstrap past it. Call Reset before stepping again.

public bool Terminated { get; init; }

Property Value

bool

Truncated

Something outside the MDP ended the episode, typically a TimeLimit: bootstrapping from the final observation stays valid. Call Reset before stepping again.

public bool Truncated { get; init; }

Property Value

bool

Methods

Deconstruct(out TObs, out double, out bool, out Info)

0.2's four-element deconstruction, var (obs, reward, done, info) = env.Step(action);, kept so 0.2 code compiles until 2.0 (DR-58): done is terminated || truncated, as gym 0.21 and Gym.Legacy report it.

[Obsolete("The pre-0.26 4-tuple: done is terminated || truncated, which loses why the episode ended. Deconstruct into (observation, reward, terminated, truncated, info). Removed in 2.0 with Gym.Legacy.")]
public void Deconstruct(out TObs observation, out double reward, out bool done, out Info info)

Parameters

observation TObs

The observation after the action.

reward double

The reward, float64 (0.2's was a float, so a 0.2 line declaring float reward still fails).

done bool

Whether the episode ended, for either reason.

info Info

The info.

Remarks

Footgun: done loses why the episode ended, and bootstrapping from the final observation is right after a truncation but wrong after a termination. The five-element deconstruction keeps both flags.

Dispose()

Releases the arrays the transition holds, the observation's and the info's, nested ones included, so using var step = env.Step(action); frees them at the end of the scope: the arrays an env returns belong to the caller (D19).

public void Dispose()

Remarks

Footgun: copies of this struct share the same arrays, so dispose once, after the last use of the observation and the info; keep anything needed longer with .copy(). Disposing again does nothing more.

Equals(StepResult<TObs>)

Exact equality (see the type's remarks): observations, rewards, flags and infos all equal. Replaces the compiler's member-wise equality, which would call NDArray's broadcasting Equals.

public bool Equals(StepResult<TObs> other)

Parameters

other StepResult<TObs>

The other transition.

Returns

bool

true when the transitions are equal.

GetHashCode()

A hash consistent with Equals(StepResult<TObs>): an array observation contributes its shape only, because GetHashCode() throws (arrays are mutable, hence unhashable in NumPy).

public override int GetHashCode()

Returns

int

The hash.