7f39abb613
Add declarative single-leg import, fixed-anchor benchmark, masked shared-policy PPO prototype, regression tests, and consolidated documentation.
88 lines
3.6 KiB
Python
88 lines
3.6 KiB
Python
"""Contract tests; opt into fresh Kit integration runs with ANCHOR_RUNTIME_TESTS=1."""
|
|
|
|
import importlib.util
|
|
import json
|
|
import os
|
|
import runpy
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).parents[1]
|
|
|
|
|
|
def test_metadata_schema(tmp_path):
|
|
spec = importlib.util.spec_from_file_location("extract_schema", ROOT / "scripts/assets/extract_go2_leg.py")
|
|
extractor = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(extractor)
|
|
manifest = extractor.extract(extractor.DEFAULT_SOURCE, tmp_path / "asset")
|
|
assert manifest["schema_version"] == 1
|
|
assert manifest["interface"]["policy_shape"] == ["B", 19]
|
|
assert manifest["interface"]["action_shape"] == ["B", 3]
|
|
assert manifest["interface"]["quaternion_order"] == "xyzw"
|
|
assert manifest["control"]["physics_dt"] == 0.002
|
|
assert manifest["control"]["decimation"] == 5
|
|
assert [j["limits"]["effort"] for j in manifest["joints"]] == [23.7, 23.7, 45.43]
|
|
assert [j["limits"]["velocity"] for j in manifest["joints"]] == [30.1, 30.1, 15.7]
|
|
assert all(len(v["origin"]["xyz"]) == 3 for v in manifest["links"].values() if v is not None)
|
|
|
|
|
|
def test_task_registration_preserves_template():
|
|
import gymnasium as gym
|
|
import SkillFactory.tasks # noqa: F401
|
|
|
|
ids = ["Template-Skillfactory-v0", "SkillFactory-SingleLegAnchor-Go2-v0"]
|
|
for task in ids:
|
|
spec = gym.spec(task)
|
|
assert spec.entry_point == "isaaclab.envs:ManagerBasedRLEnv"
|
|
assert spec.kwargs["env_cfg_entry_point"].startswith("SkillFactory.")
|
|
generic = gym.spec("SkillFactory-LegSkill-v0")
|
|
assert generic.entry_point == "SkillFactory.tasks.manager_based.leg_skill.leg_env:LegSkillEnv"
|
|
|
|
|
|
def test_packaging_discovers_task_subpackages(monkeypatch):
|
|
import setuptools
|
|
|
|
captured = {}
|
|
monkeypatch.setattr(setuptools, "setup", lambda **kwargs: captured.update(kwargs))
|
|
monkeypatch.chdir(ROOT / "source/SkillFactory")
|
|
runpy.run_path(str(ROOT / "source/SkillFactory/setup.py"))
|
|
prefix = "SkillFactory.tasks.manager_based.single_leg_anchor"
|
|
assert prefix in captured["packages"]
|
|
assert prefix + ".mdp" in captured["packages"]
|
|
assert "SkillFactory.assets" in captured["packages"]
|
|
assert "SkillFactory.legs" in captured["packages"]
|
|
assert "SkillFactory.tasks.manager_based.leg_skill" in captured["packages"]
|
|
assert captured["package_data"]["SkillFactory.legs"] == ["resources/*.usda"]
|
|
assert (ROOT / "source/SkillFactory/SkillFactory/legs/resources/ground.usda").is_file()
|
|
|
|
|
|
@pytest.mark.skipif(os.environ.get("ANCHOR_RUNTIME_TESTS") != "1", reason="Opt-in Kit/CUDA integration")
|
|
@pytest.mark.parametrize("num_envs", [1, 16, 64])
|
|
def test_cuda_contract(num_envs, tmp_path):
|
|
env = dict(os.environ)
|
|
env["PYTHONPATH"] = str(ROOT / "source/SkillFactory") + os.pathsep + env.get("PYTHONPATH", "")
|
|
with (tmp_path / "runtime.log").open("w") as log:
|
|
result = subprocess.run(
|
|
[
|
|
sys.executable,
|
|
str(ROOT / "scripts/verify_anchor.py"),
|
|
"--suite",
|
|
"contract",
|
|
"--num_envs",
|
|
str(num_envs),
|
|
"--output",
|
|
str(tmp_path / "report"),
|
|
"--headless",
|
|
],
|
|
cwd=ROOT,
|
|
env=env,
|
|
stdout=log,
|
|
stderr=subprocess.STDOUT,
|
|
)
|
|
assert result.returncode == 0, (tmp_path / "runtime.log").read_text()[-4000:]
|
|
report = json.loads((tmp_path / "report/result.json").read_text())
|
|
assert report["passed"] and report["contract"]["policy_shape"] == [num_envs, 19]
|