Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Full Observability, New Interface #8

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
151 changes: 151 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,152 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
4 changes: 2 additions & 2 deletions gym_multigrid/envs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from gym_multigrid.envs.collect_game import CollectGame4HEnv10x10N2
from gym_multigrid.envs.soccer_game import SoccerGame4HEnv10x15N2
from gym_multigrid.envs.collect_game import CollectGameEnv
from gym_multigrid.envs.soccer_game import SoccerGameEnv
15 changes: 3 additions & 12 deletions gym_multigrid/envs/collect_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def __init__(
balls_index=[],
balls_reward=[],
zero_sum = False,
partial_obs=True,
view_size=7

):
Expand All @@ -37,6 +38,7 @@ def __init__(
# Set this to True for maximum speed
see_through_walls=False,
agents=agents,
partial_obs=partial_obs,
agent_view_size=view_size
)

Expand Down Expand Up @@ -84,15 +86,4 @@ def _handle_drop(self, i, rewards, fwd_pos, fwd_cell):

def step(self, actions):
obs, rewards, done, info = MultiGridEnv.step(self, actions)
return obs, rewards, done, info


class CollectGame4HEnv10x10N2(CollectGameEnv):
def __init__(self):
super().__init__(size=10,
num_balls=[5],
agents_index = [1,2,3],
balls_index=[0],
balls_reward=[1],
zero_sum=True)

return obs, rewards, done, info
17 changes: 3 additions & 14 deletions gym_multigrid/envs/soccer_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def __init__(
self,
size=10,
view_size=3,
partial_obs=True,
width=None,
height=None,
goal_pst = [],
Expand Down Expand Up @@ -39,6 +40,7 @@ def __init__(
# Set this to True for maximum speed
see_through_walls=False,
agents=agents,
partial_obs=partial_obs,
agent_view_size=view_size
)

Expand Down Expand Up @@ -102,17 +104,4 @@ def _handle_drop(self, i, rewards, fwd_pos, fwd_cell):

def step(self, actions):
obs, rewards, done, info = MultiGridEnv.step(self, actions)
return obs, rewards, done, info


class SoccerGame4HEnv10x15N2(SoccerGameEnv):
def __init__(self):
super().__init__(size=None,
height=10,
width=15,
goal_pst = [[1,5], [13,5]],
goal_index = [1,2],
num_balls=[1],
agents_index = [1,1,2,2],
balls_index=[0],
zero_sum=True)
return obs, rewards, done, info
4 changes: 2 additions & 2 deletions gym_multigrid/multigrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ def reset(self):
if self.partial_obs:
obs = self.gen_obs()
else:
obs = [self.grid.encode_for_agents(self.agents[i].pos) for i in range(len(self.agents))]
obs = [self.grid.encode_for_agents(world=self.world, agent_pos=self.agents[i].pos) for i in range(len(self.agents))]
obs=[self.objects.normalize_obs*ob for ob in obs]
return obs

Expand Down Expand Up @@ -1315,7 +1315,7 @@ def step(self, actions):
if self.partial_obs:
obs = self.gen_obs()
else:
obs = [self.grid.encode_for_agents(self.agents[i].pos) for i in range(len(actions))]
obs = [self.grid.encode_for_agents(world=self.world, agent_pos=self.agents[i].pos) for i in range(len(actions))]

obs=[self.objects.normalize_obs*ob for ob in obs]

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup

setup(name='gym_multigrid',
version='0.0.1',
version='0.0.2',
packages=['gym_multigrid', 'gym_multigrid.envs'],
install_requires=[
'gym>=0.9.6',
Expand Down
10 changes: 7 additions & 3 deletions test_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@ def main():
if args.env == 'soccer':
register(
id='multigrid-soccer-v0',
entry_point='gym_multigrid.envs:SoccerGame4HEnv10x15N2',
entry_point='gym_multigrid.envs:SoccerGameEnv',
kwargs={'size': None, 'height': 10, 'width': 15, 'goal_pst': [[1,5], [13,5]], 'goal_index': [1,2], 'num_balls': [1],
'agents_index': [1,1,2,2], 'balls_index': [0], 'zero_sum': True}
)
env = gym.make('multigrid-soccer-v0')

else:
register(
id='multigrid-collect-v0',
entry_point='gym_multigrid.envs:CollectGame4HEnv10x10N2',
entry_point='gym_multigrid.envs:CollectGameEnv',
kwargs={'size': 10,'num_balls': [5], 'agents_index': [1,2,3], 'balls_index': [0], 'balls_reward': [1], 'zero_sum': True, 'partial_obs': False},

)
env = gym.make('multigrid-collect-v0')

Expand All @@ -29,7 +33,7 @@ def main():
nb_agents = len(env.agents)

while True:
env.render(mode='human', highlight=True)
env.render(mode='human', highlight=True if env.partial_obs else False)
time.sleep(0.1)

ac = [env.action_space.sample() for _ in range(nb_agents)]
Expand Down