2022-06-16 14:29:13 +01:00
|
|
|
"""Finds all the specs that we can test with"""
|
2024-06-10 17:07:47 +01:00
|
|
|
|
2022-07-04 18:19:25 +01:00
|
|
|
from typing import List, Optional
|
2022-06-16 14:29:13 +01:00
|
|
|
|
2022-09-16 23:41:27 +01:00
|
|
|
import gymnasium as gym
|
|
|
|
from gymnasium import logger
|
2022-09-08 10:10:07 +01:00
|
|
|
from gymnasium.envs.registration import EnvSpec
|
2022-06-16 14:29:13 +01:00
|
|
|
|
|
|
|
|
2022-09-16 23:41:27 +01:00
|
|
|
def try_make_env(env_spec: EnvSpec) -> Optional[gym.Env]:
|
2022-07-11 02:45:24 +01:00
|
|
|
"""Tries to make the environment showing if it is possible.
|
|
|
|
|
|
|
|
Warning the environments have no wrappers, including time limit and order enforcing.
|
|
|
|
"""
|
2022-09-08 10:10:07 +01:00
|
|
|
# To avoid issues with registered environments during testing, we check that the spec entry points are from gymnasium.envs.
|
2023-01-20 14:26:37 +00:00
|
|
|
if (
|
|
|
|
isinstance(env_spec.entry_point, str)
|
|
|
|
and "gymnasium.envs." in env_spec.entry_point
|
|
|
|
):
|
2022-07-11 02:45:24 +01:00
|
|
|
try:
|
|
|
|
return env_spec.make(disable_env_checker=True).unwrapped
|
2022-10-20 11:30:14 +02:00
|
|
|
except (
|
|
|
|
ImportError,
|
2023-05-16 10:32:30 +02:00
|
|
|
AttributeError,
|
2022-10-20 11:30:14 +02:00
|
|
|
gym.error.DependencyNotInstalled,
|
|
|
|
gym.error.MissingArgument,
|
|
|
|
) as e:
|
2022-07-11 02:45:24 +01:00
|
|
|
logger.warn(f"Not testing {env_spec.id} due to error: {e}")
|
|
|
|
return None
|
2022-06-16 14:29:13 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Tries to make all environment to test with
|
2022-09-16 23:41:27 +01:00
|
|
|
all_testing_initialised_envs: List[Optional[gym.Env]] = [
|
|
|
|
try_make_env(env_spec) for env_spec in gym.envs.registry.values()
|
2022-07-04 18:19:25 +01:00
|
|
|
]
|
2022-09-16 23:41:27 +01:00
|
|
|
all_testing_initialised_envs: List[gym.Env] = [
|
2022-07-04 18:19:25 +01:00
|
|
|
env for env in all_testing_initialised_envs if env is not None
|
|
|
|
]
|
2022-06-16 14:29:13 +01:00
|
|
|
|
2022-09-08 10:10:07 +01:00
|
|
|
# All testing, mujoco and gymnasium environment specs
|
2022-07-04 18:19:25 +01:00
|
|
|
all_testing_env_specs: List[EnvSpec] = [
|
|
|
|
env.spec for env in all_testing_initialised_envs
|
|
|
|
]
|
|
|
|
mujoco_testing_env_specs: List[EnvSpec] = [
|
2022-06-16 14:29:13 +01:00
|
|
|
env_spec
|
|
|
|
for env_spec in all_testing_env_specs
|
2022-09-08 10:10:07 +01:00
|
|
|
if "gymnasium.envs.mujoco" in env_spec.entry_point
|
2022-06-16 14:29:13 +01:00
|
|
|
]
|
2022-07-04 18:19:25 +01:00
|
|
|
gym_testing_env_specs: List[EnvSpec] = [
|
2022-06-16 14:29:13 +01:00
|
|
|
env_spec
|
|
|
|
for env_spec in all_testing_env_specs
|
|
|
|
if any(
|
2022-09-08 10:10:07 +01:00
|
|
|
f"gymnasium.envs.{ep}" in env_spec.entry_point
|
2022-06-16 14:29:13 +01:00
|
|
|
for ep in ["box2d", "classic_control", "toy_text"]
|
|
|
|
)
|
|
|
|
]
|