Download tests/test_release.py from MacroSwan/cablepilot: direct link, hf CLI and curl.
- Browser
- Download file 2.47 kB
-
https://huggingface.co/MacroSwan/cablepilot/resolve/main/tests/test_release.py
- Command line
-
hf download hf://MacroSwan/cablepilot/tests/test_release.py
-
curl -L -o test_release.py https://huggingface.co/MacroSwan/cablepilot/resolve/main/tests/test_release.py
2.47 kB
| """The release's own promises: cards load and check, tunings cannot reach the model, the model runs, the doctor works.""" | |
| from pathlib import Path | |
| import numpy as np | |
| import pytest | |
| from cablepilot.cardrun import SkillGap, apply_tuning, check | |
| from cablepilot.core.cards import CardError, load_card_text | |
| ROOT = Path(__file__).resolve().parents[1] | |
| CARD = """ | |
| task: t | |
| lineage: {parent: x, by: y, why: z} | |
| roles: [hand, head_camera] | |
| objects: | |
| a: {kind: toy, role: held, shape: block, movable: true} | |
| b: {kind: box, role: site, shape: open_container, movable: false} | |
| parts: | |
| b.interior: {of: b, part: interior} | |
| stages: | |
| - {name: s1, goals: [{pre_grasp: [hand, a]}]} | |
| - {name: s2, goals: [{grasp: [hand, a]}]} | |
| - {name: s3, goals: [{pre_inside: [a, b.interior]}]} | |
| - {name: s4, goals: [{release: [hand, a]}]} | |
| done: {inside: [a, b.interior]} | |
| """ | |
| def test_card_checks_and_lineage(): | |
| c = load_card_text(CARD) | |
| assert c.lineage == {"parent": "x", "by": "y", "why": "z"} | |
| assert [s for _, s in check(c)["stages"]] == ["approach", "grasp", "carry_over", "release"] | |
| assert "lineage" in c.to_dict() | |
| def test_lineage_keys_are_closed(): | |
| with pytest.raises(CardError): | |
| load_card_text(CARD.replace("why: z", "why: z, run: rm")) | |
| def test_skill_gap_is_reported(): | |
| c = load_card_text(CARD.replace("{pre_grasp: [hand, a]}", "{on_top: [a, b.interior]}")) | |
| with pytest.raises(SkillGap, match="on_top"): | |
| check(c) | |
| def test_tuning_merges_and_avoid_only_raises(): | |
| tc = {"params": {"weights": {"furniture": 5.0, "walls": 5.0, "xy": 4.0}, "funnel": {"k_xy": 3.0}}} | |
| c = load_card_text(CARD + "costs: {per_body: {cable: {avoid: 0.1}}}\n") | |
| out = apply_tuning(tc, c, {"params": {"funnel": {"k_xy": 2.0}}}) | |
| assert out["params"]["funnel"]["k_xy"] == 2.0 and out["params"]["weights"]["furniture"] == 5.0 # never less | |
| def test_model_rolls_out(): | |
| from cablepilot.model.learned import LearnedCDPRModel | |
| wm = LearnedCDPRModel.load(ROOT / "weights/stringman_g1.pt", dt=0.2) | |
| wm.set_room(np.array([[2, 2, 2.4], [-2, 2, 2.4], [-2, -2, 2.4], [2, -2, 2.4]], float)) | |
| x = np.zeros(14) | |
| x[2] = 1.2 | |
| wm.reset_history(x, np.zeros(5)) | |
| out = wm.rollout(None, None, np.zeros((4, 10, 5))) | |
| assert out.shape == (4, 10, 14) | |
| assert float(np.abs(out[..., 0:2]).max()) < 0.05 # holding still stays (nearly) still | |
| def test_doctor_quick(): | |
| from cablepilot.rig import doctor | |
| assert doctor(None, quick=True)["ok"] | |