Giter Club home page Giter Club logo

pogema's Introduction

Pogema logo

Partially-Observable Grid Environment for Multiple Agents

CodeFactor Downloads CI CodeQL

Partially Observable Multi-Agent Pathfinding (PO-MAPF) is a challenging problem that fundamentally differs from regular MAPF. In regular MAPF, a central controller constructs a joint plan for all agents before they start execution. However, PO-MAPF is intrinsically decentralized, and decision-making, such as planning, is interleaved with execution. At each time step, an agent receives a local observation of the environment and decides which action to take. The ultimate goal for the agents is to reach their goals while avoiding collisions with each other and the static obstacles.

POGEMA stands for Partially-Observable Grid Environment for Multiple Agents. It is a grid-based environment that was specifically designed to be flexible, tunable, and scalable. It can be tailored to a variety of PO-MAPF settings. Currently, the somewhat standard setting is supported, in which agents can move between the cardinal-adjacent cells of the grid, and each action (move or wait) takes one time step. No information sharing occurs between the agents. POGEMA can generate random maps and start/goal locations for the agents. It also accepts custom maps as input.

Installation

Just install from PyPI:

pip install pogema

Using Example

from pogema import pogema_v0, Hard8x8

env = pogema_v0(grid_config=Hard8x8())

obs, info = env.reset()

while True:
    # Using random policy to make actions
    obs, reward, terminated, truncated, info = env.step(env.sample_actions())
    env.render()
    if all(terminated) or all(truncated):
        break

Open In Colab

Environments

Config agents density num agents horizon
Easy8x8 2.2% 1 64
Normal8x8 4.5% 2 64
Hard8x8 8.9% 4 64
ExtraHard8x8 17.8% 8 64
Easy16x16 2.2% 4 128
Normal16x16 4.5% 8 128
Hard16x16 8.9% 16 128
ExtraHard16x16 17.8% 32 128
Easy32x32 2.2% 16 256
Normal32x32 4.5% 32 256
Hard32x32 8.9% 64 256
ExtraHard32x32 17.8% 128 256
Easy64x64 2.2% 64 512
Normal64x64 4.5% 128 512
Hard64x64 8.9% 256 512
ExtraHard64x64 17.8% 512 512

Baselines

The baseline implementations are available as a separate repository.

Interfaces

Pogema provides integrations with a range of MARL frameworks: PettingZoo, PyMARL and SampleFactory.

PettingZoo

from pogema import pogema_v0, GridConfig

# Create Pogema environment with PettingZoo interface
env = pogema_v0(GridConfig(integration="PettingZoo"))

PyMARL

from pogema import pogema_v0, GridConfig

env = pogema_v0(GridConfig(integration="PyMARL"))

SampleFactory

from pogema import pogema_v0, GridConfig

env = pogema_v0(GridConfig(integration="SampleFactory"))

Gymnasium

Pogema is fully capable for single-agent pathfinding tasks.

import gymnasium as gym
import pogema

# This interface provides experience only for agent with id=0,
# other agents will take random actions.
env = gym.make("Pogema-v0")

Example of training stable-baselines3 DQN to solve single-agent pathfinding tasks: Open In Colab

Customization

Random maps

from pogema import pogema_v0, GridConfig

# Define random configuration
grid_config = GridConfig(num_agents=4,  # number of agents
                         size=8, # size of the grid
                         density=0.4,  # obstacle density
                         seed=1,  # set to None for random 
                                  # obstacles, agents and targets 
                                  # positions at each reset
                         max_episode_steps=128,  # horizon
                         obs_radius=3,  # defines field of view
                         )

env = pogema_v0(grid_config=grid_config)
env.reset()
env.render()

Custom maps

from pogema import pogema_v0, GridConfig

grid = """
.....#.....
.....#.....
...........
.....#.....
.....#.....
#.####.....
.....###.##
.....#.....
.....#.....
...........
.....#.....
"""

# Define new configuration with 8 randomly placed agents
grid_config = GridConfig(map=grid, num_agents=8)

# Create custom Pogema environment
env = pogema_v0(grid_config=grid_config)

Citation

If you use this repository in your research or wish to cite it, please make a reference to our paper:

