Giter Site home page Giter Site logo

semitable / robotic-warehouse Goto Github PK

View Code? Open in Web Editor NEW
250.0 5.0 65.0 2.43 MB

Multi-Robot Warehouse (RWARE): A multi-agent reinforcement learning environment

License: MIT License

Python 100.00%
reinforcement-learning robotics simulation environment multi-agent-systems multi-agent-reinforcement-learning multi-agent

robotic-warehouse's Introduction

Multi-Robot Warehouse (RWARE)

A multi-agent reinforcement learning environment

Maintenance GitHub license

Table of Contents

Environment Description

The multi-robot warehouse (RWARE) environment simulates a warehouse with robots moving and delivering requested goods. The simulator is inspired by real-world applications, in which robots pick-up shelves and deliver them to a workstation. Humans access the content of a shelf, and then robots can return them to empty shelf locations.

The environment is configurable: it allows for different sizes (difficulty), number of agents, communication capabilities, and reward settings (cooperative/individual). Of course, the parameters used in each experiment must be clearly reported to allow for fair comparisons between algorithms.

What does it look like?

Below is an illustration of a small (10x20) warehouse with four trained agents. Agents have been trained with the SEAC algorithm [2]. This visualisation can be achieved using the env.render() function as described later.

Multi-Robot Warehouse (RWARE) illustration

Action Space

In this simulation, robots have the following discrete action space:

A={ Turn Left, Turn Right, Forward, Load/Unload Shelf }

The first three actions allow each robot only to rotate and move forward. Loading/Unloading only works when an agent is beneath a shelf on one of the predesignated locations.

Observation Space

The observation of an agent is partially observable and consists of a 3x3 (configurable) square centred on the agent. Inside this limited grid, all entities are observable:

  • The location, the rotation and whether the agent is carrying a shelf.
  • The location and rotation of other robots.
  • Shelves and whether they are currently in the request queue.

Dynamics: Collisions

The dynamics of the environment are also of particular interest. Like a real, 3-dimensional warehouse, the robots can move beneath the shelves. Of course, when the robots are loaded, they must use the corridors, avoiding any standing shelves.

Any collisions are resolved in a way that allows for maximum mobility. When two or more agents attempt to move to the same location, we prioritise the one that also blocks others. Otherwise, the selection is done arbitrarily. The visuals below demonstrate the resolution of various collisions.

Example 1 Example 2 Example 3

Rewards

At each time a set number of shelves R is requested. When a requested shelf is brought to a goal location, another shelf is uniformly sampled and added to the current requests. Agents are rewarded for successfully delivering a requested shelf to a goal location, with a reward of 1. A significant challenge in these environments is for agents to deliver requested shelves but also finding an empty location to return the previously delivered shelf. Having multiple steps between deliveries leads a very sparse reward signal.

Environment Parameters

The multi-robot warehouse task is parameterised by:

  • The size of the warehouse which is preset to either tiny (10x11), small (10x20), medium (16x20), or large (16x29).
  • The number of agents N.
  • The number of requested shelves R. By default R=N, but easy and hard variations of the environment use R = 2N and R = N/2, respectively.

Note that R directly affects the difficulty of the environment. A small R, especially on a larger grid, dramatically affects the sparsity of the reward and thus exploration: randomly bringing the correct shelf becomes increasingly improbable.

Naming Scheme

While RWARE allows fine tuning of multiple parameters when using the Warehouse class, it also registers multiple default environments with Gym for simplicity.

The registered names look like rware-tiny-2ag-v1 and might cryptic in the beginning, but it is not actually complicated. Every name always starts with rware. Next, the map size is appended as -tiny, -small, -medium, or -large. The number of robots in the map is selected as Xag with X being a number larger than one (e.g. -4ag for 4 agents). A difficulty modifier is optionally appended in the form of -easy or -hard, making requested shelves twice or half the number of agents (see section Rewards). Finally -v1 is the version as required by OpenAI Gym. In the time of writing all environments are v1, but we will increase it during changes or bugfixes.

A few examples:

env = gym.make("rware-tiny-2ag-v1")
env = gym.make("rware-small-4ag-v1")
env = gym.make("rware-medium-6ag-hard-v1")

Of course, more settings are available, but have to be changed during environment creation. For example:

env = gym.make("rware-tiny-2ag-v1", sensor_range=3, request_queue_size=6)

Custom layout

You can design a custom warehouse layout with the following:

