Download explore/PhaseLatch/scripts/audit_design.py from Travor278/RheoBench: direct link, hf CLI and curl.
- Browser
- Download file 5.69 kB
-
https://huggingface.co/datasets/Travor278/RheoBench/resolve/main/explore/PhaseLatch/scripts/audit_design.py
- Command line
-
hf download hf://datasets/Travor278/RheoBench/explore/PhaseLatch/scripts/audit_design.py
-
curl -L -o audit_design.py https://huggingface.co/datasets/Travor278/RheoBench/resolve/main/explore/PhaseLatch/scripts/audit_design.py
5.69 kB
| """Audit simplified intervention budgets. This is not a robotics simulator. | |
| No model scores or calibrated material values are produced. All assumptions and | |
| the limitations of each feasible/infeasible statement are preserved in output. | |
| """ | |
| import argparse | |
| import json | |
| import math | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parents[1] | |
| def require_positive(**values): | |
| for key, value in values.items(): | |
| if not isinstance(value, (int, float)) or not math.isfinite(value) or value <= 0: | |
| raise ValueError(f"{key} must be finite and positive") | |
| def rest_to_rest_time(distance, max_speed, acceleration): | |
| """Ideal 1D bang-bang move, including acceleration and deceleration.""" | |
| require_positive(distance=distance, max_speed=max_speed, acceleration=acceleration) | |
| critical_distance = max_speed**2 / acceleration | |
| if distance <= critical_distance: | |
| return 2 * math.sqrt(distance / acceleration) | |
| return 2 * max_speed / acceleration + (distance - critical_distance) / max_speed | |
| def brake_case(case, delays): | |
| D = case["distance_to_wall_m"] | |
| v = case["speed_m_s"] | |
| a = case["safe_deceleration_m_s2"] | |
| require_positive(D=D, v=v, a=a) | |
| braking_distance = v*v / (2*a) | |
| last_contact = (D-braking_distance) / v | |
| approach = rest_to_rest_time(case["robot_approach_distance_m"], case["robot_max_speed_m_s"], case["robot_max_acceleration_m_s2"]) | |
| budget = last_contact - approach | |
| return { | |
| "id": case["id"], | |
| "braking_distance_m": braking_distance, | |
| "no_intervention_collision_time_s": D/v, | |
| "last_braking_contact_time_s": last_contact, | |
| "ideal_robot_approach_time_s": approach, | |
| "ideal_remaining_latency_budget_s": budget, | |
| "feasible_at_zero_delay_in_this_model": budget >= 0, | |
| "latency_sweep": [{"delay_s": delay, "stopping_distance_including_approach_m": v*(delay+approach)+braking_distance, "within_wall_in_this_model": v*(delay+approach)+braking_distance <= D+1e-12} for delay in delays], | |
| "assumptions": case["assumptions"], | |
| "limitations": "The robot approach is an ideal motion sketch, not pursuit or velocity-matched contact. Actual contact establishment, safe acceleration calibration, compliance and alternative interventions require simulation." | |
| } | |
| def punch_case(case, delays): | |
| h = case["remaining_gap_m"] | |
| v = case["breakthrough_speed_m_s"] | |
| a = case["max_deceleration_m_s2"] | |
| require_positive(h=h, v=v, a=a) | |
| d = v*v/(2*a) | |
| budget = (h-d)/v | |
| return { | |
| "id": case["id"], | |
| "zero_delay_braking_distance_m": d, | |
| "constant_speed_time_to_plate_s": h/v, | |
| "ideal_total_response_delay_budget_s": budget, | |
| "feasible_at_zero_delay_in_this_model": budget >= 0, | |
| "latency_sweep": [{"delay_s": delay, "post_event_distance_m": v*delay+d, "within_gap_in_this_model": v*delay+d <= h+1e-12} for delay in delays], | |
| "assumptions": case["assumptions"], | |
| "limitations": "Applies to post-event tip braking only. Pre-deceleration, a physical stop or another controller may solve cases marked infeasible; extra compliance energy may make feasible sketches fail." | |
| } | |
| def audit(spec): | |
| if spec.get("status") != "proposed_not_simulated" or spec.get("units") != "SI": | |
| raise ValueError("Expected proposed_not_simulated status and SI units") | |
| tasks = spec["task_families"] | |
| ids = [x["id"] for x in tasks] | |
| if len(set(ids)) != len(ids): | |
| raise ValueError("Duplicate task IDs") | |
| for task in tasks: | |
| for key in ("desired_transition", "protected_state", "observability", "legal_prevention", "validation_required"): | |
| if not task.get(key): | |
| raise ValueError(f"{task['id']} lacks {key}") | |
| cases = spec["analytical_cases"] | |
| delays = cases["latency_probe_s"] | |
| if any(not math.isfinite(x) or x < 0 for x in delays): | |
| raise ValueError("Latency values must be finite and nonnegative") | |
| return { | |
| "project": spec["project"], | |
| "design_date": spec["design_date"], | |
| "result_type": "analytical_design_audit_not_simulation", | |
| "task_families_checked": len(tasks), | |
| "scope": spec["scope"], | |
| "braking": [brake_case(x, delays) for x in cases["braking"]], | |
| "breakthrough": [punch_case(x, delays) for x in cases["breakthrough"]], | |
| "not_audited": {x["id"]: x["validation_required"] for x in tasks}, | |
| "interpretation": "Feasibility statements concern only the declared simplified models, not all robot strategies. These results do not establish benchmark difficulty, material realism, optimality or VLA performance." | |
| } | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("--spec", type=Path, default=ROOT / "specs" / "design_cases.json") | |
| parser.add_argument("--output", type=Path, default=ROOT / "results" / "design_audit.json") | |
| args = parser.parse_args() | |
| result = audit(json.loads(args.spec.read_text(encoding="utf-8"))) | |
| args.output.parent.mkdir(parents=True, exist_ok=True) | |
| args.output.write_text(json.dumps(result, ensure_ascii=False, indent=2, allow_nan=False)+"\n", encoding="utf-8") | |
| print("Analytical audit only; no simulator or policy executed.") | |
| for group, budget_key in [("braking", "ideal_remaining_latency_budget_s"), ("breakthrough", "ideal_total_response_delay_budget_s")]: | |
| for case in result[group]: | |
| print(f"{case['id']}: ideal latency budget={1000*case[budget_key]:.2f} ms; zero-delay feasible in stated model={case['feasible_at_zero_delay_in_this_model']}") | |
| print(f"Saved: {args.output.resolve()}") | |
| if __name__ == "__main__": | |
| main() | |