Class EnvMatch
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
Reference: gymnasium/utils/env_match.py.
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
envAIEnvThe first env; its action space supplies the actions.
envBIEnvThe second env.
numStepsintThe number of steps; 0 checks the reset only.
seedlongThe seed of the resets and of
envA's action space.skipObsboolSkip the observation space and the observations.
skipRewboolSkip the rewards.
skipTerminalboolSkip the
terminatedsignals.skipTruncatedboolSkip the
truncatedsignals.skipRenderboolSkip the renders; they are skipped anyway when either env renders nothing or
human.infoComparisonstringequivalence(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), orskip.
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
infoComparisonor different spaces, as Gymnasium's bare asserts.- KeyError
Thrown in
supersetmode when B's info lacks one of A's keys, as Python'sinfo_b[key]raises.