layout = """
.......
...x...
..x.x..
.x...x.
..x.x..
...x...
.g...g.
"""
gym = env.make("rware:rware-tiny-2ag-v1", layout=layout)

This will transform "X"s to shelves and "G"s to goal locations with a result like the one below:

Multi-Robot Warehouse (RWARE) illustration

A detailed explanation of all parameters can be found here

Installation

Assuming you have Python3 (preferably on a virtual environment: venv or Anaconda) installed, you can use PyPI:

pip install rware

If you prefer to have the code available and be able to edit it, you can use Git to download and install it:

git clone [email protected]:uoe-agents/robotic-warehouse.git
cd robotic-warehouse
pip install -e .

Getting Started

RWARE was designed to be compatible with Open AI's Gym framework.

Creating the environment is done exactly as one would create a Gym environment:

import gym
import rware
env = gym.make("rware-tiny-2ag-v1")

You can even bypass the import statement with Gym, and directly use:

import gym
env = gym.make("rware:rware-tiny-2ag-v1")

The rware: in the beginning of the environment name tells Gym to import the respective package.

The number of agents, the observation space, and the action space are accessed using:

env.n_agents  # 2
env.action_space  # Tuple(Discrete(5), Discrete(5))
env.observation_space  # Tuple(Box(XX,), Box(XX,))

The returned spaces are from the Gym library (gym.spaces) Each element of the tuple corresponds to an agent, meaning that len(env.action_space) == env.n_agents and len(env.observation_space) == env.n_agents are always true.

The reset and step functions again are identical to Gym:

obs = env.reset()  # a tuple of observations

actions = env.action_space.sample()  # the action space can be sampled
print(actions)  # (1, 0)
n_obs, reward, done, info = env.step(actions)

print(done)    # [False, False]
print(reward)  # [0.0, 0.0]

which leaves as to the only difference with Gym: the rewards and the done flag are lists, and each element corresponds to the respective agent.

Finally, the environment can be rendered for debugging purposes:

env.render()

and should be closed before terminating:

env.close()

Please Cite

If you use this environment, consider citing

  1. A comperative evaluation of MARL algorithms that includes this environment
