Table of Contents

Class EnvInfo

Namespace
Gym.Envs
Assembly
Gym.dll

The base of the typed info records (DR-91, DR-94, DR-95): a built-in env's info read as a record with a .NET-typed property per key, HalfCheetahInfoV5 info = step.Info; then info.XPosition, while the dict's own values stay readable through the indexer, (double)(NDArray)info["x_position"], as on step.Info.

public abstract record EnvInfo : IEquatable<EnvInfo>
Inheritance
EnvInfo
Implements
Derived
Inherited Members
Extension Methods

Remarks

The records are generated from positional records marked [GymDict] that derive from this class, as the env classes derive from Env (the MuJoCo envs' from MujocoInfo, the toy_text envs' from ToyTextInfo). A member is double for every scalar (a float32 or int value widens exactly), bool for a flag, NDArray for an array, and nullable when the env does not always send its key (a reset sends fewer keys than a step); Get<T>(IReadOnlyDictionary<string, object?>, string) converts each value.

A record read from a dict keeps that dict's values (DR-94): the indexer and ToInfo() give the values as the env sent them, a float32 scalar as float32. A record built in code, or by a with expression, has no dict inside: its indexer reads its own members, so a changed copy never shows stale values.

Equality (DR-92): == and Equals(object) compare the members, as records do (two records with equal members are equal whatever dtypes their dicts held); PyEquals(object?) is Python's == with a dict or another record.

Footgun: array members are the step result's own arrays, shared, not copied: disposing the result (DR-51) disposes them too. Scalar members are copies and outlive it.

Constructors

EnvInfo()

A record built in code, without a dict inside.

protected EnvInfo()

EnvInfo(EnvInfo)

The copy a with expression makes: everything but the dict inside, so a copy whose members changed reads its own members through the indexer instead of the original dict's values.

protected EnvInfo(EnvInfo original)

Parameters

original EnvInfo

The record copied.

Exceptions

ArgumentNullException

Thrown when original is null.

Properties

this[string]

The value under a key as the env sent it (a NumPy scalar as a 0-d array, a Python int as a long), read from the dict inside; for a record without one, its member's value under that key's Python name.

public object? this[string key] { get; }

Parameters

key string

The key, Gymnasium's spelling ("x_position").

Property Value

object

The value; an array is the dict's own.

Exceptions

ArgumentNullException

Thrown when key is null.

KeyError

Thrown, with Python's message, for a key the info does not hold.

Source

The dict the record was read from (DR-94), or null for a record built in code or by with. The generated conversion from Info sets it; the record shares it, not a copy.

protected Info? Source { get; init; }

Property Value

Info

Methods

ContainsKey(string)

Whether the info holds a key: the dict inside's keys, or a record's members that are not null.

public bool ContainsKey(string key)

Parameters

key string

The key.

Returns

bool

true when the key is present.

Exceptions

ArgumentNullException

Thrown when key is null.

Equals(EnvInfo?)

The base's share of record equality: the same record type. Each generated record compares its members on top, never the dict inside, so records of equal members are equal whatever their dicts held.

public virtual bool Equals(EnvInfo? other)

Parameters

other EnvInfo

The other record.

Returns

bool

true when both are of the same record type.

GetHashCode()

A hash consistent with Equals(EnvInfo?): the record type's.

public override int GetHashCode()

Returns

int

The hash.

PyEquals(object?)

Python's == (DR-92) between this info and a dict (an Info, a Dictionary<TKey, TValue>) or another record: the same keys with equal values (PyEquality), whatever the order and the numbers' types.

public bool PyEquals(object? other)

Parameters

other object

The other value; null (Python's None) equals no dict.

Returns

bool

true when the two are equal dicts.

ToInfo()

The record as an info dict: a shallow copy of the dict it was read from, the env's values and key order kept, else a new dict of its members by Python name, in declaration order, the null ones left out.

public Info ToInfo()

Returns

Info

A new dict the caller owns; array values are shared, not copied.

ToInfoCore()

The record's members as a new dict by Python name, in declaration order, a null member left out (its key absent): what a record without a dict inside reads, and what equality compares. Generated.

protected abstract Info ToInfoCore()

Returns

Info

A new dict.