2024-04-10 21:06:48 +08:00
|
|
|
import importlib
|
2024-03-22 21:25:23 +08:00
|
|
|
import pytest
|
|
|
|
import lerobot
|
2024-04-10 21:06:48 +08:00
|
|
|
import gymnasium as gym
|
2024-03-22 21:25:23 +08:00
|
|
|
|
2024-04-17 22:40:40 +08:00
|
|
|
from lerobot.common.import_utils import is_package_available
|
2024-04-15 17:56:43 +08:00
|
|
|
from lerobot.common.policies.act.modeling_act import ActionChunkingTransformerPolicy
|
2024-04-16 02:06:44 +08:00
|
|
|
from lerobot.common.policies.diffusion.modeling_diffusion import DiffusionPolicy
|
2024-04-10 21:06:48 +08:00
|
|
|
from lerobot.common.policies.tdmpc.policy import TDMPCPolicy
|
2024-03-22 21:25:23 +08:00
|
|
|
|
|
|
|
|
2024-04-17 22:40:40 +08:00
|
|
|
@pytest.mark.parametrize("env_name, task_name", lerobot.env_task_pairs)
|
|
|
|
def test_available_env_task(env_name: str, task_name: list):
|
|
|
|
"""
|
|
|
|
This test verifies that all environments listed in `lerobot/__init__.py` can
|
|
|
|
be sucessfully imported if — they're installed — and that their
|
|
|
|
`available_tasks_per_env` are valid.
|
|
|
|
"""
|
|
|
|
package_name = f"gym_{env_name}"
|
|
|
|
if not is_package_available(package_name):
|
|
|
|
pytest.skip(f"gym-{env_name} not installed")
|
|
|
|
|
|
|
|
importlib.import_module(package_name)
|
|
|
|
gym_handle = f"{package_name}/{task_name}"
|
|
|
|
assert gym_handle in gym.envs.registry.keys(), gym_handle
|
|
|
|
|
|
|
|
|
|
|
|
def test_available_policies():
|
|
|
|
"""
|
|
|
|
This test verifies that the class attribute `name` for all policies is
|
|
|
|
consistent with those listed in `lerobot/__init__.py`.
|
|
|
|
"""
|
2024-04-10 21:06:48 +08:00
|
|
|
policy_classes = [
|
2024-04-15 17:56:43 +08:00
|
|
|
ActionChunkingTransformerPolicy,
|
2024-04-10 21:06:48 +08:00
|
|
|
DiffusionPolicy,
|
|
|
|
TDMPCPolicy,
|
|
|
|
]
|
|
|
|
policies = [pol_cls.name for pol_cls in policy_classes]
|
|
|
|
assert set(policies) == set(lerobot.available_policies), policies
|