GymnasiumPufferEnv
Wraps Gymnasium environments to work with PufferLib’s training infrastructure.Constructor
An existing Gymnasium environment instance. Mutually exclusive with
env_creator.A callable that creates a Gymnasium environment. Mutually exclusive with
env.Positional arguments to pass to
env_creator.Keyword arguments to pass to
env_creator.Optional buffer dictionary containing pre-allocated arrays for observations, rewards, terminals, truncations, masks, and actions.
Random seed for the environment.
Properties
The emulated observation space (flattened to Box if needed).
The emulated action space (converted to MultiDiscrete if needed).
Same as
observation_space for single-agent environments.Same as
action_space for single-agent environments.Always 1 for Gymnasium environments.
The render mode of the wrapped environment.
Dictionary containing emulation metadata:
observation_dtype: The flattened observation dtypeemulated_observation_dtype: The structured observation dtype
Methods
reset
Optional random seed for the reset.
The initial observation in emulated format.
Additional information from the environment.
step
The action to execute in emulated format.
The observation after taking the action.
The reward received.
Whether the episode terminated naturally.
Whether the episode was truncated (e.g., time limit).
Additional information from the environment.
render
close
seed
The random seed.
PettingZooPufferEnv
Wraps PettingZoo parallel environments to work with PufferLib’s training infrastructure.Constructor
An existing PettingZoo parallel environment instance. Mutually exclusive with
env_creator.A callable that creates a PettingZoo parallel environment. Mutually exclusive with
env.Positional arguments to pass to
env_creator.Keyword arguments to pass to
env_creator.Optional buffer dictionary containing pre-allocated arrays for observations, rewards, terminals, truncations, masks, and actions.
Random seed for the environment.
Properties
The emulated observation space for a single agent.
The emulated action space for a single agent.
Number of agents in the environment.
List of currently active agent IDs.
List of all possible agent IDs.
The render mode of the wrapped environment.
Whether all agents are done.
Dictionary containing emulation metadata:
observation_dtype: The flattened observation dtypeemulated_observation_dtype: The structured observation dtype
Methods
observation_space
The agent ID.
action_space
The agent ID.
reset
Optional random seed for the reset.
Dictionary mapping agent IDs to their observations in emulated format.
Dictionary mapping agent IDs to their info dicts.
step
Either a dictionary mapping agent IDs to actions, or a numpy array with actions for all agents in order.
Dictionary mapping agent IDs to their observations.
Dictionary mapping agent IDs to their rewards.
Dictionary mapping agent IDs to terminal flags.
Dictionary mapping agent IDs to truncation flags.
Dictionary mapping agent IDs to their info dicts.
render
close
Utility functions
emulate_observation_space
The original observation space (can be Box, Tuple, Dict, etc.).
A flat Box space that can hold the original observations.
Structured dtype for converting between flat and structured representations.
emulate_action_space
The original action space.
MultiDiscrete space for complex spaces, or the original for Box/Discrete.
Structured dtype for converting between representations.
dtype_from_space
The space to convert.
flatten_space
The space to flatten.
emulate
Structured numpy array view to write into.
Sample from the original space (dict, tuple, or array).
nativize
Flat array in emulated format.
The original space.
Structured dtype for conversion.
make_object
Existing object instance. Mutually exclusive with
object_creator.Callable that creates the object. Mutually exclusive with
object_instance.Positional arguments for
object_creator.Keyword arguments for
object_creator.