Skip to content
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
204 changes: 204 additions & 0 deletions minigrid/__init__.py

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion minigrid/core/roomgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(
num_cols: int = 3,
max_steps: int = 100,
agent_view_size: int = 7,
fix_empty_box_bug: bool = False,
**kwargs,
):
assert room_size > 0
Expand All @@ -85,6 +86,7 @@ def __init__(
self.room_size = room_size
self.num_rows = num_rows
self.num_cols = num_cols
self.fix_empty_box_bug = fix_empty_box_bug

height = (room_size - 1) * num_rows + 1
width = (room_size - 1) * num_cols + 1
Expand Down Expand Up @@ -219,7 +221,7 @@ def add_object(
elif kind == "ball":
obj = Ball(color)
elif kind == "box":
obj = Box(color)
obj = Box(color, fix_empty_box_bug=self.fix_empty_box_bug)
else:
raise ValueError(
f"{kind} object kind is not available in this environment."
Expand Down
11 changes: 10 additions & 1 deletion minigrid/core/world_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,15 @@ def render(self, img):


class Box(WorldObj):
def __init__(self, color, contains: WorldObj | None = None):
def __init__(
self,
color,
contains: WorldObj | None = None,
fix_empty_box_bug: bool = False,
):
super().__init__("box", color)
self.contains = contains
self.fix_empty_box_bug = fix_empty_box_bug

def can_pickup(self):
return True
Expand All @@ -288,6 +294,9 @@ def render(self, img):
fill_coords(img, point_in_rect(0.16, 0.84, 0.47, 0.53), c)

def toggle(self, env, pos):
if self.fix_empty_box_bug and self.contains is None:
return False

# Replace the box by its contents
env.grid.set(pos[0], pos[1], self.contains)
return True
15 changes: 15 additions & 0 deletions minigrid/envs/babyai/other.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ class ActionObjDoor(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make a
pickup instruction on an empty box permanently unreachable.

- `BabyAI-ActionObjDoor-v0`
- `BabyAI-ActionObjDoor-v1`

"""

Expand Down Expand Up @@ -154,9 +158,15 @@ class FindObjS5(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable when the randomly-chosen object was a box.

- `BabyAI-FindObjS5-v0`
- `BabyAI-FindObjS5-v1`
- `BabyAI-FindObjS6-v0`
- `BabyAI-FindObjS6-v1`
- `BabyAI-FindObjS7-v0`
- `BabyAI-FindObjS7-v1`

"""

Expand Down Expand Up @@ -383,8 +393,13 @@ class MoveTwoAcross(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
move object permanently uncarryable when it was drawn as a box.

- `BabyAI-MoveTwoAcrossS5N2-v0`
- `BabyAI-MoveTwoAcrossS5N2-v1`
- `BabyAI-MoveTwoAcrossS8N9-v0`
- `BabyAI-MoveTwoAcrossS8N9-v1`

"""

Expand Down
21 changes: 21 additions & 0 deletions minigrid/envs/babyai/pickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class Pickup(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable when it was drawn as a box.

- `BabyAI-Pickup-v0`
- `BabyAI-Pickup-v1`

"""

Expand Down Expand Up @@ -122,7 +126,11 @@ class UnblockPickup(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable when it was drawn as a box.

- `BabyAI-UnblockPickup-v0`
- `BabyAI-UnblockPickup-v1`

"""

Expand Down Expand Up @@ -192,7 +200,11 @@ class PickupLoc(LevelGen):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable when it was drawn as a box.

- `BabyAI-PickupLoc-v0`
- `BabyAI-PickupLoc-v1`

"""

Expand Down Expand Up @@ -264,8 +276,13 @@ class PickupDist(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable when it was drawn as a box.

- `BabyAI-PickupDist-v0`
- `BabyAI-PickupDist-v1`
- `BabyAI-PickupDistDebug-v0`
- `BabyAI-PickupDistDebug-v1`

"""

Expand Down Expand Up @@ -340,7 +357,11 @@ class PickupAbove(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable when it was drawn as a box.

- `BabyAI-PickupAbove-v0`
- `BabyAI-PickupAbove-v1`

"""

Expand Down
18 changes: 17 additions & 1 deletion minigrid/envs/babyai/putnext.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ class PutNextLocal(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
move object permanently uncarryable when it was drawn as a box.

- `BabyAI-PutNextLocal-v0`
- `BabyAI-PutNextLocal-v1`
- `BabyAI-PutNextLocalS5N3-v0`
- `BabyAI-PutNextLocalS6N4-v0``
- `BabyAI-PutNextLocalS5N3-v1`
- `BabyAI-PutNextLocalS6N4-v0`
- `BabyAI-PutNextLocalS6N4-v1`

"""

Expand Down Expand Up @@ -131,11 +137,21 @@ class PutNext(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
move object permanently uncarryable when it was drawn as a box. The
`*Carrying` configurations start with the move object already held, so they
are not affected and have no v1 counterpart.

- `BabyAI-PutNextS4N1-v0`
- `BabyAI-PutNextS4N1-v1`
- `BabyAI-PutNextS5N2-v0`
- `BabyAI-PutNextS5N2-v1`
- `BabyAI-PutNextS5N1-v0`
- `BabyAI-PutNextS5N1-v1`
- `BabyAI-PutNextS6N3-v0`
- `BabyAI-PutNextS6N3-v1`
- `BabyAI-PutNextS7N4-v0`
- `BabyAI-PutNextS7N4-v1`
- `BabyAI-PutNextS5N2Carrying-v0`
- `BabyAI-PutNextS6N3Carrying-v0`
- `BabyAI-PutNextS7N4Carrying-v0`
Expand Down
25 changes: 25 additions & 0 deletions minigrid/envs/babyai/synth.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ class Synth(LevelGen):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make a
pickup or put-next goal permanently unreachable when it involved a box.

- `BabyAI-Synth-v0`
- `BabyAI-Synth-v1`
- `BabyAI-SynthS5R2-v0`
- `BabyAI-SynthS5R2-v1`

"""

Expand Down Expand Up @@ -163,7 +168,11 @@ class SynthLoc(LevelGen):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make a
pickup or put-next goal permanently unreachable when it involved a box.

- `BabyAI-SynthLoc-v0`
- `BabyAI-SynthLoc-v1`
"""

def __init__(self, **kwargs):
Expand Down Expand Up @@ -268,7 +277,11 @@ class SynthSeq(LevelGen):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make a
pickup or put-next goal permanently unreachable when it involved a box.

- `BabyAI-SynthSeq-v0`
- `BabyAI-SynthSeq-v1`

"""

Expand Down Expand Up @@ -370,7 +383,11 @@ class MiniBossLevel(LevelGen):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make a
pickup or put-next goal permanently unreachable when it involved a box.

- `BabyAI-MiniBossLevel-v0`
- `BabyAI-MiniBossLevel-v1`

"""

Expand Down Expand Up @@ -473,7 +490,11 @@ class BossLevel(LevelGen):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make a
pickup or put-next goal permanently unreachable when it involved a box.

- `BabyAI-BossLevel-v0`
- `BabyAI-BossLevel-v1`
"""

def __init__(self, **kwargs):
Expand Down Expand Up @@ -569,7 +590,11 @@ class BossLevelNoUnlock(LevelGen):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make a
pickup or put-next goal permanently unreachable when it involved a box.

- `BabyAI-BossLevelNoUnlock-v0`
- `BabyAI-BossLevelNoUnlock-v1`
"""

def __init__(self, **kwargs):
Expand Down
9 changes: 9 additions & 0 deletions minigrid/envs/babyai/unlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,13 @@ class UnlockPickup(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable.

- `BabyAI-UnlockPickup-v0`
- `BabyAI-UnlockPickup-v1`
- `BabyAI-UnlockPickupDist-v0`
- `BabyAI-UnlockPickupDist-v1`

"""

Expand Down Expand Up @@ -364,7 +369,11 @@ class BlockedUnlockPickup(RoomGridLevel):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable.

- `BabyAI-BlockedUnlockPickup-v0`
- `BabyAI-BlockedUnlockPickup-v1`

"""

Expand Down
4 changes: 4 additions & 0 deletions minigrid/envs/blockedunlockpickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ class BlockedUnlockPickupEnv(RoomGrid):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable.

- `MiniGrid-BlockedUnlockPickup-v0`
- `MiniGrid-BlockedUnlockPickup-v1`

"""

Expand Down
17 changes: 15 additions & 2 deletions minigrid/envs/putnear.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,27 @@ class PutNearEnv(MiniGridEnv):

N: number of objects.

"v1" prevents toggling an empty box from deleting it, which used to make the
move object permanently uncarryable if it was drawn as an empty box.

- `MiniGrid-PutNear-6x6-N2-v0`
- `MiniGrid-PutNear-8x8-N3-v0`
- `MiniGrid-PutNear-6x6-N2-v1`
- `MiniGrid-PutNear-8x8-N3-v1`

"""

def __init__(self, size=6, numObjs=2, max_steps: int | None = None, **kwargs):
def __init__(
self,
size=6,
numObjs=2,
max_steps: int | None = None,
fix_empty_box_bug: bool = False,
**kwargs,
):
self.size = size
self.numObjs = numObjs
self.fix_empty_box_bug = fix_empty_box_bug
self.obj_types = ["key", "ball", "box"]
mission_space = MissionSpace(
mission_func=self._gen_mission,
Expand Down Expand Up @@ -136,7 +149,7 @@ def near_obj(env, p1):
elif objType == "ball":
obj = Ball(objColor)
elif objType == "box":
obj = Box(objColor)
obj = Box(objColor, fix_empty_box_bug=self.fix_empty_box_bug)
else:
raise ValueError(
"{} object type given. Object type can only be of values key, ball and box.".format(
Expand Down
4 changes: 4 additions & 0 deletions minigrid/envs/unlockpickup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ class UnlockPickupEnv(RoomGrid):

## Registered Configurations

"v1" prevents toggling an empty box from deleting it, which used to make the
pickup goal permanently unreachable.

- `MiniGrid-UnlockPickup-v0`
- `MiniGrid-UnlockPickup-v1`

"""

Expand Down
Loading
Loading