Skip to main content

A PettingZoo environment for multi-agent reinforcement learning with GAMA agent-based simulations

Project description

GAMA-PettingZoo

Python Package License

GAMA-PettingZoo is a generic PettingZoo environment that enables the integration of simulations from the GAMA modeling platform with multi-agent reinforcement learning algorithms.

๐ŸŽฏ Purpose

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.

โšก Quick Start

Installation

pip install gama-pettingzoo

Prerequisites

  • GAMA Platform: Install GAMA from gama-platform.org
  • Python 3.8+ with required dependencies
pip install pettingzoo gama-gymnasium numpy

Basic Usage

from 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)

GamaMultiAgent

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
        ];
    }
}

GAMA Configuration

  1. Add the GAMA component to your model: Make sure you have added the species GamaMultiAgent described above to your model:

    species GamaMultiAgent;
    

    Set up the action_spaces and observation_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;
    }
    
  2. Launch GAMA in server mode:

# Linux/MacOS
./gama-headless.sh -socket 1001

# Windows
gama-headless.bat -socket 1001

๐Ÿ“ Project Structure

gama-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

๐Ÿ“š Documentation and Examples

๐Ÿš€ Tutorials and Examples

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

๐Ÿ“– Detailed Guides

๐Ÿ›  Advanced Installation

From Source Code

git clone https://github.com/gama-platform/gama-pettingzoo.git
cd gama-pettingzoo
pip install -e src/

Development Dependencies

pip install -e ".[dev]"      # For development
pip install -e ".[examples]"  # For examples

๐Ÿงช Testing and Validation

# Run tests
pytest

# With coverage
pytest --cov=gama_pettingzoo --cov-report=html

# Multi-agent specific tests
pytest -m multiagent

๐Ÿค– Supported Algorithms

GAMA-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...

๐ŸŽฎ Available Environments

Prison Escape

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

Pac Man Multi-Agent

Multi-agent version of the famous Pac-Man game.

  • Agents: pacman, ghost1, ghost2, ...
  • Objective: Cooperation/competition in collecting points

Moving Exemple

Simple environment for learning the basics of mobile agents.

  • Agents: Configurable
  • Objective: Navigation and coordination

๐Ÿค Contributing

Contributions are welcome! Check the issues to see how you can help.

Development

# 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/

๐Ÿ”— Useful Links


For more technical details and practical examples, check the documentation in the examples/ and src/ folders, or explore our comprehensive testing framework.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gama_pettingzoo-0.1.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gama_pettingzoo-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file gama_pettingzoo-0.1.0.tar.gz.

File metadata

  • Download URL: gama_pettingzoo-0.1.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.11

File hashes

Hashes for gama_pettingzoo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9499fcd0994c5f73a6ae49ecb87ef3563f5b69494080b8a60eab8a417095deac
MD5 f85fd63e29a4fc5bef22f645ee563e39
BLAKE2b-256 a77537848412422c3eed9f6171402e31f04c6ab20efa6f319dcf11653792bfcc

See more details on using hashes here.

File details

Details for the file gama_pettingzoo-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for gama_pettingzoo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d5d77eef01a974e7ee35eb0ef02334815d7c00ae336cb1851ef070c9cd2d1f88
MD5 04ca412fa935d85cd7c5f3577bbdc29c
BLAKE2b-256 3df3fcd8e23762626f703643e86b60d95b64a4beb9acbbd1b923aea55ff44a86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page