Skip to content

Commit

Permalink
change gym rendering, fixes #48
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherhesse committed Jul 10, 2020
1 parent db0e7a7 commit 416821e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.10.4

* Support `render_mode` to gym environment and update docs to remove references to the confusing `render=True` option.

## 0.10.3

* fix render option for gym environment
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ import gym
env = gym.make("procgen:procgen-coinrun-v0", start_level=0, num_levels=1)
```

Since the gym environment is adapted from a gym3 environment, early calls to `reset()` are disallowed and the `render()` method does not do anything. To render the environment, pass `render=True`, which will send `render_mode="rgb_array"` to the environment constructor and wrap it in a `gym3.ViewerWrapper`.
Since the gym environment is adapted from a gym3 environment, early calls to `reset()` are disallowed and the `render()` method does not do anything. To render the environment, pass `render_mode="human"` to the constructor, which will send `render_mode="rgb_array"` to the environment constructor and wrap it in a `gym3.ViewerWrapper`. If you just want the frames instead of the window, pass `render_mode="rgb_array"`.

For the gym3 vectorized environment:

Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- qt=5.12.5 # conda-forge does not have 5.13.2 available
- pip
- pip:
- gym3==0.3.2
- gym3==0.3.3
- numpy==1.17.2
- gym==0.15.3
- filelock==3.0.10
2 changes: 1 addition & 1 deletion procgen/examples/random_agent_gym3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
print(f"step {step} reward {rew} first {first}")
if step > 0 and first:
break
step += 1
step += 1
16 changes: 14 additions & 2 deletions procgen/gym_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@
from .env import ENV_NAMES, ProcgenGym3Env


def make_env(render=False, **kwargs):
def make_env(render_mode=None, render=False, **kwargs):
# the render option is kept here for backwards compatibility
# users should use `render_mode="human"` or `render_mode="rgb_array"`
if render:
render_mode = "human"

use_viewer_wrapper = False
kwargs["render_mode"] = render_mode
if render_mode == "human":
# procgen does not directly support rendering a window
# instead it's handled by gym3's ViewerWrapper
# procgen only supports a render_mode of "rgb_array"
use_viewer_wrapper = True
kwargs["render_mode"] = "rgb_array"

env = ProcgenGym3Env(num=1, num_threads=0, **kwargs)
env = ExtractDictObWrapper(env, key="rgb")
if render:
if use_viewer_wrapper:
env = ViewerWrapper(env, tps=15, info_key="rgb")
gym_env = ToGymEnv(env)
return gym_env
Expand Down
2 changes: 1 addition & 1 deletion procgen/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.3
0.10.4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def run(self):
install_requires=[
"numpy>=1.17.0,<2.0.0",
"gym>=0.15.0,<1.0.0",
"gym3>=0.3.2,<1.0.0",
"gym3>=0.3.3,<1.0.0",
"filelock>=3.0.0,<4.0.0",
],
python_requires=">=3.6.0",
Expand Down

0 comments on commit 416821e

Please sign in to comment.