Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
94 commits
Select commit Hold shift + click to select a range
1aa736b
add pygame GUI for frozen_lake.py env
younik Jan 21, 2022
73a9e6b
add new line at EOF
younik Jan 21, 2022
c9a359a
pre-commit reformat
younik Jan 24, 2022
354830c
improve graphics
younik Jan 28, 2022
95258f5
new images and dynamic window size
younik Feb 1, 2022
a121b7b
darker tile borders and fix ICC profile
younik Feb 2, 2022
91f3a03
pre-commit hook
younik Feb 2, 2022
6f56feb
adjust elf and stool size
younik Feb 3, 2022
0abec2f
Update frozen_lake.py
jkterry1 Feb 3, 2022
ad87dbc
reformat
younik Feb 5, 2022
48c22fe
Merge branch 'openai:master' into master
younik Feb 7, 2022
6c38481
fix #2600
younik Feb 7, 2022
2649a1c
#2600
younik Feb 7, 2022
c2da74a
add rgb_array support
younik Feb 8, 2022
45a3154
reformat
younik Feb 8, 2022
db9ba2f
Merge branch 'master' into master
younik Feb 10, 2022
9711282
test render api change on FrozenLake
younik Mar 4, 2022
cd85df4
add render support for reset on frozenlake
younik Mar 5, 2022
1beba40
Merge branch 'render_api'
younik Mar 5, 2022
15d9321
add clock on pygame render
younik Mar 5, 2022
3089e57
new render api for blackjack
younik Mar 5, 2022
fad0f6f
new render api for cliffwalking
younik Mar 5, 2022
ffd9fc8
new render api for Env class
younik Mar 5, 2022
5140dc9
update reset method, lunar and Env
younik Mar 5, 2022
311ac82
fix wrapper
younik Mar 5, 2022
1197a36
fix reset lunar
younik Mar 5, 2022
da77145
new render api for box2d envs
younik Mar 5, 2022
18fe379
new render api for mujoco envs
younik Mar 6, 2022
d586394
fix bug
younik Mar 6, 2022
b078647
new render api for classic control envs
younik Mar 6, 2022
415449c
fix tests
younik Mar 9, 2022
9363aa0
add render_mode None for CartPole
younik Mar 10, 2022
11ab948
Merge branch 'master' into master
younik Mar 10, 2022
4912778
new render api for test fake envs
younik Mar 10, 2022
d5107d4
Merge remote-tracking branch 'origin/master'
younik Mar 10, 2022
98ab069
pre-commit hook
younik Mar 10, 2022
e06d293
fix FrozenLake
younik Mar 10, 2022
6fab5a2
fix FrozenLake
younik Mar 10, 2022
0f970ff
more render_mode to super - frozenlake
younik Mar 11, 2022
9999527
Merge remote-tracking branch 'origin/master'
younik Mar 11, 2022
f945184
Merge branch 'master' into master
younik Mar 11, 2022
4771755
remove kwargs from frozen_lake new
younik Mar 11, 2022
b458f4f
Merge remote-tracking branch 'origin/master'
younik Mar 11, 2022
1f5ddf1
pre-commit hook
younik Mar 11, 2022
96b3a7a
solve conflicts
younik Mar 17, 2022
64dcf77
add deprecated render method
younik Mar 23, 2022
5601778
Merge branch 'master' into master
younik Apr 2, 2022
cffacd7
Merge remote-tracking branch 'origin/master'
younik Apr 2, 2022
9570f30
add backwards compatibility
younik Apr 4, 2022
4345b21
fix test
younik Apr 4, 2022
99c6680
add _render
younik Apr 5, 2022
8ad9ed7
Merge branch 'master' into master
younik Apr 8, 2022
765c014
move pygame.init() (avoid pygame dependency on init)
younik Apr 8, 2022
45cbabd
fix pygame dependencies
younik Apr 8, 2022
7b13622
Merge branch 'master' into master
younik Apr 9, 2022
f53aa27
remove collect_render() maintain multi-behaviours .render()
younik Apr 19, 2022
4d76fe1
Merge remote-tracking branch 'origin/master'
younik Apr 19, 2022
2ab1824
Merge branch 'master' into master
younik Apr 19, 2022
343f72a
add type hints
younik Apr 21, 2022
c4bfe84
fix renderer
younik Apr 21, 2022
2b0ca9a
don't call .render() with None
younik Apr 21, 2022
0869ee7
improve docstring
younik Apr 21, 2022
d08b80d
add single_rgb_array to all envs
younik Apr 25, 2022
c7156bd
remove None from metadata["render_modes"]
younik Apr 25, 2022
e8e3c26
Merge branch 'master' into master
younik Apr 25, 2022
3a2f9b6
add type hints to test_env_checkers
younik Apr 25, 2022
a3ac176
Merge remote-tracking branch 'origin/master'
younik Apr 25, 2022
66b0c23
fix lint
younik Apr 25, 2022
ff4aff3
add comments to renderer
younik Apr 26, 2022
e0753ef
add comments to single_depth_array and single_state_pixels
younik Apr 30, 2022
3a961a3
Merge branch 'master' into master
younik Apr 30, 2022
07cf336
reformat
younik Apr 30, 2022
694220d
add deprecation warnings and env.render_mode declaration
younik May 7, 2022
9d04c6a
fix lint
younik May 7, 2022
52268f9
reformat
younik May 7, 2022
a0a409f
fix tests
younik May 7, 2022
d319228
Merge branch 'master' of https://github.com/openai/gym
younik May 23, 2022
ba01803
add docs
younik May 23, 2022
ce8d471
fix car racing determinism
younik May 23, 2022
f6a0c42
remove warning test envs, customizable modes on renderer
younik Jun 2, 2022
11d2260
remove commments and add todo for env_checker
younik Jun 3, 2022
7efffb8
fix car racing
younik Jun 3, 2022
5fe6e80
replace render mode check with assert
younik Jun 3, 2022
e4dc18c
Merge remote-tracking branch 'openai-gym/master'
younik Jun 3, 2022
0a979cc
update new mujoco
younik Jun 3, 2022
69326af
reformat
younik Jun 3, 2022
c220b4a
Merge remote-tracking branch 'openai-gym/master'
younik Jun 3, 2022
efda297
reformat
younik Jun 3, 2022
edb2c7a
change metaclass definition
younik Jun 4, 2022
88da572
Merge remote-tracking branch 'openai-gym/master'
younik Jun 4, 2022
540019c
fix tests
younik Jun 5, 2022
6c55c7b
implement mark suggestions (test, docs, sets)
younik Jun 6, 2022
34b8d08
Merge remote-tracking branch 'openai-gym/master'
younik Jun 6, 2022
bdb3220
check_render
younik Jun 6, 2022
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
Prev Previous commit
Next Next commit
implement mark suggestions (test, docs, sets)
  • Loading branch information
