Table of Contents

Class PassiveEnvChecker<TObs, TAct>

Namespace
Gym.Wrappers
Assembly
Gym.dll

Runs PassiveChecker's checks around the env so that a broken env is reported where it breaks: the spaces at construction, then the first reset, step and render, and whether the reset and the first step, then the first and second steps, returned shared data. Every later call is forwarded unchanged, so the checks cost nothing for the rest of the run. make adds it beneath OrderEnforcing unless disable_env_checker is set.

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

Type Parameters

TObs

The observation type, passed through.

TAct

The action type, passed through.

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

Remarks

Problems are warnings through Logger, or Gymnasium's assertions for what cannot work; the env's results are never changed. The reuse check holds views of the reset's and first step's observation and info (see RetainedData) until it has run, then lets them go, so the env's memory is not kept for the run.

As in Gymnasium, stepping before the first reset steps the env and then fails with Python's unpacking TypeError, since there is no reset data to compare with; OrderEnforcing above it in a make-built stack catches that mistake first.

Reference: gymnasium/wrappers/common.py.

Constructors

PassiveEnvChecker(Env<TObs, TAct>)

Wraps env and checks its action and observation spaces.

public PassiveEnvChecker(Env<TObs, TAct> env)

Parameters

env Env<TObs, TAct>

The env to check.

Exceptions

TypeError

Thrown when env is null.

AttributeError

Thrown when the env has no action space (The environment must specify an action space. https://gymnasium.farama.org/introduction/create_custom_env/) or no observation space (the same with "observation"), the action space being checked first.

AssertionError

Thrown for a space that cannot work (CheckSpace(Space?, string, Action<Box>)).

Properties

CheckedDataReuse

Whether the data-reuse check of the first two steps ran (checked_data_reuse).

public bool CheckedDataReuse { get; set; }

Property Value

bool

CheckedRender

Whether the first render was checked (checked_render); setting it back to false checks the next render.

public bool CheckedRender { get; set; }

Property Value

bool

CheckedReset

Whether the first reset was checked (checked_reset); setting it back to false checks the next reset.

public bool CheckedReset { get; set; }

Property Value

bool

CheckedStep

Whether the first step was checked (checked_step); setting it back to false checks the next step.

public bool CheckedStep { get; set; }

Property Value

bool

CloseCalled

Whether Close() ran (close_called); a later close that throws is reported before the error propagates.

public bool CloseCalled { get; set; }

Property Value

bool

PreviousData

The reset's or first step's observation and info, retained for the reuse check of the next step (Python's _previous_data); null before the first checked reset and once the check is done. The wrapper owns the retained views and releases them when it replaces them or is disposed: read, never dispose.

[PyName("_previous_data")]
public (RetainedData Obs, RetainedData Info)? PreviousData { get; }

Property Value

(RetainedData Obs, RetainedData Info)?

SavedKwargs

The recorded constructor arguments, {} (Python's _saved_kwargs).

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

Property Value

Info

Spec

The env's spec with DisableEnvChecker cleared (a deep copy, cached), or null when the env has none. No WrapperSpec is added: the checker is part of the spec itself.

public override EnvSpec? Spec { get; set; }

Property Value

EnvSpec

Exceptions

AttributeError

Thrown when assigned, as for every wrapper.

Methods

Close()

Closes the env. Closing again must be allowed: when a later close throws, a warning says so before the error propagates.

public override void Close()

Dispose(bool)

Releases the retained reuse-check data, then closes and disposes the env as every wrapper does.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true from Dispose().

Render()

Renders the env; the first render runs EnvRenderPassiveChecker(IEnv), later ones are forwarded.

public override RenderResult Render()

Returns

RenderResult

The env's rendering, unchanged.

Exceptions

AssertionError

Thrown by the first render's checks for metadata that contradicts the render mode.

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

Resets the env. The first reset runs EnvResetPassiveChecker<TObs, TAct>(Env<TObs, TAct>, BigInteger?, IReadOnlyDictionary<string, object?>?) and keeps its data for the first step's reuse check; later resets are forwarded.

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>

The env's first observation and info, unchanged.

Exceptions

Error

Thrown for a negative seed.

AssertionError

Thrown by the first reset's checks for a malformed observation or a null info.

Step(TAct)

Steps the env. The first step runs EnvStepPassiveChecker<TObs, TAct>(Env<TObs, TAct>, TAct) and compares its data with the reset's; the second compares its data with the first step's; later steps are forwarded.

public override StepResult<TObs> Step(TAct action)

Parameters

action TAct

The action, passed on unchecked (some envs accept out-of-bounds actions).

Returns

StepResult<TObs>

The env's transition, unchanged.

Exceptions

AssertionError

Thrown by the first step's checks for a malformed observation or a null info.

TypeError

Thrown after the env stepped when there is no reset data to compare with (stepped before the first reset): cannot unpack non-iterable NoneType object, as in Gymnasium.