@misc{https://doi.org/10.48550/arxiv.2206.10944,
  doi = {10.48550/ARXIV.2206.10944},  
  url = {https://arxiv.org/abs/2206.10944},
  author = {Skrynnik, Alexey and Andreychuk, Anton and Yakovlev, Konstantin and Panov, Aleksandr I.},
  keywords = {Machine Learning (cs.LG), Artificial Intelligence (cs.AI), Multiagent Systems (cs.MA), FOS: Computer and information sciences, FOS: Computer and information sciences},
  title = {POGEMA: Partially Observable Grid Environment for Multiple Agents},
  publisher = {arXiv},
  year = {2022},
  copyright = {arXiv.org perpetual, non-exclusive license}
}

pogema's People

Contributors

aandreychuk avatar eles13 avatar konstantin-yakovlev avatar konstantingordeev avatar panyshevalex avatar tviskaron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pogema's Issues

Feature request: update PettingZoo version

Hi, would it be possible to update this repo to use the most recent version of PettingZoo? We want to list this project in PettingZoo's third-party-environments, but we can only include environments which work with the current version.

If you need any help working out issues due to different versions feel free to ask, there were some breaking changes in version 1.2, so it requires a bit of code changes to adapt. The previous API returned done in the step() function, whereas the new one returns truncated and terminated (matching gymnasium). There is a migration guide for gymnasium explaining the changes further, the steps should be basically the same (we're working on making resources for updating old PettingZoo repositories as well): https://gymnasium.farama.org/content/migration-guide/

Custom observation

Is it possible to generate custom observation like this?
[[obstacles in agent's FOV], [other agents in agent's FOV], [guide to destination]]

At the end I hope to implement a similar environment defined in this paper (V. B. Observation representation):
Reference of the code

Thanks a lot!

How to get the big map from the environment?

I want to plot the global map with agents though matplotlib. How can I do that? Thank you.

from pogema import pogema_v0, Hard8x8


def main():
    env = pogema_v0(grid_config=Hard8x8())
    my_map = Hard8x8()  # there is no map inside :(
    obs = env.reset()

    while True:
        # Using random policy to make actions
        obs, reward, terminated, info = env.step(env.sample_actions())
        env.render()
        if all(terminated):
            break

Unable to perform training pogema_v0 environment

I'm trying to run the below code

import gymnasium as gym
from pogema import pogema_v0, GridConfig

# Create Pogema environment with PettingZoo interface
env = gym.make("Pogema-v0", grid_config=GridConfig(size=8, density=0.3, num_agents=1, max_episode_steps=30))
from stable_baselines3 import DQN

dqn_agent = DQN('MlpPolicy', env, verbose=1, tensorboard_log="./dqn_pogema_tensorboard/")
dqn_agent.learn(1000000, log_interval=1000, eval_env=env, tb_log_name="baseline")

But it fails in the last before line and I get the following error:

AssertionError: The algorithm only supports (<class 'gym.spaces.discrete.Discrete'>,) as action spaces but Discrete(5) was provided

It appears to me that there is a confusion between gymnasium and gym since both are used in this piece of code. Not sure how to fix this error.

Example not working

installing latest version using pip and the example doesn't work - seems you still implement the gym API instead of gymnasium.
pogema version - 1.1.6

Rendering Video Issues

Hi bro,
I don't want it to be displayed on the command line. I want it to be a video of the whole pathfinding process. How do I do that? I checked render() and found there was very little I could do...

Run the algorithms

Can you provide a small example of running the baseline algorithms without docker or additional projects, please?
It is ok for me to run the learning phase by myself. I just want to keep everything as simple as possible and I want to create my own algorithms to compare with yours. Thank you in advance.

Goal positon is far away from the agent

if goal position is far away from the agent (out of the observation area), what is represented by the third layer of the observation? How can agent understand where to move?

Gym do not see pogema env.

Consider the code i took from https://pypi.org/project/pogema/1.0.1/

import gym
from pogema import GridConfig

# Define random configuration
grid_config = GridConfig(num_agents=4,  # number of agents
                         size=8, # size of the grid
                         density=0.4,  # obstacle density
                         seed=1,  # set to None for random 
                                  # obstacles, agents and targets 
                                  # positions at each reset
                         max_episode_steps=128,  # horizon
                         obs_radius=3,  # defines field of view
                         )

env = gym.make('Pogema-v0', grid_config=grid_config)
env.reset()
env.render()

I got the error:

Traceback (most recent call last):

  Cell In[5], line 15
    env = gym.make('Pogema-v0', grid_config=grid_config)

  File ~\anaconda3\envs\rl_hw5\lib\site-packages\gym\envs\registration.py:569 in make
    _check_version_exists(ns, name, version)

  File ~\anaconda3\envs\rl_hw5\lib\site-packages\gym\envs\registration.py:219 in _check_version_exists
    _check_name_exists(ns, name)

  File ~\anaconda3\envs\rl_hw5\lib\site-packages\gym\envs\registration.py:197 in _check_name_exists
    raise error.NameNotFound(

NameNotFound: Environment Pogema doesn't exist. Did you mean: `Pong`?

My environment is defined below, also inform I install gym as pip install gym[atari,accept-rom-license]

packages in environment at C:\Users\satyr\anaconda3\envs\rl_hw5:

Name Version Build Channel

abseil-cpp 20211102.0 h0e60522_0 conda-forge
absl-py 2.1.0 pyhd8ed1ab_0 conda-forge
ale-py 0.8.1 pypi_0 pypi
asttokens 2.0.5 pyhd3eb1b0_0
autorom 0.4.2 pypi_0 pypi
autorom-accept-rom-license 0.6.1 pypi_0 pypi
box2d-py 2.3.5 pypi_0 pypi
bzip2 1.0.8 h2bbff1b_5
c-ares 1.19.1 h2bbff1b_0
ca-certificates 2024.2.2 h56e8100_0 conda-forge
certifi 2024.2.2 pypi_0 pypi
charset-normalizer 3.3.2 pypi_0 pypi
click 8.1.7 pypi_0 pypi
cloudpickle 2.2.1 py310haa95532_0
colorama 0.4.6 py310haa95532_0
comm 0.2.1 py310haa95532_0
contourpy 1.2.0 pypi_0 pypi
cycler 0.12.1 pypi_0 pypi
d3rlpy 2.4.0 pypi_0 pypi
dataclasses-json 0.6.4 pypi_0 pypi
debugpy 1.6.7 py310hd77b12b_0
decorator 5.1.1 pyhd3eb1b0_0
et-xmlfile 1.1.0 pypi_0 pypi
etils 1.7.0 pypi_0 pypi
exceptiongroup 1.2.0 py310haa95532_0
executing 0.8.3 pyhd3eb1b0_0
farama-notifications 0.0.4 pypi_0 pypi
filelock 3.13.3 pypi_0 pypi
fonttools 4.50.0 pypi_0 pypi
fsspec 2024.3.1 pypi_0 pypi
glfw 2.7.0 pypi_0 pypi
grpc-cpp 1.48.2 hfe90ff0_1
grpcio 1.62.1 pypi_0 pypi
gym 0.26.2 pypi_0 pypi
gym-notices 0.0.8 pypi_0 pypi
gymnasium 0.28.1 pypi_0 pypi

h5py 3.11.0 pypi_0 pypi
idna 3.6 pypi_0 pypi
imageio 2.34.0 pypi_0 pypi
importlib-metadata 7.1.0 pyha770c72_0 conda-forge
importlib-resources 6.4.0 pypi_0 pypi
intel-openmp 2024.0.0 h57928b3_49841 conda-forge
ipykernel 6.28.0 py310haa95532_0
ipython 8.20.0 py310haa95532_0
jax-jumpy 1.0.0 pypi_0 pypi
jedi 0.18.1 py310haa95532_1
jinja2 3.1.3 pypi_0 pypi
jupyter_client 8.6.0 py310haa95532_0
jupyter_core 5.5.0 py310haa95532_0
kiwisolver 1.4.5 pypi_0 pypi
libblas 3.9.0 8_mkl conda-forge
libcblas 3.9.0 8_mkl conda-forge
libffi 3.4.4 hd77b12b_0
liblapack 3.9.0 8_mkl conda-forge
libprotobuf 3.20.3 h23ce68f_0
libsodium 1.0.18 h62dcd97_0
markdown 3.6 pyhd8ed1ab_0 conda-forge
markdown-it-py 3.0.0 pypi_0 pypi
markupsafe 2.1.5 pypi_0 pypi
marshmallow 3.21.1 pypi_0 pypi
matplotlib 3.8.3 pypi_0 pypi
matplotlib-inline 0.1.6 py310haa95532_0
mdurl 0.1.2 pypi_0 pypi
mkl 2020.4 hb70f87d_311 conda-forge
mpmath 1.3.0 pypi_0 pypi
mujoco 2.3.7 pypi_0 pypi
mypy-extensions 1.0.0 pypi_0 pypi
nest-asyncio 1.6.0 py310haa95532_0
networkx 3.2.1 pypi_0 pypi
numpy 1.26.4 pypi_0 pypi
opencv-python 4.9.0.80 pypi_0 pypi
openpyxl 3.1.2 pypi_0 pypi
openssl 3.0.13 h2bbff1b_0
packaging 23.2 py310haa95532_0
pandas 2.2.1 pypi_0 pypi
parso 0.8.3 pyhd3eb1b0_0
pillow 10.2.0 pypi_0 pypi
pip 23.3.1 py310haa95532_0
platformdirs 3.10.0 py310haa95532_0
pogema 1.2.2 pypi_0 pypi
prompt-toolkit 3.0.43 py310haa95532_0
prompt_toolkit 3.0.43 hd3eb1b0_0
protobuf 5.26.1 pypi_0 pypi
psutil 5.9.0 py310h2bbff1b_0
pure_eval 0.2.2 pyhd3eb1b0_0
pydantic 1.9.1 pypi_0 pypi
pygame 2.1.0 pypi_0 pypi
pygments 2.15.1 py310haa95532_1
pyopengl 3.1.7 pypi_0 pypi
pyparsing 3.1.2 pypi_0 pypi
python 3.10.14 he1021f5_0
python-dateutil 2.8.2 pyhd3eb1b0_0
python_abi 3.10 2_cp310 conda-forge
pytz 2024.1 pypi_0 pypi
pywin32 305 py310h2bbff1b_0
pyzmq 25.1.2 py310hd77b12b_0
re2 2022.04.01 h0e60522_0 conda-forge
requests 2.31.0 pypi_0 pypi
rich 13.7.1 pypi_0 pypi
seaborn 0.13.2 pypi_0 pypi
setuptools 68.2.2 py310haa95532_0
shimmy 1.3.0 pypi_0 pypi
six 1.16.0 pyhd3eb1b0_1
spyder-kernels 2.4.4 py310haa95532_0
sqlite 3.41.2 h2bbff1b_0
stable-baselines3 2.3.0 pypi_0 pypi
stack_data 0.2.0 pyhd3eb1b0_0
structlog 24.1.0 pypi_0 pypi
swig 4.2.1 pypi_0 pypi
sympy 1.12 pypi_0 pypi
tabulate 0.9.0 pypi_0 pypi
tensorboard 2.16.2 pyhd8ed1ab_0 conda-forge
tensorboard-data-server 0.7.2 pypi_0 pypi
tk 8.6.12 h2bbff1b_0
torch 2.2.2 pypi_0 pypi
tornado 6.3.3 py310h2bbff1b_0
tqdm 4.66.2 pypi_0 pypi
traitlets 5.7.1 py310haa95532_0
typing-extensions 4.10.0 pypi_0 pypi
typing-inspect 0.9.0 pypi_0 pypi
tzdata 2024.1 pypi_0 pypi
urllib3 2.2.1 pypi_0 pypi
vc 14.2 h21ff451_1
vs2015_runtime 14.27.29016 h5e58377_2
wcwidth 0.2.5 pyhd3eb1b0_0
werkzeug 3.0.1 pyhd8ed1ab_0 conda-forge
wheel 0.41.2 py310haa95532_0
xz 5.4.6 h8cc25b3_0
zeromq 4.3.5 hd77b12b_0
zipp 3.18.1 pypi_0 pypi
zlib 1.2.13 h8cc25b3_0

The example in README.md is incorrect

  • the env.reset() returns only obs (without info)
  • the env.step() returns obs, reward, terminated, info and not obs, reward, terminated, truncated, info
from pogema import pogema_v0, Hard8x8


def main():
    env = pogema_v0(grid_config=Hard8x8())
    obs = env.reset()  # here

    while True:
        # Using random policy to make actions
        obs, reward, terminated, info = env.step(env.sample_actions())  # and here
        env.render()
        if all(terminated):
            break


if __name__ == '__main__':
    main()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.