younik committed Jun 6, 2022
commit 6c55c7bb53af6bece1e97f4828d43f033e3cb05c
8 changes: 6 additions & 2 deletions gym/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@


class _EnvDecorator(type): # TODO: remove with gym 1.0
"""Metaclass used for adding deprecation warning to the mode kwarg in the render method."""

def __new__(cls, name, bases, attr):
if "render" in attr.keys():
attr["render"] = _EnvDecorator._deprecate_mode(attr["render"])
Expand Down Expand Up @@ -190,8 +192,10 @@ def render(self, mode="human") -> Optional[Union[RenderFrame, List[RenderFrame]]
- None (default): no render is computed.
- human: render return None.
The environment is continuously rendered in the current display or terminal. Usually for human consumption.
- rgb_array: Return a list of frames. Each frame is a numpy.ndarray with shape (x, y, 3),
representing RGB values for an x-by-y pixel image.
- single_rgb_array: return a single frame representing the current state of the environment.
A frame is a numpy.ndarray with shape (x, y, 3) representing RGB values for an x-by-y pixel image.
- rgb_array: return a list of frames representing the states of the environment since the last reset.
Each frame is a numpy.ndarray with shape (x, y, 3), as with single_rgb_array.
- ansi: Return a list of strings (str) or StringIO.StringIO containing a
terminal-style text representation for each time step.
The text can include newlines and ANSI escape sequences (e.g. for colors).
Expand Down
10 changes: 5 additions & 5 deletions gym/envs/box2d/bipedal_walker.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,17 +671,17 @@ def _render(self, mode: str = "human"):
self.lidar_render = (self.lidar_render + 1) % 100
i = self.lidar_render
if i < 2 * len(self.lidar):
l = (
single_lidar = (
self.lidar[i]
if i < len(self.lidar)
else self.lidar[len(self.lidar) - i - 1]
)
if hasattr(l, "p1") and hasattr(l, "p2"):
if hasattr(single_lidar, "p1") and hasattr(single_lidar, "p2"):
pygame.draw.line(
self.surf,
color=(255, 0, 0),
start_pos=(l.p1[0] * SCALE, l.p1[1] * SCALE),
end_pos=(l.p2[0] * SCALE, l.p2[1] * SCALE),
start_pos=(single_lidar.p1[0] * SCALE, single_lidar.p1[1] * SCALE),
end_pos=(single_lidar.p2[0] * SCALE, single_lidar.p2[1] * SCALE),
width=1,
)

Expand Down Expand Up @@ -742,7 +742,7 @@ def _render(self, mode: str = "human"):
pygame.event.pump()
self.clock.tick(self.metadata["render_fps"])
pygame.display.flip()
elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.surf)), axes=(1, 0, 2)
)
Expand Down
4 changes: 2 additions & 2 deletions gym/envs/box2d/car_racing.py
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,9 @@ def _render(self, mode: str = "human"):
self.screen.blit(self.surf, (0, 0))
pygame.display.flip()

