Class EnvChecker
Gymnasium's gymnasium.utils.env_checker: the checks an env must pass to follow the API. Today it holds
DataEquivalence(object?, object?, bool), which tests and checkers use to compare observations, actions and infos; the
env checks themselves arrive with the registry (P3).
public static class EnvChecker
- Inheritance
-
EnvChecker
- Inherited Members
Remarks
Reference: gymnasium/utils/env_checker.py.
Methods
CheckEnv(IEnv, bool?, bool, bool)
Checks that an env follows Gymnasium's API (Gymnasium's check_env): its spaces, then reset (return type,
seed determinism, options), the passive checks of a reset and a step, step determinism, fresh data on every
call, every declared render mode, and a double close. Problems that make the env unusable are assertions;
questionable choices are warnings through Logger.
public static void CheckEnv(IEnv env, bool? warn = null, bool skipRenderCheck = false, bool skipCloseCheck = false)
Parameters
envIEnvThe env, ideally unwrapped (a wrapper is checked too, with a warning).
warnbool?Ignored, as in Gymnasium; giving it warns that it is.
skipRenderCheckboolSkip the render checks, which build one env per declared render mode.
skipCloseCheckboolSkip building an env from the spec to close it twice.
Remarks
The render checks build an env for every mode in metadata["render_modes"] through the env's spec, so
human needs a viewer (Gymnasium.HumanViewerFactory, DR-20) as Gymnasium's needs pygame; pass
skipRenderCheck where there is none. Gymnasium's JAX and PyTorch conversions do not apply:
Gym.NET's envs return NumSharp arrays.
The env is reset and stepped many times and left in whatever state the last check put it. The observations the checks collect are left to the garbage collector rather than disposed: an env that wrongly hands out its own buffer, which CheckReturnedDataNotReused(IEnv, long) reports, must not have it disposed under it first.
Reference: gymnasium/utils/env_checker.py.
Exceptions
- TypeError
Thrown when
envis null, or the render checks find arender_modesthat is not iterable.- AttributeError
Thrown when the env has no action or observation space.
- AssertionError
Thrown for the first violation found, with Gymnasium's message.
- KeyError
Thrown when the render checks run and the metadata has no
render_modes.
CheckResetOptions(IEnv)
Checks that the env can be reset with options (Gymnasium's check_reset_options): reset(options={}) must not raise TypeError.
public static void CheckResetOptions(IEnv env)
Parameters
envIEnvThe env.
Remarks
Reference: gymnasium/utils/env_checker.py.
Exceptions
- AssertionError
Thrown when the reset raises TypeError, with Gymnasium's message.
CheckResetReturnInfoDeprecation(IEnv)
Warns when the env's reset still takes the pre-0.26 return_info argument (Gymnasium's
check_reset_return_info_deprecation): a public Reset overload with a parameter of that Python name.
public static void CheckResetReturnInfoDeprecation(IEnv env)
Parameters
envIEnvThe env.
Remarks
Reference: gymnasium/utils/env_checker.py.
CheckResetReturnType(IEnv)
Checks what an unseeded reset returns (Gymnasium's check_reset_return_type): an observation within the
space and an info dict. The 2-tuple form Gymnasium also asserts is a ResetResult<TObs> by type.
public static void CheckResetReturnType(IEnv env)
Parameters
envIEnvThe env.
Remarks
Reference: gymnasium/utils/env_checker.py.
Exceptions
- AssertionError
Thrown for an observation outside the space or a null info, with Gymnasium's messages.
CheckResetSeedDeterminism(IEnv)
Checks that seeded resets are deterministic and reseed the env's generator (Gymnasium's
check_reset_seed_determinism): two reset(seed=123) give equivalent observations and the same
generator state, the unseeded resets after them agree too, and reset(seed=456) moves the generator elsewhere.
public static void CheckResetSeedDeterminism(IEnv env)
Parameters
envIEnvThe env.
Remarks
The determinism of the observations is asserted only for an env whose spec says it is deterministic, as in
Gymnasium; the generator checks always run. Gymnasium's checks of the signature have no counterpart: every
Reset takes a seed, and C# allows a BigInteger? parameter no default but null, so the
warning about a seed default other than None cannot arise.
Reference: gymnasium/utils/env_checker.py.
Exceptions
- AssertionError
Thrown for an observation outside the space, a reset that leaves no generator or does not reseed it (
super().reset(seed=seed)missing), or observations that differ for the same seed, with Gymnasium's messages; and for a TypeError raised by the resets, which Gymnasium turns into one.
CheckReturnedDataNotReused(IEnv, long)
Checks that every reset and step returns new observation and info data (Gymnasium's
check_returned_data_not_reused): a reset, up to two steps and another reset, compared pairwise with
DataSharesObjects(object?, object?).
public static void CheckReturnedDataNotReused(IEnv env, long seed = 123)
Parameters
Remarks
Identity, not value, is compared, so even an array an env means to be constant must be a new array in every result: neither the user nor this check can know a later call will not change it. Reference: gymnasium/utils/env_checker.py.
Exceptions
- AssertionError
Thrown when two calls returned data sharing an object, naming both calls.
CheckSeedDeprecation(IEnv)
Warns when the env still has the pre-0.26 seed function (Gymnasium's check_seed_deprecation, which
tests callable(getattr(env, "seed", None))): a public instance method named Seed, or a seed
attribute set at run time to a function. Seeding is Reset(seed: s)'s job.
public static void CheckSeedDeprecation(IEnv env)
Parameters
envIEnvThe env.
Remarks
A run-time seed attribute that is not a function (a number, a list) is not one, as in Python.
Reference: gymnasium/utils/env_checker.py.
CheckSpaceLimit(Space, string)
Warns about box bounds that make learning hard (Gymnasium's check_space_limit, run only by
CheckEnv(IEnv, bool?, bool, bool)): infinite bounds, and for a 1-d action box any range other than a symmetric or
[0, 1] one within [-1, 1]. Tuples and dicts are checked subspace by subspace.
public static void CheckSpaceLimit(Space space, string spaceType)
Parameters
Remarks
Reference: gymnasium/utils/env_checker.py.
CheckStepDeterminism(IEnv, long)
Checks that one step after a seeded reset is deterministic (Gymnasium's check_step_determinism): the same
seed and action give the same generator state, equivalent observation, reward and info, the same termination,
and no truncation. An env whose spec is nondeterministic is skipped.
public static void CheckStepDeterminism(IEnv env, long seed = 123)
Parameters
envIEnvThe env, which must already pass the reset checks.
seedlongThe seed of the action space and of both resets.
Remarks
Reference: gymnasium/utils/env_checker.py.
Exceptions
- AssertionError
Thrown for the first difference, with Gymnasium's message.
DataEquivalence(object?, object?, bool)
Whether two values are equivalent (Gymnasium's data_equivalence): of the same Python type, dicts with the
same keys and equivalent values, tuples and lists of equivalent items, arrays of the same shape and dtype with
close (or, when exact, equal) entries, and anything else equal by Python's ==.
public static bool DataEquivalence(object? data1, object? data2, bool exact = false)
Parameters
data1objectThe first value.
data2objectThe second value.
exactboolWhether arrays must be equal entry for entry rather than within
np.allclose(rtol=1e-5, atol=1e-5).
Returns
Remarks
The type test is on the values' Python counterparts (PyBuiltins): every .NET integer is an
int, an object?[] or ITuple a tuple, a typed array or list a
list, a 0-d array the NumPy scalar it stands for (DR-08), so 1 and 1L are equivalent but a
tuple never matches a list, as in Gymnasium.
A 0-d array compares with ==, exactly, as Gymnasium compares NumPy scalars (only arrays of one or more
dimensions go through allclose); a NaN therefore never equals itself.
Reference: gymnasium/utils/env_checker.py (data_equivalence).