Skip to content

Commit b41798c

Browse files
committed
compatibility with gym > 0.10.5
1 parent 69ee7f8 commit b41798c

File tree

5 files changed

+26
-9
lines changed

5 files changed

+26
-9
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
__pycache__/
22
*.egg-info/
3-
*.pyc
3+
*.pyc
4+
.venv
5+
.vscode

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
**Status:** Archive (code is provided as-is, no updates expected)
2-
31
# Multi-Agent Particle Environment
42

53
A simple multi-agent particle world with a continuous observation and discrete action space, along with some basic simulated physics.
@@ -12,7 +10,7 @@ Used in the paper [Multi-Agent Actor-Critic for Mixed Cooperative-Competitive En
1210
- To interactively view moving to landmark scenario (see others in ./scenarios/):
1311
`bin/interactive.py --scenario simple.py`
1412

15-
- Known dependencies: Python (3.5.4), OpenAI gym (0.10.5), numpy (1.14.5)
13+
- Tested with: Python (3.8.10), OpenAI gym (0.18.3), numpy (1.21)
1614

1715
- To use the environments, look at the code for importing them in `make_env.py`.
1816

multiagent/multi_discrete.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import numpy as np
55

66
import gym
7-
from gym.spaces import prng
7+
from gym.utils import seeding
88

99
class MultiDiscrete(gym.Space):
1010
"""
@@ -27,10 +27,12 @@ def __init__(self, array_of_param_array):
2727
self.high = np.array([x[1] for x in array_of_param_array])
2828
self.num_discrete_space = self.low.shape[0]
2929

30+
self.random = seeding.np_random()
31+
3032
def sample(self):
3133
""" Returns a array with one sample from each discrete action space """
3234
# For each row: round(random .* (max - min) + min, 0)
33-
random_array = prng.np_random.rand(self.num_discrete_space)
35+
random_array = self.random.rand(self.num_discrete_space)
3436
return [int(x) for x in np.floor(np.multiply((self.high - self.low + 1.), random_array) + self.low)]
3537
def contains(self, x):
3638
return len(x) == self.num_discrete_space and (np.array(x) >= self.low).all() and (np.array(x) <= self.high).all()

multiagent/rendering.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,27 @@
1111
os.environ['DYLD_FALLBACK_LIBRARY_PATH'] += ':/usr/lib'
1212
# (JDS 2016/04/15): avoid bug on Anaconda 2.3.0 / Yosemite
1313

14-
from gym.utils import reraise
1514
from gym import error
1615

1716
try:
1817
import pyglet
1918
except ImportError as e:
20-
reraise(suffix="HINT: you can install pyglet directly via 'pip install pyglet'. But if you really just want to install all Gym dependencies and not have to think about it, 'pip install -e .[all]' or 'pip install gym[all]' will do it.")
19+
raise ImportError('''
20+
Cannot import pyglet.
21+
HINT: you can install pyglet directly via 'pip install pyglet'.
22+
But if you really just want to install all Gym dependencies and not have to think about it,
23+
'pip install -e .[all]' or 'pip install gym[all]' will do it.
24+
''')
2125

2226
try:
2327
from pyglet.gl import *
2428
except ImportError as e:
25-
reraise(prefix="Error occured while running `from pyglet.gl import *`",suffix="HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'. If you're running on a server, you may need a virtual frame buffer; something like this should work: 'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'")
29+
raise ImportError('''
30+
Error occured while running `from pyglet.gl import *`
31+
HINT: make sure you have OpenGL install. On Ubuntu, you can run 'apt-get install python-opengl'.
32+
If you're running on a server, you may need a virtual frame buffer; something like this should work:
33+
'xvfb-run -s \"-screen 0 1400x900x24\" python <your_script.py>'
34+
''')
2635

2736
import math
2837
import numpy as np

multiagent/scenario.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ def make_world(self):
88
# create initial conditions of the world
99
def reset_world(self, world):
1010
raise NotImplementedError()
11+
# return agents rewards
12+
def reward(self, agent, world):
13+
raise NotImplementedError()
14+
# return agents observations
15+
def observation(self, agent, world):
16+
raise NotImplementedError()

0 commit comments

Comments
 (0)