Action Wrappers

posggym.ActionWrapper

class posggym.ActionWrapper(env: Env[StateType, ObsType, ActType])

Wraps environment to allow modular transformations of actions.

Subclasses should at least implement the actions function.

actions(actions: Dict[str, ActType]) Dict[str, WrapperActType]

Transform actions for wrapped environment.

Available Action Wrappers

class posggym.wrappers.DiscretizeActions(env: Env, num_actions: int, flatten: bool = False)

Action wrapper that discretizes continuous action space.

The base environment env must have an action space of type spaces.Box for each agent. If flatten is True and original action space is multi-dimensional with ndim dimensions, then will create discretized space with num_actions ** ndim actions.

Parameters:
  • env (posggym.Env) – The environment to apply the wrapper

  • num_actions (int) – The number of actions to discretize space into. For multi-dimensional continuous spaces each dimension will be discretized into this many actions.

  • flatten (bool) – Whether to flatten action space into one-dimensional discrete space, or keep number of dimensions of the original action space.

class posggym.wrappers.RescaleActions(env: Env, min_action: float | int | ndarray | Dict[str, float | int | ndarray], max_action: float | int | ndarray | Dict[str, float | int | ndarray])

Action wrapper that rescales continuous action space.

Rescales actions from [min, max] range to the action space range of the environment.

The base environment env must have an action space of type spaces.Box for each agent. If min_action or max_action are numpy arrays, the shape must match the shape of the environment’s action space for the given agent. If min_action or max_action are dictionaries then they must have an entry for each possible agent ID in the wrapped environment.

Parameters:
  • env (posggym.Env) – The environment to apply the wrapper

  • min_action (float, int, np.ndarray, Dict[str, Union[float, int, np.ndarray]]) – The minimum value for the scaled actions.

  • max_action (float, int, np.ndarray, Dict[str, Union[float, int, np.ndarray]]) – The maximum value for the scaled actions.

Note

Explanation of how to scale number from one interval into new interval: https://stats.stackexchange.com/questions/281162/scale-a-number-between-a-range

Implementation also based on similar wrapper from gymnasium: https://github.com/Farama-Foundation/Gymnasium/blob/v0.27.0/gymnasium/wrappers/rescale_action.py