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

Update env_checker.py #708

Merged
merged 4 commits into from
Sep 8, 2023
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
16 changes: 8 additions & 8 deletions gymnasium/utils/env_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def data_equivalence(data_1, data_2) -> bool:
return False


def check_reset_seed(env: gym.Env):
def check_reset_seed(env: gym.Env) -> None:
"""Check that the environment can be reset with a seed.

Args:
Expand Down Expand Up @@ -132,7 +132,7 @@ def check_reset_seed(env: gym.Env):
)


def check_reset_options(env: gym.Env):
def check_reset_options(env: gym.Env) -> None:
"""Check that the environment can be reset with options.

Args:
Expand Down Expand Up @@ -160,7 +160,7 @@ def check_reset_options(env: gym.Env):
)


def check_reset_return_info_deprecation(env: gym.Env):
def check_reset_return_info_deprecation(env: gym.Env) -> None:
"""Makes sure support for deprecated `return_info` argument is dropped.

Args:
Expand All @@ -177,7 +177,7 @@ def check_reset_return_info_deprecation(env: gym.Env):
)


def check_seed_deprecation(env: gym.Env):
def check_seed_deprecation(env: gym.Env) -> None:
"""Makes sure support for deprecated function `seed` is dropped.

Args:
Expand All @@ -193,7 +193,7 @@ def check_seed_deprecation(env: gym.Env):
)


def check_reset_return_type(env: gym.Env):
def check_reset_return_type(env: gym.Env) -> None:
"""Checks that :meth:`reset` correctly returns a tuple of the form `(obs , info)`.

Args:
Expand All @@ -218,7 +218,7 @@ def check_reset_return_type(env: gym.Env):
), f"The second element returned by `env.reset()` was not a dictionary, actual type: {type(info)}"


def check_space_limit(space, space_type: str):
def check_space_limit(space: spaces.Space, space_type: str) -> None:
"""Check the space limit for only the Box space as a test that only runs as part of `check_env`."""
if isinstance(space, spaces.Box):
if np.any(np.equal(space.low, -np.inf)):
Expand All @@ -227,7 +227,7 @@ def check_space_limit(space, space_type: str):
)
if np.any(np.equal(space.high, np.inf)):
logger.warn(
f"A Box {space_type} space maximum value is -infinity. This is probably too high."
f"A Box {space_type} space maximum value is infinity. This is probably too high."
)

# Check that the Box space is normalized
Expand Down Expand Up @@ -256,7 +256,7 @@ def check_space_limit(space, space_type: str):
check_space_limit(subspace, space_type)


def check_env(env: gym.Env, warn: bool = None, skip_render_check: bool = False):
def check_env(env: gym.Env, warn: bool = None, skip_render_check: bool = False) -> None:
"""Check that an environment follows Gym API.

This is an invasive function that calls the environment's reset and step.
Expand Down
2 changes: 1 addition & 1 deletion tests/envs/mujoco/test_mujoco_custom_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _get_reset_info(self):
f"\x1b[33mWARN: {message}\x1b[0m"
for message in [
"A Box observation space minimum value is -infinity. This is probably too low.",
"A Box observation space maximum value is -infinity. This is probably too high.",
"A Box observation space maximum value is infinity. This is probably too high.",
"For Box action spaces, we recommend using a symmetric and normalized space (range=[-1, 1] or [0, 1]). See https://stable-baselines3.readthedocs.io/en/master/guide/rl_tips.html for more information.",
]
]
Expand Down
2 changes: 1 addition & 1 deletion tests/envs/mujoco/test_mujoco_v5.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_verify_reward_survive(env_name: str, version: str):
f"\x1b[33mWARN: {message}\x1b[0m"
for message in [
"A Box observation space minimum value is -infinity. This is probably too low.",
"A Box observation space maximum value is -infinity. This is probably too high.",
"A Box observation space maximum value is infinity. This is probably too high.",
"For Box action spaces, we recommend using a symmetric and normalized space (range=[-1, 1] or [0, 1]). See https://stable-baselines3.readthedocs.io/en/master/guide/rl_tips.html for more information.",
]
]
Expand Down
2 changes: 1 addition & 1 deletion tests/envs/test_envs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
for message in [
"This version of the mujoco environments depends on the mujoco-py bindings, which are no longer maintained and may stop working. Please upgrade to the v4 versions of the environments (which depend on the mujoco python bindings instead), unless you are trying to precisely replicate previous works).",
"A Box observation space minimum value is -infinity. This is probably too low.",
"A Box observation space maximum value is -infinity. This is probably too high.",
"A Box observation space maximum value is infinity. This is probably too high.",
"For Box action spaces, we recommend using a symmetric and normalized space (range=[-1, 1] or [0, 1]). See https://stable-baselines3.readthedocs.io/en/master/guide/rl_tips.html for more information.",
]
]
Expand Down