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

Updating bot for compatibility with legacy and Minigrid #121

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions babyai/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ class GoNextToSubgoal(Subgoal):

def replan_before_action(self):
target_obj = None
if isinstance(self.datum, ObjDesc):
if 'ObjDesc' in type(self.datum).__name__:
target_obj, target_pos = self.bot._find_obj_pos(self.datum, self.reason == 'PutNext')
if not target_pos:
# No path found -> Explore the world
self.bot.stack.append(ExploreSubgoal(self.bot))
return
elif isinstance(self.datum, WorldObj):
elif 'WorldObj' in type(self.datum).__name__:
target_obj = self.datum
target_pos = target_obj.cur_pos
else:
Expand Down Expand Up @@ -379,7 +379,7 @@ def steppable(cell):

# So there is a path (blocker, or non-blockers)
# -> try following it
next_cell = path[0]
next_cell = np.asarray(path[0])

# Choose the action in the case when the forward cell
# is the one we should go next to
Expand Down Expand Up @@ -529,7 +529,7 @@ def __init__(self, mission):
self.grid = Grid(mission.width, mission.height)

# Visibility mask. True for explored/seen, false for unexplored.
self.vis_mask = np.zeros(shape=(mission.width, mission.height), dtype=np.bool)
self.vis_mask = np.zeros(shape=(mission.width, mission.height), dtype=bool)

# Stack of tasks/subtasks to complete (tuples)
self.stack = []
Expand Down Expand Up @@ -606,6 +606,8 @@ def _find_obj_pos(self, obj_desc, adjacent=False):
best_obj = None

for i in range(len(obj_desc.obj_set)):
if obj_desc.obj_set[i].type == 'wall':
continue
try:
if obj_desc.obj_set[i] == self.mission.carrying:
continue
Expand Down Expand Up @@ -902,36 +904,37 @@ def _process_instr(self, instr):
Translate instructions into an internal form the agent can execute
"""

if isinstance(instr, GoToInstr):
if 'GoToInstr' in type(instr).__name__:
self.stack.append(GoNextToSubgoal(self, instr.desc))
return

if isinstance(instr, OpenInstr):
if 'OpenInstr' in type(instr).__name__:
self.stack.append(OpenSubgoal(self))
self.stack.append(GoNextToSubgoal(self, instr.desc, reason='Open'))
return

if isinstance(instr, PickupInstr):
if 'PickupInstr' in type(instr).__name__:
# We pick up and immediately drop so
# that we may carry other objects
self.stack.append(DropSubgoal(self))
self.stack.append(PickupSubgoal(self))
self.stack.append(GoNextToSubgoal(self, instr.desc))
return

if isinstance(instr, PutNextInstr):
if 'PutNextInstr' in type(instr).__name__:
self.stack.append(DropSubgoal(self))
self.stack.append(GoNextToSubgoal(self, instr.desc_fixed, reason='PutNext'))
self.stack.append(PickupSubgoal(self))
self.stack.append(GoNextToSubgoal(self, instr.desc_move))
return

if isinstance(instr, BeforeInstr) or isinstance(instr, AndInstr):
if 'BeforeInstr' in type(instr).__name__ \
or 'AndInstr' in type(instr).__name__:
self._process_instr(instr.instr_b)
self._process_instr(instr.instr_a)
return

if isinstance(instr, AfterInstr):
if 'AfterInstr' in type(instr).__name__:
self._process_instr(instr.instr_a)
self._process_instr(instr.instr_b)
return
Expand Down
3 changes: 2 additions & 1 deletion babyai/levels/bonus_levels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import gym
from gym_minigrid.envs import Key, Ball, Box
#from gym_minigrid.envs import Key, Ball, Box
from gym_minigrid.minigrid import Key, Ball, Box
from .verifier import *
from .levelgen import *

Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
keywords='memory, environment, agent, rl, openaigym, openai-gym, gym',
packages=['babyai', 'babyai.levels', 'babyai.utils'],
install_requires=[
'gym>=0.9.6',
'numpy==1.15.4', # Temporary: fix numpy version because of bug introduced in 1.16
'gym==0.23', # before introduction of 'truncated' extra output... (previously: >=0.9.6')
'numpy',
"torch>=0.4.1",
'blosc>=1.5.1',
'gym_minigrid @ https://github.com/maximecb/gym-minigrid/archive/master.zip'
'gym-minigrid==1.1', # before gym-minigrid became Minigrid (previously 'gym_minigrid @ https://github.com/maximecb/gym-minigrid/archive/master.zip')
],
)