Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToGymEnv.reset to respect Gym.Env.reset signature #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 16 additions & 6 deletions gym3/interop.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _assert_num_envs_1(ac):
class FromGymEnv(Env):
"""
Create a gym3 environment from a gym environment.

Notes:
* low/high values for continuous spaces will be discarded since gym3 does not support these
* some spaces are not supported
Expand Down Expand Up @@ -182,7 +182,7 @@ class FromBaselinesVecEnv(Env):
"""
Create a gym3 environment from a baselines VecEnv environment. baselines VecEnv is rarely used outside
of the baselines code, and is not recommended for new environments.

Notes:
* low/high values for continuous spaces will be discarded since gym3 does not support these
* `callmethod()` will call methods on the underlying VecEnv environment
Expand Down Expand Up @@ -252,7 +252,7 @@ class ToGymEnv:
* `seed()` and `close() are ignored since gym3 environments do not require these methods
* `reset()` is ignored if used before an episode is complete because gym3 environments
reset automatically, if `reset()` was called before the end of an episode, a warning is printed

:param env: gym3 environment to adapt
"""

Expand All @@ -265,7 +265,17 @@ def __init__(self, env):
self.reward_range = (-float("inf"), float("inf"))
self.spec = None

def reset(self):
def reset(
self,
*,
seed: int | None = None,
options: Dict[str, Any] | None = None,
) -> Tuple["gym.core.ObsType", Dict[str, Any]]:
if seed is not None:
print("Warning: seed ignored")
if options is not None:
print("Warning: options ignored")

_rew, ob, first = self.env.observe()
if not first[0]:
print("Warning: early reset ignored")
Expand Down Expand Up @@ -362,9 +372,9 @@ def vectorize_gym(
to call:

env = vectorize_gym(num=2, env_kwargs={"id": "Pendulum-v0"})

:param num: number of gym environments to create
:param env_fn: function to call to create the gym environment, defaults to `gym.make`
:param env_fn: function to call to create the gym environment, defaults to `gym.make`
:param env_kwargs: keyword arguments to pass to env_fn
:param use_subproc: if set to False, create the environment in the current process
:param render_mode: if set, this will be passed to the `FromGymEnv` adapter,
Expand Down