Skip to content
Merged
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ If you use MiniHack in your work, please cite:
}
```

If you use our example ported environments, please cite the original papers: [MiniGrid](https://github.com/maximecb/gym-minigrid/) (see [license](https://github.com/maximecb/gym-minigrid/blob/master/LICENSE), [bib](https://github.com/maximecb/gym-minigrid/#minimalistic-gridworld-environment-minigrid)), [Boxoban](https://github.com/deepmind/boxoban-levels/) (see [license](https://github.com/deepmind/boxoban-levels/blob/master/LICENSE), [bib](https://github.com/deepmind/boxoban-levels/#bibtex)).
If you use our example ported environments, please cite the original papers: [MiniGrid](https://github.com/Farama-Foundation/Minigrid) (see [license](https://github.com/Farama-Foundation/Minigrid/LICENSE), [bib](https://github.com/maximecb/gym-minigrid/#minimalistic-gridworld-environment-minigrid)), [Boxoban](https://github.com/deepmind/boxoban-levels/) (see [license](https://github.com/deepmind/boxoban-levels/blob/master/LICENSE), [bib](https://github.com/deepmind/boxoban-levels/#bibtex)).

# Contributions and Maintenance

Expand Down
2 changes: 1 addition & 1 deletion docs/envs/ported/minigrid.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MiniGrid

This family of environments is ported to MiniHack from [MiniGrid](https://github.com/maximecb/gym-minigrid), a popular suite of procedurally generated grid-based environments that assess various capabilities of RL agents, such as exploration, memory, and generalisation. For more information, check out [MiniGrid's documentation](https://github.com/maximecb/gym-minigrid/blob/master/README.md).
This family of environments is ported to MiniHack from [MiniGrid](https://github.com/Farama-Foundation/Minigrid), a popular suite of procedurally generated grid-based environments that assess various capabilities of RL agents, such as exploration, memory, and generalisation. For more information, check out [MiniGrid's documentation](https://minigrid.farama.org/index.html).
After porting environments to MiniHack, one can make them substantially harder by adding additional environment dynamics to the task, such as monsters, dungeon features and objects.

The MultiRoom environments have a series of connected rooms. The final room has the goal location the agent needs to get to. We have ported the `MultiRoom` in three different room numbers, namely 2, 4 and 6 rooms. Moreover, we added additional complexity to them by adding monsters (e.g. `MiniHack-MultiRoom-N4-Monster-v0`), locked doors (e.g. `MiniHack-MultiRoom-N4-Locked-v0`), lava tiles instead of walls (e.g. `MiniHack-MultiRoom-N4-Lava-v0`), or all at one (e.g. `MiniHack-MultiRoom-N4-Extreme-v0`).
Expand Down
12 changes: 6 additions & 6 deletions minihack/agent/common/envs/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def step(self, action):

return step_return

def reset(self, wizkit_items=None):
def reset(self, options=dict(wizkit_items=None)):
# reset state counter when env resets
obs = self.env.reset(wizkit_items=wizkit_items)
obs = self.env.reset(options=options)
if self.state_counter != "none":
self.state_count_dict.clear()
# current state counts as one visit
Expand Down Expand Up @@ -106,8 +106,8 @@ def step(self, action):

return next_state, reward, done, truncated, info

def reset(self, wizkit_items=None):
obs = self.env.reset(wizkit_items=wizkit_items)
def reset(self, options=dict(wizkit_items=None)):
obs = self.env.reset(options=options)
obs["tty_chars_crop"] = np.zeros((self.h, self.w), dtype=np.uint8)
obs["tty_colors_crop"] = np.zeros((self.h, self.w), dtype=np.int8)
self.last_observation = obs
Expand All @@ -130,8 +130,8 @@ def step(self, action):

return next_state, reward, done, truncated, info

def reset(self, wizkit_items=None):
obs = self.env.reset(wizkit_items=wizkit_items)
def reset(self, options=dict(wizkit_items=None)):
obs = self.env.reset(options=options)
obs["prev_reward"] = np.zeros(1, dtype=np.float32)
obs["prev_action"] = np.zeros(1, dtype=np.uint8)
self.last_observation = obs
Expand Down
4 changes: 2 additions & 2 deletions minihack/envs/boxohack.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ def get_lvl_gen(self):
lvl_gen.set_start_pos(info["player"])
return lvl_gen

def reset(self, wizkit_items=None):
def reset(self, options=dict(wizkit_items=None)):
self.update(self.get_lvl_gen().get_des())
initial_obs = super().reset(wizkit_items=wizkit_items)
initial_obs = super().reset(options=options)
self._goal_pos_set = self._object_positions(self.last_observation, "{")
return initial_obs

Expand Down
37 changes: 23 additions & 14 deletions minihack/envs/minigrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from nle.nethack import Command, CompassDirection
from minihack.envs import register
import gymnasium as gym
from nle.nethack.nethack import TERMINAL_SHAPE


MOVE_AND_KICK_ACTIONS = tuple(
Expand All @@ -12,16 +13,21 @@

class MiniGridHack(MiniHackNavigation):
def __init__(self, *args, **kwargs):
# Only ask users to install gym-minigrid if they actually need it
# Only ask users to install minigrid if they actually need it
try:
import gym_minigrid # noqa: F401
import minigrid # noqa: F401
except ModuleNotFoundError:
raise ModuleNotFoundError(
"To use MiniGrid-based environments, please install"
" gym-minigrid: pip3 install gym-minigrid"
" minigrid: pip3 install minigrid"
)

self.minigrid_env = gym.make(kwargs.pop("env_name"))
height, width = TERMINAL_SHAPE
height -= 3 # adjust for topline -1 and bottomlines -2
width -= 4 # adjust for left -2 and right -2 borders
self.minigrid_env = gym.make(
kwargs.pop("env_name"), width=width, height=height
)
self.num_mon = kwargs.pop("num_mon", 0)
self.num_trap = kwargs.pop("num_trap", 0)
self.door_state = kwargs.pop("door_state", "closed")
Expand All @@ -44,10 +50,10 @@ def get_env_map(self, env):
empty_str = True
env_map = []

for j in range(env.grid.height):
for j in range(env.unwrapped.grid.height):
str = ""
for i in range(env.width):
c = env.grid.get(i, j)
for i in range(env.unwrapped.width):
c = env.unwrapped.grid.get(i, j)
if c is None:
str += "."
continue
Expand All @@ -66,7 +72,7 @@ def get_env_map(self, env):
str += "."
elif c.type == "player":
str += "."
if not empty_str and j < env.grid.height - 1:
if not empty_str and j < env.unwrapped.grid.height - 1:
if set(str) != {"."}:
str = str.replace(".", " ", str.index(self.wall))
inv = str[::-1]
Expand All @@ -75,7 +81,10 @@ def get_env_map(self, env):
elif empty_str:
empty_strs += 1

start_pos = (int(env.agent_pos[0]), int(env.agent_pos[1]) - empty_strs)
start_pos = (
int(env.unwrapped.agent_pos[0]),
int(env.unwrapped.agent_pos[1]) - empty_strs,
)
env_map = "\n".join(env_map)

return env_map, start_pos, goal_pos, door_pos
Expand Down Expand Up @@ -127,10 +136,10 @@ def seed(self, core=None, disp=None, reseed=False):
self.minigrid_env.seed(core)
return super().seed(core, disp, reseed)

def reset(self, wizkit_items=None):
def reset(self, options=dict(wizkit_items=None), **kwargs):
des_file = self.get_env_desc()
self.update(des_file)
return super().reset(wizkit_items=wizkit_items)
return super().reset(options=options, **kwargs)


class MiniHackMultiRoomN2(MiniGridHack):
Expand All @@ -157,7 +166,7 @@ def __init__(self, *args, **kwargs):

register(
id="MiniGrid-MultiRoom-N10-v0",
entry_point="gym_minigrid.envs:MultiRoomEnv",
entry_point="minigrid.envs:MultiRoomEnv",
kwargs={"minNumRooms": 10, "maxNumRooms": 10},
)

Expand Down Expand Up @@ -463,12 +472,12 @@ def __init__(self, *args, **kwargs):
# MiniGrid: LavaCrossing
register(
id="MiniGrid-LavaCrossingS19N13-v0",
entry_point="gym_minigrid.envs:CrossingEnv",
entry_point="minigrid.envs:CrossingEnv",
kwargs={"size": 19, "num_crossings": 13},
)
register(
id="MiniGrid-LavaCrossingS19N17-v0",
entry_point="gym_minigrid.envs:CrossingEnv",
entry_point="minigrid.envs:CrossingEnv",
kwargs={"size": 19, "num_crossings": 17},
)

Expand Down
Loading