9fe9d27865
Consolidate next-stage docs, archive superseded narratives, and preserve frozen document inputs. Retain invalid P2 pairs, partial RootXY training, failed attempts and nonselectable checkpoints as explicit limitations. Include supervised evaluation/training, desktop GPU admission, bounded evidence and atomic-publication monitor repairs with CPU regressions. Ignore local dotenv configuration. Validation: 1403 passed, 6 skipped for contact-cycle and related contracts/CLI tests. Full-suite legacy ABI and registration tests require Python 3.12/Torch 2.10/pxr; no runtime checks relaxed. No new physical run or accepted skill.
70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
"""Synthetic negative coverage for report logic; not physical validation."""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import torch
|
|
from SkillFactory.legs.contact_cycle.metrics import summarize
|
|
|
|
|
|
@pytest.fixture
|
|
def fixture_trace():
|
|
# Deliberately idealized input to test gate branches, not a dynamic simulator.
|
|
count = 600
|
|
phase = torch.arange(6).repeat_interleave(100)[:, None]
|
|
progress = torch.linspace(0, 1, 100).repeat(6)[:, None]
|
|
time = (torch.arange(count)*0.02)[:, None]
|
|
force = torch.zeros(count, 1, 3)
|
|
force[:, :, 2] = torch.where((phase == 0) | (phase >= 4), 50., 0.)
|
|
trace = {
|
|
"phase": phase, "progress": progress, "time": time, "scenario": torch.zeros(count, 1),
|
|
"weight": torch.full((count, 1), 50.), "normal": force,
|
|
"friction": torch.zeros_like(force), "foot": torch.zeros_like(force), "target": torch.zeros_like(force),
|
|
"gap": torch.full((count, 1), 0.05), "desired_force": force[..., 2],
|
|
"joint_excess": torch.zeros(count, 1), "limit_ratio": torch.zeros(count, 1),
|
|
"slip_speed": torch.zeros(count, 1), "height_error": torch.zeros(count, 1),
|
|
"external": torch.zeros(count, 1, 1, 6), "guide": torch.zeros(count, 1, 1, 6),
|
|
"auxiliary": torch.zeros(count, 1, 1, 6), "would_fail": torch.zeros(count, 1).bool(),
|
|
"tilt": torch.zeros(count, 1),
|
|
}
|
|
path = Path(__file__).resolve().parents[1]/"configs/contact_cycle/acceptance_v1.json"
|
|
thresholds = json.loads(path.read_text())["gates"]
|
|
return trace, thresholds
|
|
|
|
|
|
def report(fixture):
|
|
trace, thresholds = fixture
|
|
return summarize(trace, 0.02, thresholds, ["baseline"])[0]
|
|
|
|
|
|
def test_complete_fixture_passes_logic_only(fixture_trace):
|
|
assert report(fixture_trace)["success"]
|
|
|
|
|
|
@pytest.mark.parametrize("fault,reason", [
|
|
("tilt", "tilt"), ("lift", "lift_deadline"), ("terminate", "task_termination"),
|
|
("hover", "stance_contact"), ("drag", "slip"), ("nan", "missing_phase_or_nonfinite"),
|
|
("missing", "missing_phase_or_nonfinite"), ("impact", "impact"),
|
|
])
|
|
def test_negative_metrics_cannot_pass(fixture_trace, fault, reason):
|
|
t, _ = fixture_trace
|
|
if fault == "tilt":
|
|
t["tilt"][300] = 0.7
|
|
elif fault == "lift":
|
|
t["gap"][290:300] = 0
|
|
elif fault == "terminate":
|
|
t["would_fail"][100] = True
|
|
elif fault == "hover":
|
|
t["normal"][500:] = 0
|
|
elif fault == "drag":
|
|
t["slip_speed"][500:] = 0.1
|
|
elif fault == "nan":
|
|
t["normal"][400] = float("nan")
|
|
elif fault == "missing":
|
|
t["phase"][300:400] = 4
|
|
elif fault == "impact":
|
|
t["normal"][405, 0, 2] = 200
|
|
row = report(fixture_trace)
|
|
assert not row["success"] and reason in row["failure_reasons"]
|