multigrid.pettingzoo package#

This package provides tools for using MultiGrid environments with the PettingZoo ParallelEnv API.

Usage#

Wrap an environment instance with PettingZooWrapper:

>>> import gymnasium as gym
>>> import multigrid.envs
>>> env = gym.make('MultiGrid-Empty-8x8-v0', agents=2, render_mode='human')
>>> from multigrid.pettingzoo import PettingZooWrapper
>>> env = PettingZooWrapper(env)

Wrap an environment class with to_pettingzoo_env():

>>> from multigrid.envs import EmptyEnv
>>> from multigrid.pettingzoo import to_pettingzoo_env
>>> PZEnv = to_pettingzoo_env(EmptyEnv, metadata={'name': 'empty_v0'})
>>> env = PZEnv(agents=2, render_mode='human')
class multigrid.pettingzoo.PettingZooWrapper[source]#

Bases: ParallelEnv

Wrapper for a MultiGridEnv environment that implements the PettingZoo ParallelEnv interface.

__init__(env: MultiGridEnv)[source]#
property agents: list[int]#
property possible_agents: list[int]#
property observation_spaces: dict[int, gymnasium.spaces.space.Space]#
property action_spaces: dict[int, gymnasium.spaces.space.Space]#
observation_space(agent_id: int) Space[source]#

Takes in agent and returns the observation space for that agent.

MUST return the same value for the same agent name

Default implementation is to return the observation_spaces dict

action_space(agent_id: int) Space[source]#

Takes in agent and returns the action space for that agent.

MUST return the same value for the same agent name

Default implementation is to return the action_spaces dict

metadata: dict[str, Any]#
multigrid.pettingzoo.to_pettingzoo_env(env_cls: type[multigrid.base.MultiGridEnv], *wrappers: Wrapper, metadata: dict[str, Any] = {}) type[pettingzoo.utils.env.ParallelEnv][source]#

Convert a MultiGridEnv environment class to a PettingZoo ParallelEnv class.

Note that this is a wrapper around the environment class, not environment instances.

Parameters:
env_clstype[MultiGridEnv]

MultiGridEnv environment class

wrappersgym.Wrapper

Gym wrappers to apply to the environment

metadatadict[str, Any]

Environment metadata

Returns:
pettingzoo_env_clstype[ParallelEnv]

PettingZoo ParallelEnv environment class