Skip to main content

A Gymnasium environment for reinforcement learning with GAMA agent-based simulations

Project description

GAMA-Gymnasium

Python Package License

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

🎯 Purpose

This library allows researchers and developers to easily use GAMA models as reinforcement learning environments, leveraging the power of GAMA for agent-based modeling and the Python ecosystem for AI.

⚡ Quick Start

Installation

pip install gama-gymnasium

Prerequisites

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

Basic Usage

import gama_gymnasium
import gymnasium as gym

# Create the environment
env = gym.make('gama-gymnasium-v0', 
               gama_model_path='your_model.gaml',
               gama_port=6868)

# Use as a standard Gymnasium environment
obs, info = env.reset()
for _ in range(100):
    action = env.action_space.sample()
    obs, reward, terminated, truncated, info = env.step(action)
    if terminated or truncated:
        obs, info = env.reset()

GymAgent

The GymAgent is a GAMA agent that is required in the model to enable interaction between the simulation's learning agent and the Gymnasium environment. It has nine variables and one action. The GymAgent is a GAMA agent required in the model to allow the interaction between the learning agent of the simulation and Gymnasium environments. It have 9 variables and 1 action

Structure of the agent:

species GymAgent{
	map<string, unknown> action_space;
	map<string, unknown> observation_space;

	unknown state;
	float reward;
	bool terminated;
	bool truncated;
	map<string, unknown> info;

	unknown next_action;

	map<string, unknown> data;

	action update_data {
		data <- [
			"State"::state,
			"Reward"::reward,
			"Terminated"::terminated,
			"Truncated"::truncated,
			"Info"::info
		];
	}
}

GAMA Configuration

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

    species GymAgent;
    

    Set up the action_space and observation_space:

    global {
        init{
            create GymAgent{
              action_space <- ["type"::"Discrete", "n"::4];
              observation_space <- ["type"::"Box", "low"::0, "high"::grid_size, "shape"::[2], "dtype"::"int"];
            }
        }
    }
    

    Update the gym agent's data after the action is completed:

    ask GymAgent[0] {
        do update_data;
    }
    
  2. Launch GAMA in server mode:

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

# Windows
gama-headless.bat -socket 6868

📁 Project Structure

gama-gymnasium/
├── 📁 src/               # Main Python package source code
├── 📁 tests/             # Comprehensive test suite
├── 📁 examples/          # Complete examples and tutorials
├── pyproject.toml	      # Python package configuration
├── LICENSE               # Package license
└── pytest.ini            # Testing configuration

📚 Documentation and Examples

🚀 Tutorials and Examples

Example Description Documentation
Basic Example Introduction to GAMA-Gymnasium integration 📖 README
CartPole DQN Deep Q-Network implementation on CartPole environment 📖 README
Frozen Lake Q-Learning An example of Q-Learning purely in gama

📖 Detailed Guides

🛠 Advanced Installation

From Source Code

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

🧪 Testing and Validation

# Run tests
python tests/test_manager.py --quick

🤝 Contributing

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

🔗 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_gymnasium-1.0.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

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

gama_gymnasium-1.0.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file gama_gymnasium-1.0.0.tar.gz.

File metadata

  • Download URL: gama_gymnasium-1.0.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for gama_gymnasium-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3c9b473d13ea9115b25619765b4acffe9253d02d0a471a0f07830ca191593cf6
MD5 1f65191776232eaaed77e48f1e2162d0
BLAKE2b-256 113c92a32871400341e7e6dc1ad1d8d5f280e9f143e042b7951f67d03d6b7d3f

See more details on using hashes here.

File details

Details for the file gama_gymnasium-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: gama_gymnasium-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for gama_gymnasium-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8afeaee75d35fde816e888e5c2db1b52de9e9488c0bb1589f12354e743f8cd9
MD5 c13cd687769c2dd9c64d55d7a99a6afd
BLAKE2b-256 c817c1b4012753636c0e4ac5dcebd7326b402de21a4488088b85a12cf27ff66b

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