From 1f702d70a143c859ded1432d85bd9513d9dc3398 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sat, 22 Oct 2022 10:58:56 -0400 Subject: [PATCH 1/8] added docstring to a few envs --- gym_miniworld/envs/collecthealth.py | 34 ++++++++++++++++++++++++++-- gym_miniworld/envs/fourrooms.py | 32 ++++++++++++++++++++++---- gym_miniworld/envs/hallway.py | 31 +++++++++++++++++++++++-- gym_miniworld/envs/maze.py | 35 +++++++++++++++++++++++++++-- gym_miniworld/miniworld.py | 16 ++++++------- 5 files changed, 130 insertions(+), 18 deletions(-) diff --git a/gym_miniworld/envs/collecthealth.py b/gym_miniworld/envs/collecthealth.py index 56877adb..54380ec4 100644 --- a/gym_miniworld/envs/collecthealth.py +++ b/gym_miniworld/envs/collecthealth.py @@ -4,15 +4,45 @@ class CollectHealth(MiniWorldEnv): """ + ## Description + Environment where the agent has to collect health kits and stay alive as long as possible. This is inspired from the VizDoom - HealthGathering environment. Please note, however, that the rewards + `HealthGathering` environment. Please note, however, that the rewards produced by this environment are not directly comparable to those of the VizDoom environment. - reward: + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + | 3 | move back | + | 4 | pick up | + | 5 | drop | + | 6 | toggle / activate an object | + | 7 | complete task | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + +2 for each time step -100 for dying + + ## Arguments + + ```python + CollectHealth(size=16) + ``` + + `size`: size of the room + """ def __init__(self, size=16, **kwargs): diff --git a/gym_miniworld/envs/fourrooms.py b/gym_miniworld/envs/fourrooms.py index 7737fabf..569878dd 100644 --- a/gym_miniworld/envs/fourrooms.py +++ b/gym_miniworld/envs/fourrooms.py @@ -1,13 +1,37 @@ -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class FourRooms(MiniWorldEnv): """ - Classic four rooms environment. - The agent must reach the red box to get a reward. + ## Description + + Classic four rooms environment. The agent must reach the red box to get a reward. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +1 - 0.2 * (step_count / max_episode_steps) when red box reached + + ## Arguments + + ```python + FourRooms() + ``` + """ def __init__(self, **kwargs): diff --git a/gym_miniworld/envs/hallway.py b/gym_miniworld/envs/hallway.py index 711e2da3..e75c61b2 100644 --- a/gym_miniworld/envs/hallway.py +++ b/gym_miniworld/envs/hallway.py @@ -1,15 +1,42 @@ import math -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class Hallway(MiniWorldEnv): """ + ## Description + Environment in which the goal is to go to a red box at the end of a hallway + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +1 - 0.2 * (step_count / max_episode_steps) when red box reached + + ## Arguments + + ```python + FourRooms(length=12) + ``` + + `length`: length of the entire space + """ def __init__(self, length=12, **kwargs): diff --git a/gym_miniworld/envs/maze.py b/gym_miniworld/envs/maze.py index 9c23ff5b..8997d9fc 100644 --- a/gym_miniworld/envs/maze.py +++ b/gym_miniworld/envs/maze.py @@ -1,13 +1,44 @@ -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS +from gymnasium import spaces class Maze(MiniWorldEnv): """ + ## Description + Maze environment in which the agent has to reach a red box + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +1 - 0.2 * (step_count / max_episode_steps) when red box reached + + ## Arguments + + ```python + Maze(num_rows=8, num_cols=8, room_size=3) + ``` + + `num_rows`: number of rows + + `num_cols`: number of columns + + `room_size`: size of rooms + """ def __init__( diff --git a/gym_miniworld/miniworld.py b/gym_miniworld/miniworld.py index c8d9bb1b..ce413eb0 100644 --- a/gym_miniworld/miniworld.py +++ b/gym_miniworld/miniworld.py @@ -470,15 +470,15 @@ class Actions(IntEnum): def __init__( self, - max_episode_steps=1500, - obs_width=80, - obs_height=60, - window_width=800, - window_height=600, + max_episode_steps: int = 1500, + obs_width: int = 80, + obs_height: int = 60, + window_width: int = 800, + window_height: int = 600, params=DEFAULT_PARAMS, - domain_rand=False, - render_mode=None, - view="agent", + domain_rand: bool = False, + render_mode: Optional[str] = None, + view: str = "agent", ): # Action enumeration for this environment self.actions = MiniWorldEnv.Actions From b64013cf5a5e7d64baa04af21fac7ea15c0e40a4 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sat, 22 Oct 2022 11:00:31 -0400 Subject: [PATCH 2/8] passed pre-commit --- gym_miniworld/envs/fourrooms.py | 3 ++- gym_miniworld/envs/hallway.py | 3 ++- gym_miniworld/envs/maze.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/gym_miniworld/envs/fourrooms.py b/gym_miniworld/envs/fourrooms.py index 569878dd..7aefe9f9 100644 --- a/gym_miniworld/envs/fourrooms.py +++ b/gym_miniworld/envs/fourrooms.py @@ -1,6 +1,7 @@ +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class FourRooms(MiniWorldEnv): diff --git a/gym_miniworld/envs/hallway.py b/gym_miniworld/envs/hallway.py index e75c61b2..23060646 100644 --- a/gym_miniworld/envs/hallway.py +++ b/gym_miniworld/envs/hallway.py @@ -1,8 +1,9 @@ import math +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class Hallway(MiniWorldEnv): diff --git a/gym_miniworld/envs/maze.py b/gym_miniworld/envs/maze.py index 8997d9fc..653e75a3 100644 --- a/gym_miniworld/envs/maze.py +++ b/gym_miniworld/envs/maze.py @@ -1,7 +1,8 @@ +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS -from gymnasium import spaces class Maze(MiniWorldEnv): From be10adbdb4388c8e652e14116c6a60c0b8229936 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sat, 29 Oct 2022 14:40:22 -0400 Subject: [PATCH 3/8] updated manual_control to conform with the new api --- scripts/benchmark.py | 2 +- scripts/manual_control.py | 22 +++++++++++----------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/scripts/benchmark.py b/scripts/benchmark.py index b8bb43cf..c25f0066 100755 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -2,7 +2,7 @@ import time -import gym +import gymnasium as gym # Benchmark loading time st = time.time() diff --git a/scripts/manual_control.py b/scripts/manual_control.py index c2559563..c7303d71 100755 --- a/scripts/manual_control.py +++ b/scripts/manual_control.py @@ -9,12 +9,13 @@ import math import sys -import gym +import gym_miniworld +import gymnasium as gym import pyglet from pyglet.window import key parser = argparse.ArgumentParser() -parser.add_argument("--env-name", default="MiniWorld-Hallway-v0") +parser.add_argument("--env-name", default=gym_miniworld.envs.env_ids[0]) parser.add_argument( "--domain-rand", action="store_true", help="enable domain randomization" ) @@ -27,20 +28,19 @@ help="show the top view instead of the agent view", ) args = parser.parse_args() +view_mode = "top" if args.top_view else "agent" -env = gym.make(args.env_name) +env = gym.make(args.env_name, view=view_mode, render_mode="human") if args.no_time_limit: env.max_episode_steps = math.inf if args.domain_rand: env.domain_rand = True -view_mode = "top" if args.top_view else "agent" - env.reset() # Create the display window -env.render("pyglet", view=view_mode) +env.render() def step(action): @@ -50,16 +50,16 @@ def step(action): ) ) - obs, reward, done, info = env.step(action) + obs, reward, termination, truncation, info = env.step(action) if reward > 0: print(f"reward={reward:.2f}") - if done: + if termination: print("done!") env.reset() - env.render("pyglet", view=view_mode) + env.render() @env.unwrapped.window.event @@ -72,7 +72,7 @@ def on_key_press(symbol, modifiers): if symbol == key.BACKSPACE or symbol == key.SLASH: print("RESET") env.reset() - env.render("pyglet", view=view_mode) + env.render() return if symbol == key.ESCAPE: @@ -105,7 +105,7 @@ def on_key_release(symbol, modifiers): @env.unwrapped.window.event def on_draw(): - env.render("pyglet", view=view_mode) + env.render() @env.unwrapped.window.event From de32af49904af0fa1d21276415fc9d19e3d598e0 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sat, 29 Oct 2022 14:40:43 -0400 Subject: [PATCH 4/8] updated manual_control to conform with the new api --- scripts/manual_control.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/manual_control.py b/scripts/manual_control.py index c7303d71..6b62d153 100755 --- a/scripts/manual_control.py +++ b/scripts/manual_control.py @@ -9,11 +9,12 @@ import math import sys -import gym_miniworld import gymnasium as gym import pyglet from pyglet.window import key +import gym_miniworld + parser = argparse.ArgumentParser() parser.add_argument("--env-name", default=gym_miniworld.envs.env_ids[0]) parser.add_argument( From 68a938b08db2f3da96beaad975537bc21a459001 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 30 Oct 2022 15:09:22 -0400 Subject: [PATCH 5/8] added docstrings to all envs --- gym_miniworld/envs/fourrooms.py | 5 ++- gym_miniworld/envs/hallway.py | 5 ++- gym_miniworld/envs/maze.py | 19 +++++----- gym_miniworld/envs/oneroom.py | 31 ++++++++++++++-- gym_miniworld/envs/pickupobjs.py | 35 ++++++++++++++++-- gym_miniworld/envs/putnext.py | 33 +++++++++++++++++ gym_miniworld/envs/remotebot.py | 6 +--- gym_miniworld/envs/roomobjs.py | 33 +++++++++++++++++ gym_miniworld/envs/sidewalk.py | 29 +++++++++++++-- gym_miniworld/envs/sign.py | 56 ++++++++++++++++++++--------- gym_miniworld/envs/simtorealgoto.py | 29 +++++++++++++-- gym_miniworld/envs/simtorealpush.py | 30 ++++++++++++++-- gym_miniworld/envs/threerooms.py | 29 +++++++++++++-- gym_miniworld/envs/tmaze.py | 32 +++++++++++++++-- gym_miniworld/envs/wallgap.py | 28 +++++++++++++-- gym_miniworld/envs/ymaze.py | 31 ++++++++++++++-- scripts/benchmark.py | 5 +-- scripts/manual_control.py | 7 ++-- 18 files changed, 381 insertions(+), 62 deletions(-) diff --git a/gym_miniworld/envs/fourrooms.py b/gym_miniworld/envs/fourrooms.py index 7aefe9f9..407156c8 100644 --- a/gym_miniworld/envs/fourrooms.py +++ b/gym_miniworld/envs/fourrooms.py @@ -1,7 +1,6 @@ -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class FourRooms(MiniWorldEnv): @@ -25,7 +24,7 @@ class FourRooms(MiniWorldEnv): ## Rewards: - +1 - 0.2 * (step_count / max_episode_steps) when red box reached + +(1 - 0.2 * (step_count / max_episode_steps)) when red box reached ## Arguments diff --git a/gym_miniworld/envs/hallway.py b/gym_miniworld/envs/hallway.py index 23060646..4e625188 100644 --- a/gym_miniworld/envs/hallway.py +++ b/gym_miniworld/envs/hallway.py @@ -1,9 +1,8 @@ import math -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class Hallway(MiniWorldEnv): @@ -28,7 +27,7 @@ class Hallway(MiniWorldEnv): ## Rewards: - +1 - 0.2 * (step_count / max_episode_steps) when red box reached + +(1 - 0.2 * (step_count / max_episode_steps)) when red box reached ## Arguments diff --git a/gym_miniworld/envs/maze.py b/gym_miniworld/envs/maze.py index 653e75a3..d73313f4 100644 --- a/gym_miniworld/envs/maze.py +++ b/gym_miniworld/envs/maze.py @@ -1,8 +1,7 @@ -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS +from gymnasium import spaces class Maze(MiniWorldEnv): @@ -11,7 +10,7 @@ class Maze(MiniWorldEnv): Maze environment in which the agent has to reach a red box - ## Action Space + ## Action Space | Num | Action | |-----|-----------------------------| @@ -26,20 +25,18 @@ class Maze(MiniWorldEnv): ## Rewards: - +1 - 0.2 * (step_count / max_episode_steps) when red box reached + +(1 - 0.2 * (step_count / max_episode_steps)) when red box reached ## Arguments ```python - Maze(num_rows=8, num_cols=8, room_size=3) + MazeS2() + # or + MazeS3() + # or + MazeS3Fast() ``` - `num_rows`: number of rows - - `num_cols`: number of columns - - `room_size`: size of rooms - """ def __init__( diff --git a/gym_miniworld/envs/oneroom.py b/gym_miniworld/envs/oneroom.py index df8e0d18..260e92a3 100644 --- a/gym_miniworld/envs/oneroom.py +++ b/gym_miniworld/envs/oneroom.py @@ -1,14 +1,41 @@ -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS +from gymnasium import spaces class OneRoom(MiniWorldEnv): """ + ## Description + Environment in which the goal is to go to a red box placed randomly in one big room. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +(1 - 0.2 * (step_count / max_episode_steps)) when red box reached + + ## Arguments + + ```python + OneRoomS6() + # or + OneRoomS6Fast() + ``` + """ def __init__(self, size=10, max_episode_steps=180, **kwargs): diff --git a/gym_miniworld/envs/pickupobjs.py b/gym_miniworld/envs/pickupobjs.py index 6cc3d9e8..ad294f27 100644 --- a/gym_miniworld/envs/pickupobjs.py +++ b/gym_miniworld/envs/pickupobjs.py @@ -1,13 +1,44 @@ -from gymnasium import spaces - from gym_miniworld.entity import Ball, Box, Key from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class PickupObjs(MiniWorldEnv): """ + ## Description + Room with multiple objects. The agent collects +1 reward for picking up each object. Objects disappear when picked up. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + | 3 | move_back | + | 4 | pickup | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +1 when agent picked up object + + ## Arguments + + ```python + PickupObjs(size=12, num_objs=5) + ``` + + `size`: size of world + + `num_objs`: number of objects + """ def __init__(self, size=12, num_objs=5, **kwargs): diff --git a/gym_miniworld/envs/putnext.py b/gym_miniworld/envs/putnext.py index ed3ff2eb..7df931fb 100644 --- a/gym_miniworld/envs/putnext.py +++ b/gym_miniworld/envs/putnext.py @@ -4,8 +4,41 @@ class PutNext(MiniWorldEnv): """ + ## Description + Single-room environment where a red box must be placed next to a yellow box. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + | 3 | move back | + | 4 | pick up | + | 5 | drop | + | 6 | toggle / activate an object | + | 7 | complete task | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +(1 - 0.2 * (step_count / max_episode_steps)) when red box is next to yellow box + + ## Arguments + + ```python + PutNext(size=12) + ``` + + `size`: size of world + """ def __init__(self, size=12, **kwargs): diff --git a/gym_miniworld/envs/remotebot.py b/gym_miniworld/envs/remotebot.py index fd0a3585..bc48e505 100644 --- a/gym_miniworld/envs/remotebot.py +++ b/gym_miniworld/envs/remotebot.py @@ -7,6 +7,7 @@ import numpy import numpy as np import pyglet +from gym_miniworld.miniworld import MiniWorldEnv from gymnasium import spaces # Try importing ZMQ @@ -21,11 +22,6 @@ glViewport, ) -from gym_miniworld.miniworld import MiniWorldEnv - -# from gym.utils import seeding - - try: import zmq except ImportError: diff --git a/gym_miniworld/envs/roomobjs.py b/gym_miniworld/envs/roomobjs.py index 3ef8c4ae..9f195dfa 100644 --- a/gym_miniworld/envs/roomobjs.py +++ b/gym_miniworld/envs/roomobjs.py @@ -6,10 +6,43 @@ class RoomObjs(MiniWorldEnv): """ + ## Description + Single room with multiple objects Inspired by the single room environment of the Generative Query Networks paper: https://deepmind.com/blog/neural-scene-representation-and-rendering/ + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + | 3 | move back | + | 4 | pick up | + | 5 | drop | + | 6 | toggle / activate an object | + | 7 | complete task | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +0 + + ## Arguments + + ```python + RoomObjs(size=16) + ``` + + `size`: size of world + """ def __init__(self, size=10, **kwargs): diff --git a/gym_miniworld/envs/sidewalk.py b/gym_miniworld/envs/sidewalk.py index 5ea93359..332b004f 100644 --- a/gym_miniworld/envs/sidewalk.py +++ b/gym_miniworld/envs/sidewalk.py @@ -1,16 +1,41 @@ import math import numpy as np -from gymnasium import spaces - from gym_miniworld.entity import Box, MeshEnt from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class Sidewalk(MiniWorldEnv): """ + ## Description + Walk on a sidewalk up to an object to be collected. Don't walk into the street. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +(1 - 0.2 * (step_count / max_episode_steps)) when object reached + + ## Arguments + + ```python + Sidewalk() + ``` + """ def __init__(self, **kwargs): diff --git a/gym_miniworld/envs/sign.py b/gym_miniworld/envs/sign.py index 0a64098c..b028b511 100644 --- a/gym_miniworld/envs/sign.py +++ b/gym_miniworld/envs/sign.py @@ -2,12 +2,11 @@ from typing import Optional, Tuple import gymnasium as gym -from gymnasium.core import ObsType -from gymnasium.spaces import Dict, Discrete - from gym_miniworld.entity import COLOR_NAMES, Box, Key, MeshEnt, TextFrame from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS +from gymnasium.core import ObsType +from gymnasium.spaces import Dict, Discrete class BigKey(Key): @@ -19,7 +18,10 @@ def __init__(self, color, size=0.6): class Sign(MiniWorldEnv): - """Sign environment from https://arxiv.org/abs/2008.02790. + """ + ## Description + + Sign environment from https://arxiv.org/abs/2008.02790. If you use this environment, please cite the above paper (Liu et al., 2020). @@ -30,26 +32,48 @@ class Sign(MiniWorldEnv): includes a goal under state["goal"] that specifies box or key. The episode ends when any object is touched. - Touching the object where the color matches the sign and the shape matches the - goal yields +1 reward. - Touching any other object yields -1 reward. The sign and goal can be configured via the color_index and goal arguments to the constructor respectively. Includes an action to end the episode. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + | 3 | end episode | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +1 for touching the object where the color matches the sign and the shape matches the goal + -1 for touching any other object + + ## Arguments + + ```python + Sign(size=10, max_episode_steps=20, color_index=0, goal=0) + ``` + + `size`: size of the square room. + + `max_episode_steps`: number of steps before the episode ends. + + `color_index`: specifies whether the sign says blue (0), green (1), or red (2). + + `goal`: specifies box (0) or key (1). + """ def __init__(self, size=10, max_episode_steps=20, color_index=0, goal=0): - """Constructs. - - Args: - size (int): size of the square room. - max_episode_steps (int): number of steps before the episode ends. - color_index (int): specifies whether the sign says blue (0), green (1), or - red (2). - goal (int): specifies box (0) or key (1). - """ if color_index not in [0, 1, 2]: raise ValueError("Only supported values for color_index are 0, 1, 2.") diff --git a/gym_miniworld/envs/simtorealgoto.py b/gym_miniworld/envs/simtorealgoto.py index e87b4e4f..22f3915e 100644 --- a/gym_miniworld/envs/simtorealgoto.py +++ b/gym_miniworld/envs/simtorealgoto.py @@ -1,8 +1,7 @@ -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS +from gymnasium import spaces # Simulation parameters # These assume a robot about 15cm tall with a pi camera module v2 @@ -21,8 +20,34 @@ class SimToRealGoTo(MiniWorldEnv): """ + ## Description + Environment designed for sim-to-real transfer. In this environment, the robot has to go to the red box. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +(1 - 0.2 * (step_count / max_episode_steps)) when red box reached + + ## Arguments + + ```python + SimToRealGoTo() + ``` + """ def __init__(self, **kwargs): diff --git a/gym_miniworld/envs/simtorealpush.py b/gym_miniworld/envs/simtorealpush.py index 6598183e..d4fa3c56 100644 --- a/gym_miniworld/envs/simtorealpush.py +++ b/gym_miniworld/envs/simtorealpush.py @@ -1,11 +1,10 @@ import math import numpy as np -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS +from gymnasium import spaces # Simulation parameters # These assume a robot about 15cm tall with a pi camera module v2 @@ -23,9 +22,36 @@ class SimToRealPush(MiniWorldEnv): """ + ## Description + Environment designed for sim-to-real transfer. In this environment, the robot has to push the red box towards the yellow box. + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + | 3 | move back | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +1 when the red box is close to the yellow box + + ## Arguments + + ```python + SimToRealPush() + ``` + """ def __init__(self, **kwargs): diff --git a/gym_miniworld/envs/threerooms.py b/gym_miniworld/envs/threerooms.py index 8d8487bc..edd59cb9 100644 --- a/gym_miniworld/envs/threerooms.py +++ b/gym_miniworld/envs/threerooms.py @@ -1,14 +1,39 @@ import math -from gymnasium import spaces - from gym_miniworld.entity import Ball, Box, ImageFrame, Key, MeshEnt from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class ThreeRooms(MiniWorldEnv): """ + ## Description + Two small rooms connected to one large room + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + None + + ## Arguments + + ```python + ThreeRooms() + ``` + """ def __init__(self, **kwargs): diff --git a/gym_miniworld/envs/tmaze.py b/gym_miniworld/envs/tmaze.py index b0cc0dca..3741da6e 100644 --- a/gym_miniworld/envs/tmaze.py +++ b/gym_miniworld/envs/tmaze.py @@ -1,14 +1,42 @@ import math -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class TMaze(MiniWorldEnv): """ + ## Description + Two hallways connected in a T-junction + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +(1 - 0.2 * (step_count / max_episode_steps)) when box reached + + ## Arguments + + ```python + TMazeLeft() + # or + TMazeRight() + ``` + + """ def __init__(self, goal_pos=None, **kwargs): diff --git a/gym_miniworld/envs/wallgap.py b/gym_miniworld/envs/wallgap.py index 95750f2a..a95c373d 100644 --- a/gym_miniworld/envs/wallgap.py +++ b/gym_miniworld/envs/wallgap.py @@ -1,15 +1,39 @@ import math import numpy as np -from gymnasium import spaces - from gym_miniworld.entity import Box, MeshEnt from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class WallGap(MiniWorldEnv): """ + ## Description + Outside environment with two rooms connected by a gap in a wall + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +(1 - 0.2 * (step_count / max_episode_steps)) when box reached + + ## Arguments + + ```python + WallGap() + ``` """ def __init__(self, **kwargs): diff --git a/gym_miniworld/envs/ymaze.py b/gym_miniworld/envs/ymaze.py index e9dd9f3d..01eb9278 100644 --- a/gym_miniworld/envs/ymaze.py +++ b/gym_miniworld/envs/ymaze.py @@ -1,16 +1,43 @@ import math import numpy as np -from gymnasium import spaces - from gym_miniworld.entity import Box from gym_miniworld.math import gen_rot_matrix from gym_miniworld.miniworld import MiniWorldEnv +from gymnasium import spaces class YMaze(MiniWorldEnv): """ + ## Description + Two hallways connected in a Y-junction + + ## Action Space + + | Num | Action | + |-----|-----------------------------| + | 0 | turn left | + | 1 | turn right | + | 2 | move forward | + + ## Observation Space + + The observation space is an `ndarray` with shape `(obs_height, obs_width, 3)` + representing the view the agents sees. + + ## Rewards: + + +(1 - 0.2 * (step_count / max_episode_steps)) when box reached + + ## Arguments + + ```python + YMazeLeft() + # or + YMazeRight() + ``` + """ def __init__(self, goal_pos=None, **kwargs): diff --git a/scripts/benchmark.py b/scripts/benchmark.py index c25f0066..5c63c497 100755 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -2,6 +2,7 @@ import time +import gym_miniworld import gymnasium as gym # Benchmark loading time @@ -29,9 +30,9 @@ # Slow movement speed to minimize resets action = 0 - obs, reward, done, info = env.step(action) + obs, reward, termination, truncation, info = env.step(action) - if done: + if termination or truncation: env.reset() num_frames += 1 diff --git a/scripts/manual_control.py b/scripts/manual_control.py index 6b62d153..712eaf15 100755 --- a/scripts/manual_control.py +++ b/scripts/manual_control.py @@ -9,12 +9,11 @@ import math import sys +import gym_miniworld import gymnasium as gym import pyglet from pyglet.window import key -import gym_miniworld - parser = argparse.ArgumentParser() parser.add_argument("--env-name", default=gym_miniworld.envs.env_ids[0]) parser.add_argument( @@ -56,7 +55,7 @@ def step(action): if reward > 0: print(f"reward={reward:.2f}") - if termination: + if termination or truncation: print("done!") env.reset() @@ -78,7 +77,7 @@ def on_key_press(symbol, modifiers): if symbol == key.ESCAPE: env.close() - sys.exit(0) + # sys.exit(0) if symbol == key.UP: step(env.actions.move_forward) From 0e47e5acd5cd6e5a5b6948f4ac27a2d625ef6ee5 Mon Sep 17 00:00:00 2001 From: Bolun <36321182+BolunDai0216@users.noreply.github.com> Date: Sun, 30 Oct 2022 15:13:50 -0400 Subject: [PATCH 6/8] pass pre-commit --- gym_miniworld/envs/fourrooms.py | 3 ++- gym_miniworld/envs/hallway.py | 3 ++- gym_miniworld/envs/maze.py | 3 ++- gym_miniworld/envs/oneroom.py | 3 ++- gym_miniworld/envs/pickupobjs.py | 3 ++- gym_miniworld/envs/remotebot.py | 3 ++- gym_miniworld/envs/sidewalk.py | 3 ++- gym_miniworld/envs/sign.py | 5 +++-- gym_miniworld/envs/simtorealgoto.py | 3 ++- gym_miniworld/envs/simtorealpush.py | 3 ++- gym_miniworld/envs/threerooms.py | 3 ++- gym_miniworld/envs/tmaze.py | 3 ++- gym_miniworld/envs/wallgap.py | 3 ++- gym_miniworld/envs/ymaze.py | 3 ++- scripts/benchmark.py | 3 ++- scripts/manual_control.py | 7 +++++-- 16 files changed, 36 insertions(+), 18 deletions(-) diff --git a/gym_miniworld/envs/fourrooms.py b/gym_miniworld/envs/fourrooms.py index 407156c8..f676de02 100644 --- a/gym_miniworld/envs/fourrooms.py +++ b/gym_miniworld/envs/fourrooms.py @@ -1,6 +1,7 @@ +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class FourRooms(MiniWorldEnv): diff --git a/gym_miniworld/envs/hallway.py b/gym_miniworld/envs/hallway.py index 4e625188..4336c9ad 100644 --- a/gym_miniworld/envs/hallway.py +++ b/gym_miniworld/envs/hallway.py @@ -1,8 +1,9 @@ import math +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class Hallway(MiniWorldEnv): diff --git a/gym_miniworld/envs/maze.py b/gym_miniworld/envs/maze.py index d73313f4..5363686a 100644 --- a/gym_miniworld/envs/maze.py +++ b/gym_miniworld/envs/maze.py @@ -1,7 +1,8 @@ +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS -from gymnasium import spaces class Maze(MiniWorldEnv): diff --git a/gym_miniworld/envs/oneroom.py b/gym_miniworld/envs/oneroom.py index 260e92a3..9974f43d 100644 --- a/gym_miniworld/envs/oneroom.py +++ b/gym_miniworld/envs/oneroom.py @@ -1,7 +1,8 @@ +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS -from gymnasium import spaces class OneRoom(MiniWorldEnv): diff --git a/gym_miniworld/envs/pickupobjs.py b/gym_miniworld/envs/pickupobjs.py index ad294f27..5c38e915 100644 --- a/gym_miniworld/envs/pickupobjs.py +++ b/gym_miniworld/envs/pickupobjs.py @@ -1,6 +1,7 @@ +from gymnasium import spaces + from gym_miniworld.entity import Ball, Box, Key from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class PickupObjs(MiniWorldEnv): diff --git a/gym_miniworld/envs/remotebot.py b/gym_miniworld/envs/remotebot.py index bc48e505..45bf9d82 100644 --- a/gym_miniworld/envs/remotebot.py +++ b/gym_miniworld/envs/remotebot.py @@ -7,7 +7,6 @@ import numpy import numpy as np import pyglet -from gym_miniworld.miniworld import MiniWorldEnv from gymnasium import spaces # Try importing ZMQ @@ -22,6 +21,8 @@ glViewport, ) +from gym_miniworld.miniworld import MiniWorldEnv + try: import zmq except ImportError: diff --git a/gym_miniworld/envs/sidewalk.py b/gym_miniworld/envs/sidewalk.py index 332b004f..19bbd9e0 100644 --- a/gym_miniworld/envs/sidewalk.py +++ b/gym_miniworld/envs/sidewalk.py @@ -1,9 +1,10 @@ import math import numpy as np +from gymnasium import spaces + from gym_miniworld.entity import Box, MeshEnt from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class Sidewalk(MiniWorldEnv): diff --git a/gym_miniworld/envs/sign.py b/gym_miniworld/envs/sign.py index b028b511..fe944165 100644 --- a/gym_miniworld/envs/sign.py +++ b/gym_miniworld/envs/sign.py @@ -2,11 +2,12 @@ from typing import Optional, Tuple import gymnasium as gym +from gymnasium.core import ObsType +from gymnasium.spaces import Dict, Discrete + from gym_miniworld.entity import COLOR_NAMES, Box, Key, MeshEnt, TextFrame from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS -from gymnasium.core import ObsType -from gymnasium.spaces import Dict, Discrete class BigKey(Key): diff --git a/gym_miniworld/envs/simtorealgoto.py b/gym_miniworld/envs/simtorealgoto.py index 22f3915e..d59865bc 100644 --- a/gym_miniworld/envs/simtorealgoto.py +++ b/gym_miniworld/envs/simtorealgoto.py @@ -1,7 +1,8 @@ +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS -from gymnasium import spaces # Simulation parameters # These assume a robot about 15cm tall with a pi camera module v2 diff --git a/gym_miniworld/envs/simtorealpush.py b/gym_miniworld/envs/simtorealpush.py index d4fa3c56..f8bb9976 100644 --- a/gym_miniworld/envs/simtorealpush.py +++ b/gym_miniworld/envs/simtorealpush.py @@ -1,10 +1,11 @@ import math import numpy as np +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv from gym_miniworld.params import DEFAULT_PARAMS -from gymnasium import spaces # Simulation parameters # These assume a robot about 15cm tall with a pi camera module v2 diff --git a/gym_miniworld/envs/threerooms.py b/gym_miniworld/envs/threerooms.py index edd59cb9..8dbb5859 100644 --- a/gym_miniworld/envs/threerooms.py +++ b/gym_miniworld/envs/threerooms.py @@ -1,8 +1,9 @@ import math +from gymnasium import spaces + from gym_miniworld.entity import Ball, Box, ImageFrame, Key, MeshEnt from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class ThreeRooms(MiniWorldEnv): diff --git a/gym_miniworld/envs/tmaze.py b/gym_miniworld/envs/tmaze.py index 3741da6e..31d8f758 100644 --- a/gym_miniworld/envs/tmaze.py +++ b/gym_miniworld/envs/tmaze.py @@ -1,8 +1,9 @@ import math +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class TMaze(MiniWorldEnv): diff --git a/gym_miniworld/envs/wallgap.py b/gym_miniworld/envs/wallgap.py index a95c373d..6d953fba 100644 --- a/gym_miniworld/envs/wallgap.py +++ b/gym_miniworld/envs/wallgap.py @@ -1,9 +1,10 @@ import math import numpy as np +from gymnasium import spaces + from gym_miniworld.entity import Box, MeshEnt from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class WallGap(MiniWorldEnv): diff --git a/gym_miniworld/envs/ymaze.py b/gym_miniworld/envs/ymaze.py index 01eb9278..9b187843 100644 --- a/gym_miniworld/envs/ymaze.py +++ b/gym_miniworld/envs/ymaze.py @@ -1,10 +1,11 @@ import math import numpy as np +from gymnasium import spaces + from gym_miniworld.entity import Box from gym_miniworld.math import gen_rot_matrix from gym_miniworld.miniworld import MiniWorldEnv -from gymnasium import spaces class YMaze(MiniWorldEnv): diff --git a/scripts/benchmark.py b/scripts/benchmark.py index 5c63c497..17e96e84 100755 --- a/scripts/benchmark.py +++ b/scripts/benchmark.py @@ -2,9 +2,10 @@ import time -import gym_miniworld import gymnasium as gym +# import gym_miniworld + # Benchmark loading time st = time.time() env = gym.make("MiniWorld-Maze-v0") diff --git a/scripts/manual_control.py b/scripts/manual_control.py index 712eaf15..a04ed9fd 100755 --- a/scripts/manual_control.py +++ b/scripts/manual_control.py @@ -7,13 +7,16 @@ import argparse import math -import sys -import gym_miniworld import gymnasium as gym import pyglet from pyglet.window import key +import gym_miniworld + +# import sys + + parser = argparse.ArgumentParser() parser.add_argument("--env-name", default=gym_miniworld.envs.env_ids[0]) parser.add_argument( From 01473a885fb6cc9b033c4e0ef2c3d2387045e44f Mon Sep 17 00:00:00 2001 From: Bolun Dai Date: Thu, 3 Nov 2022 14:16:05 -0400 Subject: [PATCH 7/8] push test --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a8e71235..a831e10c 100644 --- a/README.md +++ b/README.md @@ -118,3 +118,4 @@ Alternatively, if this doesn't work, you can also try running MiniWorld with `xv ``` xvfb-run -a -s "-screen 0 1024x768x24 -ac +extension GLX +render -noreset" python3 your_script.py ``` + From 6d747e3ca0ee1793c241650d0a1dbe1fa04fa6c8 Mon Sep 17 00:00:00 2001 From: Bolun Dai Date: Thu, 3 Nov 2022 14:31:33 -0400 Subject: [PATCH 8/8] updated setup.py --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index edec8a4e..87df9f74 100644 --- a/setup.py +++ b/setup.py @@ -59,7 +59,7 @@ def get_version(): extras_require={"testing": ["pytest==7.0.1", "torch"]}, install_requires=[ "numpy>=1.18.0", - "pyglet>=1.5.11", + "pyglet==1.5.27", "gymnasium>=0.26.2", ], # Include textures and meshes in the package