@inproceedings{papoudakis2021benchmarking,
   title={Benchmarking Multi-Agent Deep Reinforcement Learning Algorithms in Cooperative Tasks},
   author={Georgios Papoudakis and Filippos Christianos and Lukas Schäfer and Stefano V. Albrecht},
   booktitle = {Proceedings of the Neural Information Processing Systems Track on Datasets and Benchmarks (NeurIPS)},
   year={2021},
   url = {http://arxiv.org/abs/2006.07869},
   openreview = {https://openreview.net/forum?id=cIrPX-Sn5n},
   code = {https://github.com/uoe-agents/epymarl},
}
  1. A method that achieves state-of-the-art performance in the robotic warehouse task
@inproceedings{christianos2020shared,
 author = {Christianos, Filippos and Sch\"{a}fer, Lukas and Albrecht, Stefano},
 booktitle = {Advances in Neural Information Processing Systems},
 editor = {H. Larochelle and M. Ranzato and R. Hadsell and M. F. Balcan and H. Lin},
 pages = {10707--10717},
 publisher = {Curran Associates, Inc.},
 title = {Shared Experience Actor-Critic for Multi-Agent Reinforcement Learning},
 url = {https://proceedings.neurips.cc/paper/2020/file/7967cc8e3ab559e68cc944c44b1cf3e8-Paper.pdf},
 volume = {33},
 year = {2020}
}

robotic-warehouse's People

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

robotic-warehouse's Issues

PettingZoo Compatibility

Hello,

We (@mobius-logic) are looking into using robotic warehouse as a manageable open-ended learning environment, since it seems highly customizable and is computationally efficient. However, since this work predates the PettingZoo interface, we're having difficulty adapting it to our needs. Are there any plans to update robotic warehouse for PettingZoo compatibility? We're happy to help with that, or take over the conversion ourselves if there's no interest.

Ask about gym version maintenance update compatibility issues

First of all, thank you for developing and maintaining the environment.

I noticed that the current version supports up to gym==0.21. I am interested in knowing whether there are any plans to update the environment for compatibility with newer versions of Gym. Keeping up with the latest versions would be beneficial for integrating with other tools and libraries that depend on newer Gym features.

Could you please share any information on potential updates or the maintenance plan for the environment? Any timeline or roadmap you could provide would be greatly appreciated.

Thank you very much for your time and assistance.

Cannot run the basic program

Is this bug or I do something wrong?
The code from your README.md file..

import gym
import rware
env = gym.make("rware-tiny-2ag-v1")
obs = env.reset()  # a tuple of observations

actions = env.action_space.sample()  # the action space can be sampled
print(actions)  # (1, 0)
n_obs, reward, done, info = env.step(actions)

print(done)    # [False, False]
print(reward)  # [0.0, 0.0]
env.render()

The output:

Traceback (most recent call last):
  File "/Users/perchik/PycharmProjects/Try_OpenAI_GYM/main.py", line 3, in <module>
    env = gym.make("rware-tiny-2ag-v1")
  File "/Users/perchik/opt/anaconda3/envs/Try_OpenAI_GYM/lib/python3.10/site-packages/gym/envs/registration.py", line 662, in make
    env = env_creator(**_kwargs)
  File "/Users/perchik/opt/anaconda3/envs/Try_OpenAI_GYM/lib/python3.10/site-packages/rware/warehouse.py", line 247, in __init__
    self._use_slow_obs()
  File "/Users/perchik/opt/anaconda3/envs/Try_OpenAI_GYM/lib/python3.10/site-packages/rware/warehouse.py", line 313, in _use_slow_obs
    [
  File "/Users/perchik/opt/anaconda3/envs/Try_OpenAI_GYM/lib/python3.10/site-packages/rware/warehouse.py", line 344, in <listcomp>
    "local_message": spaces.MultiBinary(
  File "/Users/perchik/opt/anaconda3/envs/Try_OpenAI_GYM/lib/python3.10/site-packages/gym/spaces/multi_binary.py", line 45, in __init__
    assert (np.asarray(input_n) > 0).all()  # n (counts) have to be positive
AssertionError

Why so? Can you help?
Thanks in advance

Question about the observation space

Hi!

I'm confused about the observation space of each robot in the environment. The document explains that the observation space includes (1) The location, the rotation, and whether the agent is carrying a shelf; (2) The location and rotation of other robots; and (3) The shelves and whether they are currently in the request queue. However, I'm not sure about the exact dimension of it.

I created an example with a single agent, one workstation, and four shelves as demonstrated:
image

In this case, the observation is a tuple with only one element, and the element's size is 80 (retrieved directly from the program). I'm wondering how the size is added up.

Thank you so much for your help.

Applying Reinforcement Learning

Hi!

Does anyone have any documentation or tutorial on how to apply Multi-Agent Reinforcement Learning for this enviroment?

I'm having an hard time finding any good resources on how to use rlib or stable-baslines (or any other framework) for any openAI Gym environment with multi-agents.

(PS: I understand that this is not an issue, but I didn't know any better place for this :p).

Thank you!

creating the environment

when I try to execute this line:
env.render()
I get this error:
/usr/local/lib/python3.7/dist-packages/pyglet/canvas/xlib.py in init(self, name, x_screen)
121 self._display = xlib.XOpenDisplay(name)
122 if not self._display:
--> 123 raise NoSuchDisplayException('Cannot connect to "%s"' % name)
124
125 screen_count = xlib.XScreenCount(self._display)

NoSuchDisplayException: Cannot connect to "None"

Bugs caused by gym version changes

Hi,

Great environment, good job!

But it is worth pointing out that due to the change of the gym version to 0.20 or more, the calculation of the number of dimensions of MultiDiscrete has changed. This also leads to different observation dim under different gym versions, and makes the way of writing information in the function _make_obs wrong.

eg:

obs.write([agent.x, agent.y, int(agent.carrying_shelf is not None)])

Should be modified to something like:

direction = np.zeros(4)
direction[self.agents[id_agent - 1].dir.value] = 1.0
obs.write(direction)

gym.make gives an error

AssertionError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_22856\2368146761.py in
----> 1 env = gym.make("rware-tiny-2ag-v1")

~\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py in make(id, **kwargs)
674 # fmt: on
675 def make(id: str, **kwargs) -> "Env":
--> 676 return registry.make(id, **kwargs)
677
678

~\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py in make(self, path, **kwargs)
518 spec = self.spec(path)
519 # Construct the environment
--> 520 return spec.make(**kwargs)
521
522 def all(self):

~\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\envs\registration.py in make(self, kwargs)
138 else:
139 cls = load(self.entry_point)
--> 140 env = cls(
_kwargs)
141
142 # Make the environment aware of which spec it came from.

~\AppData\Local\Programs\Python\Python37\lib\site-packages\rware\warehouse.py in init(self, shelf_columns, column_height, shelf_rows, n_agents, msg_bits, sensor_range, request_queue_size, max_inactivity_steps, max_steps, reward_type, fast_obs, layout)
245 self.fast_obs = None
246 self.observation_space = None
--> 247 self._use_slow_obs()
248
249 # for performance reasons we

~\AppData\Local\Programs\Python\Python37\lib\site-packages\rware\warehouse.py in _use_slow_obs(self)
357 )
358 )
--> 359 for _ in range(self.n_agents)
360 ]
361 )

~\AppData\Local\Programs\Python\Python37\lib\site-packages\rware\warehouse.py in (.0)
357 )
358 )
--> 359 for _ in range(self.n_agents)
360 ]
361 )

