Table of Contents

Class EnvMatch

Namespace
Gym.Utils
Assembly
Gym.dll

Gymnasium's gymnasium.utils.env_match: drives two envs with the same seed and actions and asserts they behave the same, for checking a port, a refactor or a wrapper against the original (a legacy env against its new version during a migration, for one).

public static class EnvMatch
Inheritance
EnvMatch
Inherited Members

Remarks

Methods

CheckEnvironmentsMatch(IEnv, IEnv, int, long, bool, bool, bool, bool, bool, string)

Asserts that two envs are identical for numSteps steps (Gymnasium's check_environments_match): the same spaces, then a seeded reset of both and steps with actions sampled from envA's seeded action space, comparing observations, rewards, signals, infos and renders, and resetting both (seeded again) whenever either episode ends.

public static void CheckEnvironmentsMatch(IEnv envA, IEnv envB, int numSteps, long seed = 0, bool skipObs = false, bool skipRew = false, bool skipTerminal = false, bool skipTruncated = false, bool skipRender = false, string infoComparison = "equivalence")

Parameters

envA IEnv

The first env; its action space supplies the actions.

envB IEnv

The second env.

numSteps int

The number of steps; 0 checks the reset only.

seed long

The seed of the resets and of envA's action space.

skipObs bool

Skip the observation space and the observations.

skipRew bool

Skip the rewards.

skipTerminal bool

Skip the terminated signals.

skipTruncated bool

Skip the truncated signals.

skipRender bool

Skip the renders; they are skipped anyway when either env renders nothing or human.

infoComparison string

equivalence (the infos are equivalent), superset (every entry of A's info is in B's, equivalent), keys-equivalence (the same keys), keys-superset (B's keys include A's), or skip.

Remarks

Both envs are stepped as far as the check gets and left there. The observations, infos and frames are compared and dropped; the frames are released at once.

Exceptions

AssertionError

Thrown at the first difference, with Gymnasium's message naming the step and both values; with an empty message for an unknown infoComparison or different spaces, as Gymnasium's bare asserts.

KeyError

Thrown in superset mode when B's info lacks one of A's keys, as Python's info_b[key] raises.