code wiki / _hdl_build / nx_costest_gate.nx
nx_costest_gate.nx source
↩ module page · 285 lines · 20435 B
1// nx_costest_gate.nx -- GATE for the cost estimator (nx_costest_lib), driven IN-PROCESS: known-answer teeth on the
2// integer sqrt, the deci-u parser and printers, the three-point aggregate (root-sum-square band beside the
3// correlated sum), the quantile rank rule and the derived distinct-rank floor, the compute-cost rules, and the
4// calibration census over planted plan rows (a rung calibrated from two journal rows, a rung whose last land row
5// wins, a rung with no declared cost EXCLUDED BY NAME, a rung whose only row is its land row EXCLUDED BY NAME, a
6// journal row naming no rung COUNTED, a non-integer epoch IGNORED), then the ledger line written and read back
7// through the one grammar, a malformed ledger REFUSED and an absent one reported absent. Every fixture asserts
8// its own condition first; the neg-controls are named.
9// license_tier: ORIGINAL No hw writes (Rule 26).
10import "nx_syscalls.nx"
11import "nx_costest_lib.nx"
12import "nx_gate_verdict.nx"
13
14const G_I64: i64 = 8
15const G_MODE_755: i64 = 493
16const G_MODE_644: i64 = 420
17const G_DIR: *u8 = "/tmp/nx_costest_gate"
18const G_LEDGER: *u8 = "/tmp/nx_costest_gate/costcal.ledger"
19const G_BADLEDGER: *u8 = "/tmp/nx_costest_gate/bad.ledger"
20const G_ABSENT: *u8 = "/tmp/nx_costest_gate/absent.ledger"
21const G_NUM_CAP: i64 = 32
22const G_ROWCAP: i64 = 4096
23const G_PLAN: *u8 = "rung|R1|a|s1|d|Organ|2|-\nrung|R2|b|s2|d|Organ|1.5|-\nrung|R3|c|s3|d|Organ|-|-\nrung|R4|d|s4|d|Organ|1|-\nlog|1000|R1|queue|q\nlog|8200|R1|land|l\nlog|2000|R2|measure|m\nlog|2000|R2|land|first land\nlog|29000|R2|land|last land\nlog|3000|R3|land|no cost\nlog|4000|R4|land|only row\nlog|5000|R9|land|unmatched\nlog|bad|R1|land|a non-integer epoch\n"
24const G_PLAN_RUNGS: i64 = 4
25const G_PLAN_LOGROWS: i64 = 9
26const G_PLAN_UNMATCHED: i64 = 1
27const G_PLAN_WITHLAND: i64 = 4
28const G_PLAN_CALIBRATED: i64 = 2
29const G_PLAN_EXCL_ZERO: i64 = 1
30const G_PLAN_EXCL_NOCOST: i64 = 1
31const G_R1_RATIO: i64 = 100 // 7200 s over 2 u = 1.00 h per u
32const G_R2_RATIO: i64 = 500 // 27000 s over 1.5 u = 5.00 h per u
33const G_NOPLAN: *u8 = "log|1000|R1|land|no rung rows at all\nlog|2000|R2|land|none\n"
34const G_NOPLAN_LOGROWS: i64 = 2
35const G_BADCAL: *u8 = "cal|1|x|3|4|5|6|7|8|9|10|11|12|13\n"
36const G_AGG_N: i64 = 2
37const G_AGG_P10: i64 = 26 // 40 - isqrt(200)
38const G_AGG_P50: i64 = 40
39const G_AGG_P90: i64 = 68 // 40 + isqrt(800)
40const G_AGG_SUM10: i64 = 20
41const G_AGG_SUM90: i64 = 80
42// EC56 event rows: a rung landed twice with a retraction between, and a measure row that is NOT an event
43const G_EVPLAN: *u8 = "rung|A1|a|s|d|Organ|1|-\nlog|100|A1|land|first\nlog|200|A1|retract|withdrawn\nlog|300|A1|land|again\nlog|400|A1|measure|not an event\n"
44const G_EV_FX_LANDS: i64 = 5 // R1 once, R2 twice, R3, R4; R9 is unmatched and the bad epoch writes nothing
45const G_EV_FX_DECIU: i64 = 45 // 20 + 15 + 0 + 10 over the four distinct landed rungs
46const G_EV_LO: i64 = 2500
47const G_EV_HI_INCL: i64 = 8201 // [2500, 8201) holds R3 at 3000, R4 at 4000 and R1 at 8200
48const G_EV_HI_EXCL: i64 = 8200 // hi is exclusive: the same window one second shorter drops R1
49const G_EV_ALL_HI: i64 = 100000
50// EC57 WIP rows: W1, W4 and W5 have journal rows and no land (open); W2 landed; W3 was never touched (not started, so not open)
51const G_WIPPLAN: *u8 = "rung|W1|a|s|d|Organ|1|-\nrung|W2|b|s|d|Organ|2|-\nrung|W3|c|s|d|Organ|1|-\nrung|W4|d|s|d|Organ|1|-\nrung|W5|e|s|d|Organ|1|-\nlog|100|W1|measure|m\nlog|900|W1|queue|q\nlog|500|W2|measure|m\nlog|600|W2|land|l\nlog|950|W4|measure|m\nlog|50|W5|measure|m\n"
52const G_WIP_OPEN: i64 = 3
53const G_WIP_NOW_NEAR: i64 = 1000 // W4 touched 50 s ago, W1 100 s ago, W5 950 s ago
54const G_WIP_NOW_FAR: i64 = 5000 // everything is older than the window
55const G_WIP_ACTIVE_S: i64 = 200
56const G_WIP_NEAR_CODE: i64 = 21 // active 2, stale 1, written as active * 10 + stale
57const G_WIP_FAR_CODE: i64 = 3 // active 0, stale 3
58const G_WIP_OLDEST: i64 = 50
59const G_MINN: i64 = 4 // n=3 collides P50 and P90 at rank 1; n=4 gives ranks 0,1,2
60
61func g_lit(s: *u8, dst: *u8) -> i64 {
62 let n: i64 = ces_slen(s)
63 var i: i64 = 0
64 while i < n { dst[i] = s[i]; i = i + 1 }
65 dst[n] = 0 as u8
66 return n
67}
68func g_streq(a: *u8, b: *u8) -> i64 {
69 let n: i64 = ces_slen(a)
70 if n != ces_slen(b) { return 0 }
71 var i: i64 = 0
72 while i < n { if a[i] != b[i] { return 0 } i = i + 1 }
73 return 1
74}
75func g_contains(hay: *u8, n: i64, needle: *u8) -> i64 {
76 let m: i64 = ces_slen(needle)
77 if m == 0 { return 0 }
78 var i: i64 = 0
79 while i + m <= n {
80 var j: i64 = 0
81 var ok: i64 = 1
82 while j < m { if hay[i + j] != needle[j] { ok = 0; j = m } else { j = j + 1 } }
83 if ok == 1 { return 1 }
84 i = i + 1
85 }
86 return 0
87}
88func g_write(path: *u8, buf: *u8, n: i64) -> i64 {
89 let fd: i64 = sys_openat_wr(path, G_MODE_644)
90 if fd < 0 { return 0 }
91 sys_write(fd, buf, n)
92 sys_close(fd)
93 return 1
94}
95func g_deciu(lit: *u8) -> i64 {
96 let b: *u8 = sys_mmap(G_NUM_CAP)
97 let n: i64 = g_lit(lit, b)
98 return ces_parse_deciu(b, 0, n)
99}
100
101func main(argc: i64, argv: *i64) -> i64 {
102 let c: *i64 = gv_ctr()
103 gv_head("nx_costest_gate -- the cost estimator: three-point arithmetic, quantiles, compute rules, the calibration census and its ledger grammar" as *u8)
104 sys_mkdir(G_DIR, G_MODE_755)
105 // integer sqrt
106 gv_check_eq("isqrt-0" as *u8, ces_isqrt(0), 0, c)
107 gv_check_eq("isqrt-1" as *u8, ces_isqrt(1), 1, c)
108 gv_check_eq("isqrt-3-floors-to-1" as *u8, ces_isqrt(3), 1, c)
109 gv_check_eq("isqrt-4" as *u8, ces_isqrt(4), 2, c)
110 gv_check_eq("isqrt-15-floors-to-3" as *u8, ces_isqrt(15), 3, c)
111 gv_check_eq("isqrt-16" as *u8, ces_isqrt(16), 4, c)
112 gv_check_eq("isqrt-17-floors-to-4" as *u8, ces_isqrt(17), 4, c)
113 gv_check_eq("isqrt-million" as *u8, ces_isqrt(1000000), 1000, c)
114 gv_check_eq("isqrt-999999-floors-to-999" as *u8, ces_isqrt(999999), 999, c)
115 // the deci-u parser
116 gv_check_eq("parse-12-is-120" as *u8, g_deciu("12" as *u8), 120, c)
117 gv_check_eq("parse-1.5-is-15" as *u8, g_deciu("1.5" as *u8), 15, c)
118 gv_check_eq("parse-0.5-is-5" as *u8, g_deciu("0.5" as *u8), 5, c)
119 gv_check_eq("parse-dash-is-ABSENT" as *u8, g_deciu("-" as *u8), CES_ABSENT, c)
120 gv_check_eq("neg-control-parse-two-fractional-digits-is-NONE" as *u8, g_deciu("1.55" as *u8), CES_NONE, c)
121 gv_check_eq("neg-control-parse-letters-is-NONE" as *u8, g_deciu("abc" as *u8), CES_NONE, c)
122 gv_check_eq("neg-control-parse-empty-is-NONE" as *u8, g_deciu("" as *u8), CES_NONE, c)
123 gv_check_eq("neg-control-parse-trailing-dot-is-NONE" as *u8, g_deciu("1." as *u8), CES_NONE, c)
124 // the printers
125 let pb: *u8 = sys_mmap(G_NUM_CAP)
126 ces_fmt_deci(pb, 0, 15); gv_check("fmt-deci-15-is-1.5" as *u8, g_streq(pb, "1.5" as *u8), c)
127 ces_fmt_deci(pb, 0, 120); gv_check("fmt-deci-120-is-12 (zero fractional digit dropped)" as *u8, g_streq(pb, "12" as *u8), c)
128 ces_fmt_deci(pb, 0, 0); gv_check("fmt-deci-0-is-0" as *u8, g_streq(pb, "0" as *u8), c)
129 ces_fmt_centi(pb, 0, 1234); gv_check("fmt-centi-1234-is-12.34" as *u8, g_streq(pb, "12.34" as *u8), c)
130 ces_fmt_centi(pb, 0, 5); gv_check("fmt-centi-5-is-0.05" as *u8, g_streq(pb, "0.05" as *u8), c)
131 // the three-point aggregate: two components (1, 2, 4) u each
132 let a10: *i64 = sys_mmap(G_AGG_N * G_I64) as *i64
133 let a50: *i64 = sys_mmap(G_AGG_N * G_I64) as *i64
134 let a90: *i64 = sys_mmap(G_AGG_N * G_I64) as *i64
135 a10[0] = 10; a50[0] = 20; a90[0] = 40
136 a10[1] = 10; a50[1] = 20; a90[1] = 40
137 let agg: *i64 = sys_mmap(CES_A_SLOTS * G_I64) as *i64
138 ces_agg3(a10, a50, a90, G_AGG_N, agg)
139 gv_check_eq("agg-p50-is-the-sum-of-medians" as *u8, agg[CES_A_P50], G_AGG_P50, c)
140 gv_check_eq("agg-p10-is-p50-minus-rss-of-lower-half-widths" as *u8, agg[CES_A_P10], G_AGG_P10, c)
141 gv_check_eq("agg-p90-is-p50-plus-rss-of-upper-half-widths" as *u8, agg[CES_A_P90], G_AGG_P90, c)
142 gv_check_eq("agg-correlated-sum10-beside-it" as *u8, agg[CES_A_SUM10], G_AGG_SUM10, c)
143 gv_check_eq("agg-correlated-sum90-beside-it" as *u8, agg[CES_A_SUM90], G_AGG_SUM90, c)
144 gv_check("agg-rss-band-is-inside-the-correlated-band" as *u8, ((agg[CES_A_P10] >= agg[CES_A_SUM10]) as i64) * ((agg[CES_A_P90] <= agg[CES_A_SUM90]) as i64), c)
145 ces_agg3(a10, a50, a90, 0, agg)
146 gv_check_eq("neg-control-agg-of-nothing-is-zero" as *u8, agg[CES_A_P50] + agg[CES_A_P10] + agg[CES_A_P90] + agg[CES_A_N], 0, c)
147 // quantiles and the distinct-rank floor
148 let q: *i64 = sys_mmap(5 * G_I64) as *i64
149 q[0] = 5; q[1] = 1; q[2] = 4; q[3] = 2; q[4] = 3
150 ces_sort(q, 5)
151 gv_check("sort-ascending" as *u8, ((q[0] == 1) as i64) * ((q[4] == 5) as i64) * ((q[2] == 3) as i64), c)
152 gv_check_eq("quantile-p10-of-five-is-the-first" as *u8, ces_quantile(q, 5, CES_P10), 1, c)
153 gv_check_eq("quantile-p50-of-five-is-the-middle" as *u8, ces_quantile(q, 5, CES_P50), 3, c)
154 gv_check_eq("quantile-p90-of-five-is-the-fourth" as *u8, ces_quantile(q, 5, CES_P90), 4, c)
155 gv_check_eq("neg-control-quantile-of-nothing-is-NONE" as *u8, ces_quantile(q, 0, CES_P50), CES_NONE, c)
156 gv_check_eq("fixture-reached-the-condition: at n=3 P50 and P90 share a rank" as *u8, ces_qidx(3, CES_P50), ces_qidx(3, CES_P90), c)
157 gv_check_eq("distinct-rank-floor-derived-is-4" as *u8, ces_cal_min_n(), G_MINN, c)
158 // compute rules and the hours conversion
159 gv_check_eq("train-flops-6-per-param-token" as *u8, ces_train_flops(2, 3), 36, c)
160 gv_check_eq("infer-flops-2-per-param-token" as *u8, ces_infer_flops(2, 3), 12, c)
161 gv_check_eq("seconds-at-a-measured-rate" as *u8, ces_seconds(100, 7), 14, c)
162 gv_check_eq("neg-control-seconds-at-no-rate-is-NONE" as *u8, ces_seconds(100, 0), CES_NONE, c)
163 gv_check_eq("hours-centi-1.5u-at-2.00h-per-u-is-3.00h" as *u8, ces_hours_centi(15, 200), 300, c)
164 // the calibration census over planted plan rows
165 let plan: *u8 = sys_mmap(ces_slen(G_PLAN) + 1)
166 let pn: i64 = g_lit(G_PLAN, plan)
167 gv_check("fixture-reached-the-condition: the plan holds four rung rows and nine log rows" as *u8, (pn > 0) as i64, c)
168 let st: *i64 = sys_mmap(CES_S_SLOTS * G_I64) as *i64
169 let samples: *i64 = sys_mmap(16 * G_I64) as *i64
170 let sc: *i64 = sys_mmap(G_I64) as *i64
171 let ro: *i64 = sys_mmap(G_I64) as *i64
172 let rows: *u8 = sys_mmap(G_ROWCAP)
173 sc[0] = 0; ro[0] = 0
174 let nr: i64 = ces_census_plan(plan, pn, "fx" as *u8, samples, 16, sc, st, rows, G_ROWCAP, ro)
175 gv_check_eq("census-rungs" as *u8, nr, G_PLAN_RUNGS, c)
176 gv_check_eq("census-logrows-counted-including-the-bad-epoch" as *u8, st[CES_S_LOGROWS], G_PLAN_LOGROWS, c)
177 gv_check_eq("census-unmatched-journal-row-counted" as *u8, st[CES_S_UNMATCHED], G_PLAN_UNMATCHED, c)
178 gv_check_eq("census-withland" as *u8, st[CES_S_WITHLAND], G_PLAN_WITHLAND, c)
179 gv_check_eq("census-calibrated" as *u8, st[CES_S_CALIBRATED], G_PLAN_CALIBRATED, c)
180 gv_check_eq("census-excluded-zero-elapsed-by-name" as *u8, st[CES_S_EXCL_ZERO], G_PLAN_EXCL_ZERO, c)
181 gv_check_eq("census-excluded-no-cost-by-name" as *u8, st[CES_S_EXCL_NOCOST], G_PLAN_EXCL_NOCOST, c)
182 gv_check_eq("census-partition-sums-to-withland" as *u8, st[CES_S_CALIBRATED] + st[CES_S_EXCL_ZERO] + st[CES_S_EXCL_NOCOST], st[CES_S_WITHLAND], c)
183 gv_check_eq("census-samples-are-the-calibrated-rungs" as *u8, sc[0], G_PLAN_CALIBRATED, c)
184 ces_sort(samples, sc[0])
185 gv_check_eq("census-R1-ratio-1.00h-per-u" as *u8, samples[0], G_R1_RATIO, c)
186 gv_check_eq("census-R2-ratio-5.00h-per-u-uses-the-LAST-land-row" as *u8, samples[1], G_R2_RATIO, c)
187 gv_check("census-row-line-written-for-R1" as *u8, g_contains(rows, ro[0], "row|fx|R1|20|1000|8200|7200|100" as *u8), c)
188 gv_check("neg-control-no-row-line-for-the-excluded-rung" as *u8, 1 - g_contains(rows, ro[0], "row|fx|R4|" as *u8), c)
189 // EC56: the EVENT rows -- every land on a declared rung, including the rungs the calibration excludes
190 gv_check("event-row-for-both-lands-of-R2 (the row line keeps only the last)" as *u8, g_contains(rows, ro[0], "land|fx|R2|2000|15" as *u8) * g_contains(rows, ro[0], "land|fx|R2|29000|15" as *u8), c)
191 gv_check("event-row-for-the-rungs-calibration-excludes (R3 no cost, R4 only row)" as *u8, g_contains(rows, ro[0], "land|fx|R3|3000|0" as *u8) * g_contains(rows, ro[0], "land|fx|R4|4000|10" as *u8), c)
192 gv_check("neg-control-event-no-row-for-the-unmatched-rung" as *u8, 1 - g_contains(rows, ro[0], "land|fx|R9|" as *u8), c)
193 gv_check_eq("event-rows-counted-in-the-stats" as *u8, st[CES_S_LANDEVENTS], G_EV_FX_LANDS, c)
194 // the reader over the SAME bytes the writer produced: a round trip on the wire, not two units in isolation
195 let wacc: *i64 = sys_mmap(CES_W_SLOTS * G_I64) as *i64
196 gv_check_eq("events-window-all-distinct-rungs" as *u8, ces_events_window(rows, ro[0], 0, G_EV_ALL_HI, wacc), G_PLAN_WITHLAND, c)
197 gv_check_eq("events-window-all-land-events (the bad epoch wrote none)" as *u8, wacc[CES_W_LAND_EVENTS], G_EV_FX_LANDS, c)
198 gv_check_eq("events-window-relanded-is-R2" as *u8, wacc[CES_W_RELANDED], 1, c)
199 gv_check_eq("events-window-deciu-20-15-0-10" as *u8, wacc[CES_W_LANDED_DECIU], G_EV_FX_DECIU, c)
200 gv_check_eq("events-window-filter-includes-the-last-second" as *u8, ces_events_window(rows, ro[0], G_EV_LO, G_EV_HI_INCL, wacc), 3, c)
201 gv_check_eq("neg-control-events-window-hi-is-exclusive" as *u8, ces_events_window(rows, ro[0], G_EV_LO, G_EV_HI_EXCL, wacc), 2, c)
202 // a rung landed twice with a retraction between, censused under two boards: identity is domain AND rung
203 let plan4: *u8 = sys_mmap(ces_slen(G_EVPLAN) + 1)
204 let pn4: i64 = g_lit(G_EVPLAN, plan4)
205 let st4: *i64 = sys_mmap(CES_S_SLOTS * G_I64) as *i64
206 let samples4: *i64 = sys_mmap(16 * G_I64) as *i64
207 let sc4: *i64 = sys_mmap(G_I64) as *i64
208 let ro4: *i64 = sys_mmap(G_I64) as *i64
209 let rows4: *u8 = sys_mmap(G_ROWCAP)
210 sc4[0] = 0; ro4[0] = 0
211 ces_census_plan(plan4, pn4, "fa" as *u8, samples4, 16, sc4, st4, rows4, G_ROWCAP, ro4)
212 ces_census_plan(plan4, pn4, "fb" as *u8, samples4, 16, sc4, st4, rows4, G_ROWCAP, ro4)
213 gv_check("fixture-reached-the-condition: the retract row was written" as *u8, g_contains(rows4, ro4[0], "retract|fa|A1|200" as *u8), c)
214 gv_check_eq("events-window-identity-is-domain-AND-rung (A1 on two boards is two rungs)" as *u8, ces_events_window(rows4, ro4[0], 0, G_EV_ALL_HI, wacc), 2, c)
215 gv_check_eq("events-window-two-lands-per-board-are-four-events" as *u8, wacc[CES_W_LAND_EVENTS], 4, c)
216 gv_check_eq("events-window-retracts-counted" as *u8, wacc[CES_W_RETRACTS], 2, c)
217 gv_check("neg-control-a-measure-row-is-not-an-event" as *u8, 1 - g_contains(rows4, ro4[0], "|400" as *u8), c)
218 gv_check_eq("neg-control-events-window-on-an-empty-buffer-is-zero" as *u8, ces_events_window(rows4, 0, 0, G_EV_ALL_HI, wacc), 0, c)
219 // EC57 WIP: a rung with journal rows and no land row is OPEN, by name; a landed rung and an untouched rung are not
220 let oacc: *i64 = sys_mmap(CES_O_SLOTS * G_I64) as *i64
221 let otoff: *i64 = sys_mmap(CES_WIP_TOP * G_I64) as *i64
222 let otlen: *i64 = sys_mmap(CES_WIP_TOP * G_I64) as *i64
223 gv_check_eq("neg-control-wip-summary-of-the-first-fixture-is-zero (every rung there landed)" as *u8, ces_open_summary(rows, ro[0], G_WIP_NOW_FAR, G_WIP_ACTIVE_S, oacc, otoff, otlen) + oacc[CES_O_OPEN], 0, c)
224 let plan5: *u8 = sys_mmap(ces_slen(G_WIPPLAN) + 1)
225 let pn5: i64 = g_lit(G_WIPPLAN, plan5)
226 let st5: *i64 = sys_mmap(CES_S_SLOTS * G_I64) as *i64
227 let samples5: *i64 = sys_mmap(16 * G_I64) as *i64
228 let sc5: *i64 = sys_mmap(G_I64) as *i64
229 let ro5: *i64 = sys_mmap(G_I64) as *i64
230 let rows5: *u8 = sys_mmap(G_ROWCAP)
231 sc5[0] = 0; ro5[0] = 0
232 ces_census_plan(plan5, pn5, "fw" as *u8, samples5, 16, sc5, st5, rows5, G_ROWCAP, ro5)
233 gv_check("wip-open-row-written-with-first-and-last (W1: 100 to 900, 1 u)" as *u8, g_contains(rows5, ro5[0], "open|fw|W1|100|900|10" as *u8), c)
234 gv_check("neg-control-wip-a-landed-rung-is-not-open" as *u8, 1 - g_contains(rows5, ro5[0], "open|fw|W2|" as *u8), c)
235 gv_check("neg-control-wip-an-untouched-rung-is-not-open (never started)" as *u8, 1 - g_contains(rows5, ro5[0], "open|fw|W3|" as *u8), c)
236 gv_check_eq("wip-open-counted-in-the-stats" as *u8, st5[CES_S_OPEN], G_WIP_OPEN, c)
237 gv_check_eq("wip-summary-names-the-three-most-recent" as *u8, ces_open_summary(rows5, ro5[0], G_WIP_NOW_NEAR, G_WIP_ACTIVE_S, oacc, otoff, otlen), G_WIP_OPEN, c)
238 gv_check_eq("wip-summary-active-2-stale-1-inside-the-window" as *u8, oacc[CES_O_ACTIVE] * 10 + oacc[CES_O_STALE], G_WIP_NEAR_CODE, c)
239 gv_check_eq("wip-summary-oldest-is-the-earliest-first-row" as *u8, oacc[CES_O_OLDEST], G_WIP_OLDEST, c)
240 gv_check("wip-summary-top-is-newest-first (W4 at 950, then W1 at 900, then W5 at 50)" as *u8, ces_span_is(rows5, otoff[0], otlen[0], "fw|W4" as *u8) * ces_span_is(rows5, otoff[1], otlen[1], "fw|W1" as *u8) * ces_span_is(rows5, otoff[2], otlen[2], "fw|W5" as *u8), c)
241 ces_open_summary(rows5, ro5[0], G_WIP_NOW_FAR, G_WIP_ACTIVE_S, oacc, otoff, otlen)
242 gv_check_eq("neg-control-wip-the-same-rungs-read-stale-outside-the-window" as *u8, oacc[CES_O_ACTIVE] * 10 + oacc[CES_O_STALE], G_WIP_FAR_CODE, c)
243 gv_check_eq("wip-partition-open-is-active-plus-stale" as *u8, oacc[CES_O_ACTIVE] + oacc[CES_O_STALE], oacc[CES_O_OPEN], c)
244 // neg-control: journal rows with no rung rows calibrate nothing
245 let st2: *i64 = sys_mmap(CES_S_SLOTS * G_I64) as *i64
246 let plan2: *u8 = sys_mmap(ces_slen(G_NOPLAN) + 1)
247 let pn2: i64 = g_lit(G_NOPLAN, plan2)
248 sc[0] = 0; ro[0] = 0
249 let nr2: i64 = ces_census_plan(plan2, pn2, "fx2" as *u8, samples, 16, sc, st2, rows, G_ROWCAP, ro)
250 gv_check_eq("neg-control-no-rung-rows-calibrates-nothing" as *u8, nr2 + st2[CES_S_CALIBRATED] + sc[0], 0, c)
251 gv_check_eq("neg-control-every-orphan-journal-row-is-unmatched" as *u8, st2[CES_S_UNMATCHED], G_NOPLAN_LOGROWS, c)
252 // the ledger grammar: write, read back, every slot equal
253 st[CES_S_ASOF] = 1789580000
254 st[CES_S_BOARDS] = 1
255 st[CES_S_P10] = samples[0]; st[CES_S_P50] = samples[0]; st[CES_S_P90] = samples[1]
256 st[CES_S_MINN] = ces_cal_min_n()
257 let lb: *u8 = sys_mmap(1024)
258 let lo: i64 = ces_cal_line(lb, 0, st)
259 gv_check("ledger-line-written" as *u8, g_write(G_LEDGER, lb, lo), c)
260 let st3: *i64 = sys_mmap(CES_S_SLOTS * G_I64) as *i64
261 gv_check_eq("ledger-load-finds-the-cal-line" as *u8, ces_cal_load(G_LEDGER, st3), 1, c)
262 var mism: i64 = 0
263 var k: i64 = 0
264 while k < CES_S_MINN + 1 { if st3[k] != st[k] { mism = mism + 1 } k = k + 1 }
265 gv_check_eq("ledger-round-trip-every-slot-equal" as *u8, mism, 0, c)
266 gv_check_eq("ledger-round-trip-p90-is-the-R2-ratio" as *u8, st3[CES_S_P90], G_R2_RATIO, c)
267 let bb: *u8 = sys_mmap(ces_slen(G_BADCAL) + 1)
268 let bn: i64 = g_lit(G_BADCAL, bb)
269 g_write(G_BADLEDGER, bb, bn)
270 gv_check_eq("neg-control-malformed-cal-line-is-refused" as *u8, ces_cal_load(G_BADLEDGER, st3), CES_NONE, c)
271 gv_check_eq("neg-control-absent-ledger-reads-absent" as *u8, ces_cal_load(G_ABSENT, st3), 0, c)
272 gv_values_head()
273 gv_kv("agg_p10" as *u8, G_AGG_P10)
274 gv_kv("agg_p50" as *u8, G_AGG_P50)
275 gv_kv("agg_p90" as *u8, G_AGG_P90)
276 gv_kv("distinct_rank_floor" as *u8, ces_cal_min_n())
277 gv_kv("r1_centih_per_u" as *u8, samples[0])
278 gv_kv("r2_centih_per_u" as *u8, samples[1])
279 gv_kv("census_withland" as *u8, st[CES_S_WITHLAND])
280 gv_kv("event_land_rows" as *u8, st[CES_S_LANDEVENTS])
281 gv_kv("event_retract_rows_two_boards" as *u8, st4[CES_S_RETRACTS])
282 gv_kv("census_calibrated" as *u8, st[CES_S_CALIBRATED])
283 gv_kv("ledger_bytes" as *u8, lo)
284 return gv_verdict("nx_costest_gate" as *u8, c, "the cost estimator proven on known answers and planted plan rows: the integer sqrt floors, the deci-u parser accepts one fractional digit and refuses the rest by name, the three-point aggregate sums medians and root-sum-squares the half-widths inside the correlated bound, the quantile rank rule and its derived distinct-rank floor hold, the compute rules and the hours conversion are exact, the calibration census calibrates the rungs it can and excludes the rest by name with a partition that sums, and the ledger line round-trips through the one grammar while a malformed line is refused and an absent ledger reads absent" as *u8)
285}