stable_gym.common.max_episode_steps_injection_wrapper

This file contains a small gymnasium wrapper that injects the max_episode_steps argument of a potentially nested TimeLimit wrapper into the base environment under the _time_limit_max_episode_steps attribute.

Module Contents

Classes

MaxEpisodeStepsInjectionWrapper

A gymnasium wrapper that injects the max_episode_steps attribute of the

Functions

get_time_limit_wrapper_max_episode_steps(env)

Returns the max_episode_steps attribute of a potentially nested

inject_attribute_into_base_env(env, attribute_name, ...)

Injects the max_episode_steps argument into the base environment under the

stable_gym.common.max_episode_steps_injection_wrapper.get_time_limit_wrapper_max_episode_steps(env)[source]

Returns the max_episode_steps attribute of a potentially nested TimeLimit wrapper.

Parameters:

env (gym.Env) – The gymnasium environment.

Returns:

The value of the max_episode_steps attribute of a potentially nested

TimeLimit wrapper. If the environment is not wrapped in a TimeLimit wrapper, then this function returns None.

Return type:

int

stable_gym.common.max_episode_steps_injection_wrapper.inject_attribute_into_base_env(env, attribute_name, attribute_value)[source]

Injects the max_episode_steps argument into the base environment under the _time_limit_max_episode_steps attribute.

Parameters:
  • env (gym.Env) – The gymnasium environment.

  • attribute_name (str) – The attribute’s name to inject into the base environment.

  • attribute_value (object) – The attribute’s value to inject into the base environment.

class stable_gym.common.max_episode_steps_injection_wrapper.MaxEpisodeStepsInjectionWrapper(env)[source]

Bases: gymnasium.Wrapper

A gymnasium wrapper that injects the max_episode_steps attribute of the TimeLimit wrapper into the base environment as the _time_limit_max_episode_steps attribute. If the environment is not wrapped in a TimeLimit wrapper, then the _time_limit_max_episode_steps attribute is set to None.

Wrap a gymnasium environment. :param env: The gymnasium environment. :type env: gym.Env