~\AppData\Local\Programs\Python\Python37\lib\site-packages\gym\spaces\multi_binary.py in init(self, n, seed)
39 input_n = (n,)
40
---> 41 assert (np.asarray(input_n) > 0).all(), "n (counts) have to be positive"
42
43 super().init(input_n, np.int8, seed)

AssertionError: n (counts) have to be positive

Check for whether agent is unloading shelf at a location where another shelf is already present.

Hi. I am working on a project where I need to modify some of your source code. While going through it, I noticed that you do a check when you toggle load for unloading, to ensure that it does not unload on a highway. From what I can understand a highway is defined as any place not instantiated as a shelf location.

However, I do not see a check for whether you are trying to unload at a location where a shelf is already present.
image

Is that check not done? Is it possible to unload at a non-empty shelf location? Or do you do this check somewhere or maybe define shelf locations already containing a shelf as a highway?

Thank you!

Questions of reward every step output

Hi,I'm interested in your project,but I'm confused about your warehouse.py,that is,why does't it output reward values every time step?Longing for your reply!

modify the environment

hello! I would like to know if it is possible to modify the environment to have the boxes with obstacles that cannot be occupied by the robots.
I am not very expert and would like to understand how to interact with the library to modify aspects of my interest.

I had problems at the beginning

import rware
import gym

env = gym.make("rware-tiny-2ag-v1")

When I run the above code I get an error:
env = gym.make("rware-tiny-2ag-v1")
File "D:\anconda_env\envs\robotic_warehouse\lib\site-packages\gym\envs\registration.py", line 640, in make
env = env_creator(**_kwargs)
File "D:\anconda_env\envs\robotic_warehouse\lib\site-packages\rware\warehouse.py", line 247, in init
self._use_slow_obs()
File "D:\anconda_env\envs\robotic_warehouse\lib\site-packages\rware\warehouse.py", line 359, in _use_slow_obs
for _ in range(self.n_agents)
File "D:\anconda_env\envs\robotic_warehouse\lib\site-packages\rware\warehouse.py", line 359, in
for _ in range(self.n_agents)
File "D:\anconda_env\envs\robotic_warehouse\lib\site-packages\gym\spaces\multi_binary.py", line 44, in init
assert (np.asarray(input_n) > 0).all() # n (counts) have to be positive
AssertionError
image-20240312163712957
The picture above is the package of my environment

Import error

env = gym.make("rware-tiny-2ag-v1")
Traceback (most recent call last):
File "", line 1, in
File "/home/jianhong/anaconda3/envs/mansa/lib/python3.7/site-packages/gym/envs/registration.py", line 676, in make
return registry.make(id, **kwargs)
File "/home/jianhong/anaconda3/envs/mansa/lib/python3.7/site-packages/gym/envs/registration.py", line 520, in make
return spec.make(kwargs)
File "/home/jianhong/anaconda3/envs/mansa/lib/python3.7/site-packages/gym/envs/registration.py", line 140, in make
env = cls(
_kwargs)
File "/home/jianhong/anaconda3/envs/mansa/lib/python3.7/site-packages/rware/warehouse.py", line 247, in init
self._use_slow_obs()
File "/home/jianhong/anaconda3/envs/mansa/lib/python3.7/site-packages/rware/warehouse.py", line 359, in _use_slow_obs
for _ in range(self.n_agents)
File "/home/jianhong/anaconda3/envs/mansa/lib/python3.7/site-packages/rware/warehouse.py", line 359, in
for _ in range(self.n_agents)
File "/home/jianhong/anaconda3/envs/mansa/lib/python3.7/site-packages/gym/spaces/multi_binary.py", line 41, in init
assert (np.asarray(input_n) > 0).all(), "n (counts) have to be positive"
AssertionError: n (counts) have to be positiv

Observation Space Interpretation