if mode in ["rgb_array", "single_rgb_array"]:
if mode in {"rgb_array", "single_rgb_array"}:
return self._create_image_array(self.surf, (VIDEO_W, VIDEO_H))
elif mode in ["state_pixels", "single_state_pixels"]:
elif mode in {"state_pixels", "single_state_pixels"}:
return self._create_image_array(self.surf, (STATE_W, STATE_H))
else:
return self.isopen
Expand Down
2 changes: 1 addition & 1 deletion gym/envs/box2d/lunar_lander.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ def _render(self, mode="human"):
pygame.event.pump()
self.clock.tick(self.metadata["render_fps"])
pygame.display.flip()
elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.surf)), axes=(1, 0, 2)
)
Expand Down
4 changes: 2 additions & 2 deletions gym/envs/classic_control/acrobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ def _render(self, mode="human"):
self.screen = pygame.display.set_mode(
(self.SCREEN_DIM, self.SCREEN_DIM)
)
else: # mode in ["rgb_array", "single_rgb_array"]
else: # mode in {"rgb_array", "single_rgb_array"}
self.screen = pygame.Surface((self.SCREEN_DIM, self.SCREEN_DIM))
if self.clock is None:
self.clock = pygame.time.Clock()
Expand Down Expand Up @@ -365,7 +365,7 @@ def _render(self, mode="human"):
self.clock.tick(self.metadata["render_fps"])
pygame.display.flip()

elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.screen)), axes=(1, 0, 2)
)
Expand Down
4 changes: 2 additions & 2 deletions gym/envs/classic_control/cartpole.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _render(self, mode="human"):
self.screen = pygame.display.set_mode(
(self.screen_width, self.screen_height)
)
else: # mode in ["rgb_array", "single_rgb_array"]
else: # mode in {"rgb_array", "single_rgb_array"}
self.screen = pygame.Surface((self.screen_width, self.screen_height))
if self.clock is None:
self.clock = pygame.time.Clock()
Expand Down Expand Up @@ -295,7 +295,7 @@ def _render(self, mode="human"):
self.clock.tick(self.metadata["render_fps"])
pygame.display.flip()

elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.screen)), axes=(1, 0, 2)
)
Expand Down
4 changes: 2 additions & 2 deletions gym/envs/classic_control/continuous_mountain_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def _render(self, mode="human"):
self.screen = pygame.display.set_mode(
(self.screen_width, self.screen_height)
)
else: # mode in ["rgb_array", "single_rgb_array"]
else: # mode in {"rgb_array", "single_rgb_array"}
self.screen = pygame.Surface((self.screen_width, self.screen_height))
if self.clock is None:
self.clock = pygame.time.Clock()
Expand Down Expand Up @@ -290,7 +290,7 @@ def _render(self, mode="human"):
self.clock.tick(self.metadata["render_fps"])
pygame.display.flip()

elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.screen)), axes=(1, 0, 2)
)
Expand Down
4 changes: 2 additions & 2 deletions gym/envs/classic_control/mountain_car.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _render(self, mode="human"):
self.screen = pygame.display.set_mode(
(self.screen_width, self.screen_height)
)
else: # mode in ["rgb_array", "single_rgb_array"]
else: # mode in {"rgb_array", "single_rgb_array"}
self.screen = pygame.Surface((self.screen_width, self.screen_height))
if self.clock is None:
self.clock = pygame.time.Clock()
Expand Down Expand Up @@ -263,7 +263,7 @@ def _render(self, mode="human"):
self.clock.tick(self.metadata["render_fps"])
pygame.display.flip()

elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.screen)), axes=(1, 0, 2)
)
Expand Down
2 changes: 1 addition & 1 deletion gym/envs/classic_control/pendulum.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def _render(self, mode="human"):
self.screen = pygame.display.set_mode(
(self.screen_dim, self.screen_dim)
)
else: # mode in ["rgb_array", "single_rgb_array"]
else: # mode in {"rgb_array", "single_rgb_array"}
self.screen = pygame.Surface((self.screen_dim, self.screen_dim))
if self.clock is None:
self.clock = pygame.time.Clock()
Expand Down
6 changes: 3 additions & 3 deletions gym/envs/toy_text/frozen_lake.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def _render(self, mode="human"):
assert mode in self.metadata["render_modes"]
if mode == "ansi":
return self._render_text()
elif mode in ["human", "rgb_array", "single_rgb_array"]:
elif mode in {"human", "rgb_array", "single_rgb_array"}:
return self._render_gui(mode)

def _render_gui(self, mode):
Expand All @@ -287,7 +287,7 @@ def _render_gui(self, mode):
pygame.display.set_caption("Frozen Lake")
if mode == "human":
self.window_surface = pygame.display.set_mode(self.window_size)
elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
self.window_surface = pygame.Surface(self.window_size)
if self.clock is None:
self.clock = pygame.time.Clock()
Expand Down Expand Up @@ -378,7 +378,7 @@ def _render_gui(self, mode):
pygame.event.pump()
pygame.display.update()
self.clock.tick(self.metadata["render_fps"])
elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.window_surface)), axes=(1, 0, 2)
)
Expand Down
6 changes: 3 additions & 3 deletions gym/envs/toy_text/taxi.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _render(self, mode):
assert mode in self.metadata["render_modes"]
if mode == "ansi":
return self._render_text()
elif mode in ["human", "rgb_array", "single_rgb_array"]:
elif mode in {"human", "rgb_array", "single_rgb_array"}:
return self._render_gui(mode)

def _render_gui(self, mode):
Expand All @@ -268,7 +268,7 @@ def _render_gui(self, mode):
pygame.display.set_caption("Taxi")
if mode == "human":
self.window = pygame.display.set_mode(WINDOW_SIZE)
elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
self.window = pygame.Surface(WINDOW_SIZE)
if self.clock is None:
self.clock = pygame.time.Clock()
Expand Down Expand Up @@ -376,7 +376,7 @@ def _render_gui(self, mode):
if mode == "human":
pygame.display.update()
self.clock.tick(self.metadata["render_fps"])
elif mode in ["rgb_array", "single_rgb_array"]:
elif mode in {"rgb_array", "single_rgb_array"}:
return np.transpose(
np.array(pygame.surfarray.pixels3d(self.window)), axes=(1, 0, 2)
)
Expand Down
15 changes: 15 additions & 0 deletions tests/envs/test_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ def test_reset_info(spec):
env.close()


@pytest.mark.parametrize(
"spec", spec_list_no_mujoco_py, ids=[spec.id for spec in spec_list_no_mujoco_py]
)
def test_render_modes(spec):
env = spec.make()

for mode in env.metadata.get("render_modes", []):
if mode != "human":
new_env = spec.make(render_mode=mode)

new_env.reset()
new_env.step(new_env.action_space.sample())
new_env.render()


def test_env_render_result_is_immutable():
environs = [
envs.make("Taxi-v3", render_mode="ansi"),
Expand Down