|
| 1 | +"""Run canonical NRA-IDE states through the normative reference implementation. |
| 2 | +
|
| 3 | +This file is an executable example, not a separate canonical evaluator. |
| 4 | +The thresholds are explicit demonstration values, not inferred domain defaults. |
| 5 | +Do not use this demo for medical, autonomous-control, or other operational decisions. |
| 6 | +""" |
| 7 | + |
| 8 | +from __future__ import annotations |
| 9 | + |
| 10 | +import importlib.util |
| 11 | +import pathlib |
| 12 | +from typing import Any |
| 13 | + |
| 14 | + |
| 15 | +ROOT = pathlib.Path(__file__).resolve().parents[1] |
| 16 | +SOURCE = ROOT / "nra-core" / "foundations" / "NRA-IDE_Architecture_public.py" |
| 17 | +SPEC = importlib.util.spec_from_file_location("nra_ide_reference_quick_demo", SOURCE) |
| 18 | +NRA = importlib.util.module_from_spec(SPEC) |
| 19 | +assert SPEC.loader is not None |
| 20 | +SPEC.loader.exec_module(NRA) |
| 21 | + |
| 22 | +THRESHOLDS = { |
| 23 | + "r_warn": 0.4, |
| 24 | + "r_handoff": 0.6, |
| 25 | + "r_irrev": 0.8, |
| 26 | +} |
| 27 | + |
| 28 | +SCENARIOS = ( |
| 29 | + ("below warning", 0.1, 1.0, "PERMIT"), |
| 30 | + ("warning boundary", 0.4, 1.0, "BOUNDARY_WARNING"), |
| 31 | + ("human handoff", 0.6, 1.0, "HANDOFF_REQUIRED"), |
| 32 | + ("irreversible onset", 0.8, 1.0, "IRREVERSIBLE_TRANSITION"), |
| 33 | + ("complete rupture", 1.0, 1.0, "RUPTURE_BOUNDARY"), |
| 34 | + ("invalid structural input", "invalid", 1.0, "CONFESSION"), |
| 35 | + ("undefined ratio domain", 0.1, 0.0, "OUT_OF_DESCRIPTION_DOMAIN"), |
| 36 | +) |
| 37 | + |
| 38 | + |
| 39 | +def display_value(value: Any) -> str: |
| 40 | + return "NOT_AVAILABLE" if value is None else str(value) |
| 41 | + |
| 42 | + |
| 43 | +def main() -> int: |
| 44 | + print("NRA-IDE normative reference quick demo") |
| 45 | + print("Thresholds are explicit demonstration values:", THRESHOLDS) |
| 46 | + print() |
| 47 | + |
| 48 | + passed = 0 |
| 49 | + for name, delta, tau, expected in SCENARIOS: |
| 50 | + result = NRA.nra_ide_core_evaluation(delta, tau, **THRESHOLDS) |
| 51 | + actual = result["status"] |
| 52 | + outcome = "PASS" if actual == expected else "FAIL" |
| 53 | + passed += actual == expected |
| 54 | + print( |
| 55 | + f"{outcome:4} | {name:24} | delta={delta!r:9} | tau={tau!r:4} | " |
| 56 | + f"R={display_value(result['R']):13} | status={actual} | expected={expected}" |
| 57 | + ) |
| 58 | + |
| 59 | + print() |
| 60 | + print(f"Scenarios passed: {passed}/{len(SCENARIOS)}") |
| 61 | + if passed == len(SCENARIOS): |
| 62 | + print("Quick demo result: OK") |
| 63 | + return 0 |
| 64 | + print("Quick demo result: FAILED") |
| 65 | + return 1 |
| 66 | + |
| 67 | + |
| 68 | +if __name__ == "__main__": |
| 69 | + raise SystemExit(main()) |
0 commit comments