Misc Wrappers
- class posggym.wrappers.PassiveEnvChecker(env: Env)
A passive environment checker wrapper.
Surrounds the step, reset and render functions to check that they follow the posggym environment and model APIs.
- Parameters:
env (posggym.Env) – The environment to apply the wrapper
Note
This implementation is based on the similar Gymnasium wrapper: https://github.com/Farama-Foundation/Gymnasium/blob/v0.27.0/gymnasium/wrappers/env_checker.py
- class posggym.wrappers.OrderEnforcing(env: Env, disable_render_order_enforcing: bool = False)
Wraps environment to enforce environment is reset before stepped.
Will produce an error if
step()is called before an initialreset().- Parameters:
env (posggym.Env) – The environment to apply the wrapper
disable_render_order_enforcing (bool) – Whether to disable enforcing of reset before render is called or not.
Note
This implementation is based on the similar Gymnasium wrapper: https://github.com/Farama-Foundation/Gymnasium/blob/v0.27.0/gymnasium/wrappers/order_enforcing.py
- class posggym.wrappers.RecordVideo(env: Env, video_folder: str, episode_trigger: Callable[[int], bool] | None = None, step_trigger: Callable[[int], bool] | None = None, video_length: int = 0, name_prefix: str = 'posggym-video', disable_logger: bool = False, resize: int | None = None)
Wrapper for recording videos of rollouts.
- Parameters:
env (posggym.Env) – The environment that will be wrapped
video_folder (str) – The folder where the recordings will be stored
episode_trigger (Optional[Callable[[int], bool]]) – Function that accepts an integer and returns
Trueiff a recording should be started at this episodestep_trigger (Optional[Callable[[int], bool]]) – Function that accepts an integer and returns
Trueiff a recording should be started at this stepvideo_length (int) – The length of recorded episodes. If 0, entire episodes are recorded. Otherwise, snippets of the specified length are captured
name_prefix (str, optional) – Will be prepended to the filename of the recordings
disable_logger (bool) – Whether to disable moviepy logger or not.
resize (Optional[int]) – If not None, resize the video to the given dimensions (will resize the width to given number of pixels with the height computed automatically to conserve the width/height dimension).
Note
This implementation is based on the gymnasium.wrappers.RecordVideo (version gymnasium 0.27) wrapper, adapted here to work with posggym’s multiagent environment: https://github.com/Farama-Foundation/Gymnasium/blob/v0.27.0/gymnasium/wrappers/record_video.py
- class posggym.wrappers.TimeLimit(env: Env, max_episode_steps: int | None = None)
Wraps environment to enforce environment time limit.
This wrapper will issue a truncated signal in the
step()method for any agents that have not already reached a terminal state by the time a maximum number of timesteps is exceeded. It will also signal that the episode is done for all agents.- Parameters:
env (posggym.Env) – The environment to apply the wrapper
max_episode_steps (int, optional) – The maximum length of episode before it is truncated. If None then will not truncate episodes.
Note
This implementation is based on the similar Gymnasium wrapper: https://github.com/Farama-Foundation/Gymnasium/blob/v0.27.0/gymnasium/wrappers/time_limit.py