Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Farama Foundation Gymnasium Vector Action Wrappers

From Leeroopedia
Knowledge Sources
Domains Reinforcement_Learning, Wrappers
Last Updated 2026-02-15 03:00 GMT

Overview

A collection of vectorized action wrappers that transform actions for VectorEnv environments, including TransformAction, VectorizeTransformAction, ClipAction, and RescaleAction.

Description

This module provides vectorized versions of action transformation wrappers:

  • TransformAction -- Applies a user-provided function to the entire action vector at once. Accepts optional action_space and single_action_space parameters for specifying the transformed spaces. Best used when vector-level parallel processing of actions is possible.
  • VectorizeTransformAction -- Wraps a single-agent action wrapper to work with vector environments by iterating over individual actions and applying the wrapper's transform. Uses a fake _SingleEnv internally. Serves as the base class for ClipAction and RescaleAction.
  • ClipAction -- Clips continuous actions to the environment's action space bounds. A thin wrapper around VectorizeTransformAction using the single-agent ClipAction wrapper.
  • RescaleAction -- Affinely rescales the continuous action space to a new range [min_action, max_action]. A thin wrapper around VectorizeTransformAction using the single-agent RescaleAction wrapper.

Usage

Use these wrappers to transform actions in vectorized environments. ClipAction is commonly used to ensure valid actions, and RescaleAction is used to normalize action ranges. Use TransformAction for custom vector-level action transforms.

Code Reference

Source Location

Signature

class TransformAction(VectorActionWrapper):
    def __init__(self, env: VectorEnv, func: Callable[[ActType], Any],
                 action_space: Space | None = None, single_action_space: Space | None = None): ...

class VectorizeTransformAction(VectorActionWrapper):
    def __init__(self, env: VectorEnv, wrapper: type[transform_action.TransformAction], **kwargs: Any): ...

class ClipAction(VectorizeTransformAction):
    def __init__(self, env: VectorEnv): ...

class RescaleAction(VectorizeTransformAction):
    def __init__(self, env: VectorEnv, min_action: float | int | np.ndarray, max_action: float | int | np.ndarray): ...

Import

from gymnasium.wrappers.vector import TransformAction, VectorizeTransformAction, ClipAction, RescaleAction

I/O Contract

Inputs

Name Type Required Description
env VectorEnv Yes The vector environment to wrap
func Callable Yes (TransformAction) Function to transform the action vector
action_space Space or None No New action space for the wrapper
single_action_space Space or None No Action space for a single sub-environment
min_action float, int, or ndarray Yes (RescaleAction) Minimum values for rescaled action space
max_action float, int, or ndarray Yes (RescaleAction) Maximum values for rescaled action space

Outputs

Name Type Description
actions ActType Transformed actions passed to the underlying vector environment

Usage Examples

import numpy as np
import gymnasium as gym
from gymnasium.wrappers.vector import ClipAction, RescaleAction

# ClipAction: clip out-of-bounds actions
envs = gym.make_vec("MountainCarContinuous-v0", num_envs=3)
envs = ClipAction(envs)
obs, info = envs.reset(seed=123)
obs, rew, term, trunc, info = envs.step(np.array([5.0, -5.0, 2.0]))
envs.close()

# RescaleAction: rescale actions to [0, 1]
envs = gym.make_vec("MountainCarContinuous-v0", num_envs=3)
envs = RescaleAction(envs, 0.0, 1.0)
_ = envs.action_space.seed(123)
obs, info = envs.reset(seed=123)
for _ in range(10):
    obs, rew, term, trunc, info = envs.step(0.5 * np.ones((3, 1)))
envs.close()

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment