nx_maint_simloop_test.nx source
↩ module page · 57 lines · 2703 B
1// nx_maint_simloop_test.nx -- gate for the closed-loop digital-twin simulator.
2//
3// Proves the platform end-to-end IN SOFTWARE (no IRL spend): a CLOSED loop
4// (diagnose -> act -> the fix feeds back -> recover) SELF-MAINTAINS the asset,
5// while an OPEN loop (OBD-style: error, no feedback) degrades and stays broken.
6// The measured EXCEED = far fewer sustained failures; the asset ends HEALTHY
7// under the closed loop, BROKEN under the open loop. Plus reproducibility.
8//
9// expect_exit: 0
10//
11// license_tier: ORIGINAL
12
13import "nx_syscalls_x86_64.nx"
14import "nx_maint_simloop.nx"
15
16func main() -> i64 {
17 let t: *i64 = sys_mmap(128) as *i64
18 let indoor: *i64 = sys_mmap(128) as *i64
19 let outdoor: *i64 = sys_mmap(128) as *i64
20 let on: *i64 = sys_mmap(128) as *i64
21 let out: *HvacEff = sys_mmap(128) as *HvacEff
22 let plan: *ActionPlan = sys_mmap(64) as *ActionPlan
23
24 // ===== CLOSED loop: diagnose -> act -> feedback -> recover =======
25 let tw_c: *TwinThermal = sys_mmap(64) as *TwinThermal
26 nx_twin_init(tw_c, 400, 100)
27 nx_sim_run(tw_c, 1, 20, t, indoor, outdoor, on, out, plan, 60000, 150)
28 if tw_c.cycles_run != 20 { return 10 }
29 if tw_c.fixes_applied != 2 { return 11 } // it fixed itself twice
30 if tw_c.failures_seen != 2 { return 12 } // only the 2 brief degradations
31 if tw_c.fouling > 625 { return 13 } // ends HEALTHY (recovered)
32
33 // ===== OPEN loop (OBD-style: error, no feedback) ================
34 let tw_o: *TwinThermal = sys_mmap(64) as *TwinThermal
35 nx_twin_init(tw_o, 400, 100)
36 nx_sim_run(tw_o, 0, 20, t, indoor, outdoor, on, out, plan, 60000, 150)
37 if tw_o.cycles_run != 20 { return 20 }
38 if tw_o.fixes_applied != 0 { return 21 } // no feedback = no fix
39 if tw_o.failures_seen != 13 { return 22 } // degrades and STAYS broken
40 if tw_o.fouling <= 625 { return 23 } // ends BROKEN
41
42 // ===== MEASURED EXCEED: closed loop self-maintains ==============
43 if tw_c.failures_seen >= tw_o.failures_seen { return 30 } // 2 << 13
44 if tw_c.fixes_applied < 2 { return 31 } // it acted on its own
45 // closed ends healthy, open ends broken (the closed loop earned its keep)
46 if tw_o.fouling <= tw_c.fouling { return 32 }
47
48 // ===== REPRODUCIBLE: same model + params -> same trajectory =====
49 let tw_r: *TwinThermal = sys_mmap(64) as *TwinThermal
50 nx_twin_init(tw_r, 400, 100)
51 nx_sim_run(tw_r, 1, 20, t, indoor, outdoor, on, out, plan, 60000, 150)
52 if tw_r.fixes_applied != tw_c.fixes_applied { return 40 }
53 if tw_r.failures_seen != tw_c.failures_seen { return 41 }
54 if tw_r.fouling != tw_c.fouling { return 42 }
55
56 return 0
57}