I have this environment(photo) and when I print the observation space I receive this list. Where can I find the structure of the observation space to understand better what each elements really means. The only thing that I understand is the position of the agent, which are the first 2 elements ( 5,2).

photo
photo2

I got this error

when i run env.render
i get this error
AssertionError: No 'v' attribute found in ShaderProgram(id=4).
Valid attibutes are: {'colors': Attribute('colors', program=4, location=1, count=4, format=f), 'position': Attribute('position', program=4, location=0, count=3, format=f), 'tex_coords': Attribute('tex_coords', program=4, location=2, count=3, format=f)}.

gym.make("rware:rware-tiny-2ag-v1") assertion error

Hello

when all installed by pip, the following code

import gym
env = gym.make("rware:rware-tiny-2ag-v1")

produces this error:


AssertionError Traceback (most recent call last)
/tmp/ipykernel_318/3796930484.py in <cell line: 2>()
1 import gym
----> 2 env = gym.make("rware:rware-tiny-2ag-v1")

~/.conda/envs/default/lib/python3.9/site-packages/gym/envs/registration.py in make(id, max_episode_steps, autoreset, disable_env_checker, kwargs)
590 env_creator = load(spec_.entry_point)
591
--> 592 env = env_creator(
_kwargs)
593
594 # Copies the environment creation specification and kwargs to add to the environment specification details

~/.conda/envs/default/lib/python3.9/site-packages/rware/warehouse.py in init(self, shelf_columns, column_height, shelf_rows, n_agents, msg_bits, sensor_range, request_queue_size, max_inactivity_steps, max_steps, reward_type, fast_obs, layout)
245 self.fast_obs = None
246 self.observation_space = None
--> 247 self._use_slow_obs()
248
249 # for performance reasons we

~/.conda/envs/default/lib/python3.9/site-packages/rware/warehouse.py in _use_slow_obs(self)
311 self.observation_space = spaces.Tuple(
312 tuple(
--> 313 [
314 spaces.Dict(
315 OrderedDict(

~/.conda/envs/default/lib/python3.9/site-packages/rware/warehouse.py in (.0)
342 "has_agent": spaces.MultiBinary(1),
343 "direction": spaces.Discrete(4),
--> 344 "local_message": spaces.MultiBinary(
345 self.msg_bits
346 ),

~/.conda/envs/default/lib/python3.9/site-packages/gym/spaces/multi_binary.py in init(self, n, seed)
43 self.n = n = int(n)
44 input_n = (n,)
---> 45 assert (np.asarray(input_n) > 0).all() # n (counts) have to be positive
46
47 super().init(input_n, np.int8, seed)

AssertionError:

What shall I do?

An error when using render().

2022-11-27 17-18-33 的屏幕截图
Hi, when I try the example on GitHub. It shows this error. I follow every step on the web. Do you have any idea of this?

Environment breaks down when an agent delivers a shelf

Hi,
I am getting this error the moment an agent delivers a shelf to the predesignated location.

Here's a full stack of the error:

Traceback (most recent call last):
  File "/home/ayoub/Desktop/Projects/RL-algorithms/simulations/qlearning/qlearning.py", line 96, in <module>
    test_robot_warehouse()
  File "/home/ayoub/Desktop/Projects/RL-algorithms/simulations/qlearning/qlearning.py", line 81, in test_robot_warehouse
    states, rewards, done, info = env.step(actions)
  File "/home/ayoub/Desktop/Projects/RL-algorithms/venv/lib/python3.9/site-packages/gym/wrappers/order_enforcing.py", line 11, in step
    observation, reward, done, info = self.env.step(action)
  File "/home/ayoub/Desktop/Projects/RL-algorithms/venv/lib/python3.9/site-packages/rware/warehouse.py", line 606, in step
    new_request = np.random.choice(
  File "mtrand.pyx", line 915, in numpy.random.mtrand.RandomState.choice
ValueError: 'a' cannot be empty unless no samples are taken

Here's the environment configuration:
env = gym.make("rware:rware-tiny-2ag-v1", max_steps=MAX_STEPS, n_agents=N_AGENTS, request_queue_size=32)

I suspect the bug is ignited because the queue size equals the number of shelves in the configuration, so when one is delivered this line fails to catch that exception (inside warehouse.py) since the list is empty:

new_request = np.random.choice(
                list(set(self.shelfs) - set(self.request_queue))
            )

"time_limit" Setting

I'm a little confused about setting "time_limit", do I have to set it to 500?

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.