-
-
Notifications
You must be signed in to change notification settings - Fork 935
/
Copy pathutils.py
55 lines (48 loc) · 1.78 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""Finds all the specs that we can test with"""
from typing import List, Optional
import gymnasium as gym
from gymnasium import logger
from gymnasium.envs.registration import EnvSpec
def try_make_env(env_spec: EnvSpec) -> Optional[gym.Env]:
"""Tries to make the environment showing if it is possible.
Warning the environments have no wrappers, including time limit and order enforcing.
"""
# To avoid issues with registered environments during testing, we check that the spec entry points are from gymnasium.envs.
if (
isinstance(env_spec.entry_point, str)
and "gymnasium.envs." in env_spec.entry_point
):
try:
return env_spec.make(disable_env_checker=True).unwrapped
except (
ImportError,
AttributeError,
gym.error.DependencyNotInstalled,
gym.error.MissingArgument,
) as e:
logger.warn(f"Not testing {env_spec.id} due to error: {e}")
return None
# Tries to make all environment to test with
all_testing_initialised_envs: List[Optional[gym.Env]] = [
try_make_env(env_spec) for env_spec in gym.envs.registry.values()
]
all_testing_initialised_envs: List[gym.Env] = [
env for env in all_testing_initialised_envs if env is not None
]
# All testing, mujoco and gymnasium environment specs
all_testing_env_specs: List[EnvSpec] = [
env.spec for env in all_testing_initialised_envs
]
mujoco_testing_env_specs: List[EnvSpec] = [
env_spec
for env_spec in all_testing_env_specs
if "gymnasium.envs.mujoco" in env_spec.entry_point
]
gym_testing_env_specs: List[EnvSpec] = [
env_spec
for env_spec in all_testing_env_specs
if any(
f"gymnasium.envs.{ep}" in env_spec.entry_point
for ep in ["box2d", "classic_control", "toy_text"]
)
]