GAMA-PettingZoo is a generic PettingZoo environment that enables the integration of simulations from the GAMA modeling platform with multi-agent reinforcement learning algorithms.
This library allows researchers and developers to easily use GAMA models as multi-agent reinforcement learning environments, leveraging the power of GAMA for agent-based modeling and the Python ecosystem for AI.
pip install gama-pettingzoo- GAMA Platform: Install GAMA from gama-platform.org
- Python 3.8+ with required dependencies
pip install pettingzoo gama-gymnasium numpyfrom gama_pettingzoo.gama_parallel_env import GamaParallelEnv
# Create the environment
env = GamaParallelEnv(
gaml_experiment_path='your_model.gaml',
gaml_experiment_name='main',
gama_ip_address='localhost',
gama_port=1001
)
# Use as a standard PettingZoo environment
observations, infos = env.reset()
for agent in env.agent_iter():
observation, reward, termination, truncation, info = env.last()
action = policy(observation, agent) # Your policy
env.step(action)The GamaMultiAgent is a GAMA agent required in the model to enable interaction between the simulation's learning agents and the PettingZoo environment. It has specialized variables and actions for multi-agent management.
Structure of the agent:
species GamaMultiAgent {
map<string, unknown> action_spaces;
map<string, unknown> observation_spaces;
list<string> agents_list;
map<string, unknown> states;
map<string, float> rewards;
map<string, bool> terminated;
map<string, bool> truncated;
map<string, unknown> infos;
map<string, unknown> next_actions;
map<string, unknown> data;
action update_data {
data <- [
"States"::states,
"Rewards"::rewards,
"Terminated"::terminated,
"Truncated"::truncated,
"Infos"::infos,
"Agents"::agents_list
];
}
}
-
Add the GAMA component to your model: Make sure you have added the species
GamaMultiAgentdescribed above to your model:species GamaMultiAgent;Set up the
action_spacesandobservation_spaces:global { init { create GamaMultiAgent { agents_list <- ["prisoner", "guard"]; action_spaces <- [ "prisoner"::["type"::"Discrete", "n"::4], "guard"::["type"::"Discrete", "n"::4] ]; observation_spaces <- [ "prisoner"::["type"::"Box", "low"::0, "high"::grid_size, "shape"::[2], "dtype"::"int"], "guard"::["type"::"Box", "low"::0, "high"::grid_size, "shape"::[2], "dtype"::"int"] ]; } } }Update the multi-agent's data after actions are completed:
ask GamaMultiAgent[0] { do update_data; } -
Launch GAMA in server mode:
# Linux/MacOS
./gama-headless.sh -socket 1001
# Windows
gama-headless.bat -socket 1001gama-pettingzoo/
โโโ ๐ src/ # Main Python package source code
โโโ ๐ tests/ # Comprehensive test suite
โโโ ๐ examples/ # Complete examples and tutorials
โ โโโ ๐ Moving Exemple/ # Basic movement example
โ โโโ ๐ Pac Man/ # Multi-agent Pac-Man game
โ โโโ ๐ Prison Escape/ # Prison escape environment
โโโ ๐ improved_trained_models/ # Advanced trained models
โโโ ๐ simple_trained_models/ # Basic trained models
โโโ pyproject.toml # Python package configuration
โโโ pytest.ini # Testing configuration
โโโ LICENSE # Package license
โโโ README.md # This documentation
| Example | Description | Documentation |
|---|---|---|
| Moving Exemple | Introduction to mobile agents | ๐ README |
| Pac Man | Multi-agent implementation of Pac-Man game | ๐ README |
| Prison Escape | Prison escape environment (guard vs prisoner) | ๐ README |
- Moving Exemple Guide: Complete tutorial for creating your first multi-agent environment
- Prison Escape Guide: Escape environment with antagonist agents
- Source Code Documentation: Technical documentation of the package structure
- Testing Guide: Comprehensive testing framework and best practices
git clone https://github.com/gama-platform/gama-pettingzoo.git
cd gama-pettingzoo
pip install -e src/pip install -e ".[dev]" # For development
pip install -e ".[examples]" # For examples# Run tests
pytest
# With coverage
pytest --cov=gama_pettingzoo --cov-report=html
# Multi-agent specific tests
pytest -m multiagentGAMA-PettingZoo supports all multi-agent reinforcement learning algorithms compatible with PettingZoo:
- Multi-Agent Q-Learning
- Independent Deep Q-Networks (DQN)
- Multi-Agent Deep Deterministic Policy Gradient (MADDPG)
- Multi-Agent Proximal Policy Optimization (PPO)
- And many more...
An escape environment where a prisoner attempts to escape while a guard tries to stop them.
- Agents:
prisoner,guard - Action Space: Discrete (4 directions)
- Observation Space: Agent positions on the grid
Multi-agent version of the famous Pac-Man game.
- Agents:
pacman,ghost1,ghost2, ... - Objective: Cooperation/competition in collecting points
Simple environment for learning the basics of mobile agents.
- Agents: Configurable
- Objective: Navigation and coordination
Contributions are welcome! Check the issues to see how you can help.
# Clone the repository
git clone https://github.com/gama-platform/gama-pettingzoo.git
cd gama-pettingzoo
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
# Code formatting
black src/ examples/ tests/
isort src/ examples/ tests/For more technical details and practical examples, check the documentation in the examples/ and src/ folders, or explore our comprehensive testing framework.