Skip to main content
Version: 🚧 Alpha 🚧

14. Connect a parallel environment

The GAMA-PettingZoo README lists its Python requirements and shows a GAMA socket server on port 1001. Start the server with the command for your operating system, then configure the Python client to use the same host and port:

gama-headless.bat -socket 1001

On Linux or macOS, use gama-headless.sh -socket 1001. The GamaParallelEnv constructor defaults to port 6868; when the server uses 1001, pass that port explicitly as shown below. The package README lists Python 3.10–3.12; check its pinned dependency information when setting up an environment.

Create the environment​

The constructor takes a GAML file path and experiment name. This example assumes that the model defines the PetzAgent interface from the previous step and that GAMA is listening on the selected socket:

from gama_pettingzoo.gama_parallel_env import GamaParallelEnv

env = GamaParallelEnv(
gaml_experiment_path="path/to/model.gaml",
gaml_experiment_name="main",
gama_ip_address="localhost",
gama_port=1001,
)
observations, infos = env.reset()

Use the observations to build one action per active agent, then send them together in one step call:

actions = {
agent_id: policy(agent_id, observation)
for agent_id, observation in observations.items()
}
observations, rewards, terminations, truncations, infos = env.step(actions)

Repeat with the observations from each step and close the environment when finished. This uses the package's ParallelEnv interface; its README quick-start also shows agent_iter() and last(), which are methods of PettingZoo's AEC interaction pattern and do not match the GamaParallelEnv class. The wrapper's implementation defines the parallel reset and step results.