Skip to content

lit_sb3.core.gym_patches

source module lit_sb3.core.gym_patches

Patches for gymnasium so lit-sb3 keeps working as expected.

Notably patches the TimeLimit wrapper to keep the behaviour as before and provide additional info that the episode reached a timeout, but only when the episode is over because of that.

Adapted from https://github.com/DLR-RM/rl-baselines3-zoo/blob/master/rl_zoo3/gym_patches.py

Classes

  • PatchedTimeLimit — Patched TimeLimit that sets TimeLimit.truncated correctly.

source class PatchedTimeLimit(env: gym.Env, max_episode_steps: int)

Bases : gymnasium.wrappers.TimeLimit

Patched TimeLimit that sets TimeLimit.truncated correctly.

See https://github.com/openai/gym/issues/3102 and https://github.com/Farama-Foundation/Gymnasium/pull/101: keep the behaviour as before and provide additional info that the episode reached a timeout, but only when the episode is over because of that.

Initializes the :class:TimeLimit wrapper with an environment and the number of steps after which truncation will occur.

Parameters

  • env : gym.Env — The environment to apply the wrapper

  • max_episode_steps : int — the environment step after which the episode is truncated (elapsed >= max_episode_steps)

Attributes

  • spec : EnvSpec | None — Modifies the environment spec to include the max_episode_steps=self._max_episode_steps.

Methods

source method PatchedTimeLimit.step(action: Any) → tuple[Any, Any, bool, bool, dict[str, Any]]