code wiki / (root) / nx_bright_prep_gate.nx

nx_bright_prep_gate.nx source

↩ module page · 200 lines · 11000 B

1// nx_bright_prep_gate.nx -- GATE for nx_bright_prep (BRIGHT reshaped into the BEIR layout), driven IN-PROCESS through 2// bp_run on the pinned pony fixtures (search.refs brightds26) into a /tmp tree: the receipt must reproduce the card 3// (112 queries, 2219 qrels, 112 excluded pairs, 7894 corpus rows, 0 orphans, 2317793 corpus bytes), the files must 4// carry the shapes nx_beir_eval reads (queries.tsv row 0 is id 0 TAB the known query prefix; qrels/test.tsv opens 5// with the BEIR header then a score-1 row for the known first gold id; excluded.tsv row 0 is 0 TAB N/A), the licence 6// must sit beside the bytes and name cc-by-4.0, and two runs must be byte-identical. Neg-controls: a missing examples 7// file refuses at examples-open; the documents file offered as the examples file refuses at examples-columns (it has 8// no query, gold_ids or excluded_ids); a missing documents file refuses at documents-open. SKIPs when the fixtures 9// are absent, never acquits. Expected byte strings are BUILT at run time from named pieces and byte constants (a tab 10// or newline spelled as an escape inside a literal is a lexer contract this gate does not depend on). 11// license_tier: ORIGINAL No hw writes (Rule 26). 12import "nx_syscalls.nx" 13import "nx_gate_verdict.nx" 14import "nx_bright_prep.nx" 15 16const G_ROOT: *u8 = "/tmp/nx_bright_prep_gate" 17const G_OUT_A: *u8 = "/tmp/nx_bright_prep_gate/bright/pony" 18const G_OUT_B: *u8 = "/tmp/nx_bright_prep_gate/bright2/pony" 19const G_QUERIES_A: *u8 = "/tmp/nx_bright_prep_gate/bright/pony/queries.tsv" 20const G_QRELS_A: *u8 = "/tmp/nx_bright_prep_gate/bright/pony/qrels/test.tsv" 21const G_EXCL_A: *u8 = "/tmp/nx_bright_prep_gate/bright/pony/excluded.tsv" 22const G_CORPUS_A: *u8 = "/tmp/nx_bright_prep_gate/bright/pony/corpus.tsv" 23const G_LICENSE_A: *u8 = "/tmp/nx_bright_prep_gate/bright/LICENSE" 24const G_QUERIES_B: *u8 = "/tmp/nx_bright_prep_gate/bright2/pony/queries.tsv" 25const G_QRELS_B: *u8 = "/tmp/nx_bright_prep_gate/bright2/pony/qrels/test.tsv" 26const G_CORPUS_B: *u8 = "/tmp/nx_bright_prep_gate/bright2/pony/corpus.tsv" 27const G_EX_A: *u8 = "knowledge/fetched/cmp_search_bright_examples_pony.parquet" 28const G_EX_B: *u8 = "../knowledge/fetched/cmp_search_bright_examples_pony.parquet" 29const G_DOC_A: *u8 = "knowledge/fetched/cmp_search_bright_documents_pony.parquet" 30const G_DOC_B: *u8 = "../knowledge/fetched/cmp_search_bright_documents_pony.parquet" 31const G_ABSENT: *u8 = "/tmp/nx_bright_prep_gate/no_such_file.parquet" 32const G_MODE_DIR: i64 = 0x1ed 33const G_I64: i64 = 8 34const G_EXPECT_CAP: i64 = 256 35// the card and the measured pony receipt (search.plan 1789433620) 36const G_QUERIES: i64 = 112 37const G_QRELS: i64 = 2219 38const G_EXCL: i64 = 112 39const G_CORPUS: i64 = 7894 40const G_CORPUS_BYTES: i64 = 2317793 41// pieces of the expected rows; joined at run time with PQ_TAB and PQ_NL 42const G_ZERO: *u8 = "0" 43const G_ONE: *u8 = "1" 44const G_NA: *u8 = "N/A" 45const G_Q0_TEXT: *u8 = "I will use the programming language pony" 46const G_H1: *u8 = "query-id" 47const G_H2: *u8 = "corpus-id" 48const G_H3: *u8 = "score" 49const G_GOLD0: *u8 = "Pony/4_control-structures_13.txt" 50const G_CORPUS0_ID: *u8 = "Pony/src-builtin-runtime_options-_1.txt" 51const G_LIC_MARK: *u8 = "cc-by-4.0" 52 53func g_slen(s: *u8) -> i64 { 54 var n: i64 = 0 55 while (s[n] & PQ_BYTE) as i64 != 0 { n = n + 1 } 56 return n 57} 58func g_cat(dst: *u8, off: i64, s: *u8) -> i64 { 59 let n: i64 = g_slen(s) 60 var i: i64 = 0 61 while i < n { dst[off + i] = s[i]; i = i + 1 } 62 dst[off + n] = 0 as u8 63 return off + n 64} 65func g_catb(dst: *u8, off: i64, b: i64) -> i64 { 66 dst[off] = b as u8 67 dst[off + 1] = 0 as u8 68 return off + 1 69} 70func g_read(path: *u8, lenp: *i64) -> *u8 { 71 lenp[0] = 0 72 return sys_read_file(path, lenp) 73} 74func g_starts(buf: *u8, n: i64, s: *u8) -> i64 { 75 let m: i64 = g_slen(s) 76 if n < m { return 0 } 77 var i: i64 = 0 78 while i < m { if (buf[i] & PQ_BYTE) as i64 != (s[i] & PQ_BYTE) as i64 { return 0 } i = i + 1 } 79 return 1 80} 81func g_contains(buf: *u8, n: i64, s: *u8) -> i64 { 82 let m: i64 = g_slen(s) 83 var i: i64 = 0 84 while i + m <= n { 85 var j: i64 = 0 86 var ok: i64 = 1 87 while j < m { if (buf[i + j] & PQ_BYTE) as i64 != (s[j] & PQ_BYTE) as i64 { ok = 0; j = m } else { j = j + 1 } } 88 if ok == 1 { return 1 } 89 i = i + 1 90 } 91 return 0 92} 93func g_files_equal(a: *u8, b: *u8) -> i64 { 94 let la: *i64 = sys_mmap(G_I64) as *i64 95 let lb: *i64 = sys_mmap(G_I64) as *i64 96 let ba: *u8 = g_read(a, la) 97 let bb: *u8 = g_read(b, lb) 98 if (ba as i64) == 0 || (bb as i64) == 0 { return 0 } 99 if la[0] != lb[0] { return 0 } 100 if la[0] <= 0 { return 0 } 101 var i: i64 = 0 102 while i < la[0] { if ba[i] != bb[i] { return 0 } i = i + 1 } 103 return 1 104} 105// the fixture path that opens from this CWD (serving root or buildroot), or 0 106func g_pick(a: *u8, b: *u8) -> *u8 { 107 let fd: i64 = sys_openat_rd(a) 108 if fd >= 0 { sys_close(fd); return a } 109 let fd2: i64 = sys_openat_rd(b) 110 if fd2 >= 0 { sys_close(fd2); return b } 111 return 0 as *u8 112} 113 114func main() -> i64 { 115 gv_head("=== nx_bright_prep_gate -- BRIGHT reshaped into the BEIR layout, proven on the pinned pony files ===" as *u8) 116 let c: *i64 = gv_ctr() 117 sys_mkdir(G_ROOT, G_MODE_DIR) 118 // expected rows, built from pieces 119 let q0: *u8 = sys_mmap(G_EXPECT_CAP) 120 var o: i64 = g_cat(q0, 0, G_ZERO) 121 o = g_catb(q0, o, PQ_TAB) 122 o = g_cat(q0, o, G_Q0_TEXT) 123 let rh: *u8 = sys_mmap(G_EXPECT_CAP) 124 o = g_cat(rh, 0, G_H1) 125 o = g_catb(rh, o, PQ_TAB) 126 o = g_cat(rh, o, G_H2) 127 o = g_catb(rh, o, PQ_TAB) 128 o = g_cat(rh, o, G_H3) 129 o = g_catb(rh, o, PQ_NL) 130 o = g_cat(rh, o, G_ZERO) 131 o = g_catb(rh, o, PQ_TAB) 132 o = g_cat(rh, o, G_GOLD0) 133 o = g_catb(rh, o, PQ_TAB) 134 o = g_cat(rh, o, G_ONE) 135 o = g_catb(rh, o, PQ_NL) 136 let x0: *u8 = sys_mmap(G_EXPECT_CAP) 137 o = g_cat(x0, 0, G_ZERO) 138 o = g_catb(x0, o, PQ_TAB) 139 o = g_cat(x0, o, G_NA) 140 o = g_catb(x0, o, PQ_NL) 141 let c0: *u8 = sys_mmap(G_EXPECT_CAP) 142 o = g_cat(c0, 0, G_CORPUS0_ID) 143 o = g_catb(c0, o, PQ_TAB) 144 let exf: *u8 = g_pick(G_EX_A, G_EX_B) 145 let docf: *u8 = g_pick(G_DOC_A, G_DOC_B) 146 let present: i64 = (((exf as i64) != 0) as i64) * (((docf as i64) != 0) as i64) 147 if gv_need("the pinned BRIGHT pony examples and documents parquet files (knowledge/fetched, search.refs brightds26)" as *u8, present, c) == 1 { 148 let st: *i64 = sys_mmap(BR_SLOTS * G_I64) as *i64 149 gv_check_eq("bp_run-on-pony-returns-OK" as *u8, bp_run(exf, docf, G_OUT_A, st), 0, c) 150 gv_check_eq("stage-is-none-after-OK" as *u8, st[BR_STAGE], BR_ST_NONE, c) 151 gv_check_eq("queries-equal-the-card (112)" as *u8, st[BR_QUERIES], G_QUERIES, c) 152 gv_check_eq("queries-equal-the-file's-declared-rows" as *u8, st[BR_QUERIES], st[BR_QDECL], c) 153 gv_check_eq("no-null-queries" as *u8, st[BR_NULLQ], 0, c) 154 gv_check_eq("qrels-are-the-2219-gold_ids-elements" as *u8, st[BR_QRELS], G_QRELS, c) 155 gv_check_eq("excluded-pairs-are-112 (one N/A per query)" as *u8, st[BR_EXCL], G_EXCL, c) 156 gv_check_eq("no-orphans" as *u8, st[BR_ORPHANS], 0, c) 157 gv_check_eq("corpus-rows-equal-the-card (7894)" as *u8, st[BR_CORPUS_WRITTEN], G_CORPUS, c) 158 gv_check_eq("corpus-written-equals-the-documents-file's-declared-rows" as *u8, st[BR_CORPUS_WRITTEN], st[BR_CORPUS_DECL], c) 159 gv_check_eq("corpus-has-no-null-rows" as *u8, st[BR_CORPUS_NULL], 0, c) 160 gv_check_eq("corpus-bytes-are-the-measured-2317793 (a determinism KAT)" as *u8, st[BR_CORPUS_BYTES], G_CORPUS_BYTES, c) 161 gv_check_eq("the-receipt-verdict-is-OK" as *u8, bp_verdict(st), 1, c) 162 let lp: *i64 = sys_mmap(G_I64) as *i64 163 let qb: *u8 = g_read(G_QUERIES_A, lp) 164 gv_check("queries.tsv-row-0-is-id-0-TAB-the-known-query" as *u8, g_starts(qb, lp[0], q0), c) 165 let rb: *u8 = g_read(G_QRELS_A, lp) 166 gv_check("qrels-opens-with-the-BEIR-header-then-the-first-gold-id-at-score-1" as *u8, g_starts(rb, lp[0], rh), c) 167 let xb: *u8 = g_read(G_EXCL_A, lp) 168 gv_check("excluded.tsv-row-0-is-0-TAB-N/A" as *u8, g_starts(xb, lp[0], x0), c) 169 let cb: *u8 = g_read(G_CORPUS_A, lp) 170 gv_check("corpus.tsv-row-0-starts-with-the-first-document-id-and-a-tab" as *u8, g_starts(cb, lp[0], c0), c) 171 let lb: *u8 = g_read(G_LICENSE_A, lp) 172 gv_check("the-LICENSE-sits-beside-the-split-directory" as *u8, (lp[0] > 0) as i64, c) 173 gv_check("the-LICENSE-names-cc-by-4.0" as *u8, g_contains(lb, lp[0], G_LIC_MARK), c) 174 let st2: *i64 = sys_mmap(BR_SLOTS * G_I64) as *i64 175 gv_check_eq("a-second-run-into-another-tree-returns-OK" as *u8, bp_run(exf, docf, G_OUT_B, st2), 0, c) 176 gv_check("two-runs-write-byte-identical-queries.tsv" as *u8, g_files_equal(G_QUERIES_A, G_QUERIES_B), c) 177 gv_check("two-runs-write-byte-identical-qrels" as *u8, g_files_equal(G_QRELS_A, G_QRELS_B), c) 178 gv_check("two-runs-write-byte-identical-corpus.tsv" as *u8, g_files_equal(G_CORPUS_A, G_CORPUS_B), c) 179 // neg-controls 180 let st3: *i64 = sys_mmap(BR_SLOTS * G_I64) as *i64 181 let rc3: i64 = bp_run(G_ABSENT, docf, G_OUT_B, st3) 182 gv_check_eq("neg-control-a-missing-examples-file-refuses-CANNOT-OPEN" as *u8, rc3, PQ_E_OPEN, c) 183 gv_check_eq("neg-control-and-names-the-examples-open-stage" as *u8, st3[BR_STAGE], BR_ST_EX_OPEN, c) 184 let st4: *i64 = sys_mmap(BR_SLOTS * G_I64) as *i64 185 let rc4: i64 = bp_run(docf, docf, G_OUT_B, st4) 186 gv_check_eq("neg-control-the-documents-file-as-examples-refuses-OUT-OF-RANGE (no query, gold_ids, excluded_ids columns)" as *u8, rc4, PQ_E_ARG, c) 187 gv_check_eq("neg-control-and-names-the-examples-columns-stage" as *u8, st4[BR_STAGE], BR_ST_EX_COLUMNS, c) 188 let st5: *i64 = sys_mmap(BR_SLOTS * G_I64) as *i64 189 let rc5: i64 = bp_run(exf, G_ABSENT, G_OUT_B, st5) 190 gv_check_eq("neg-control-a-missing-documents-file-refuses-CANNOT-OPEN" as *u8, rc5, PQ_E_OPEN, c) 191 gv_check_eq("neg-control-and-names-the-documents-open-stage" as *u8, st5[BR_STAGE], BR_ST_DOCS_OPEN, c) 192 gv_values_head() 193 gv_kv("pony_queries" as *u8, st[BR_QUERIES]) 194 gv_kv("pony_qrels" as *u8, st[BR_QRELS]) 195 gv_kv("pony_excluded" as *u8, st[BR_EXCL]) 196 gv_kv("pony_corpus_rows" as *u8, st[BR_CORPUS_WRITTEN]) 197 gv_kv("pony_corpus_bytes" as *u8, st[BR_CORPUS_BYTES]) 198 } 199 return gv_verdict("nx_bright_prep_gate" as *u8, c, "nx_bright_prep proven in-process on the pinned BRIGHT pony files: the receipt reproduces the card (112 queries, 2219 qrels, 112 excluded pairs, 7894 corpus rows, 0 orphans, the measured corpus byte count), every output file carries the shape nx_beir_eval reads, the licence sits beside the bytes and names cc-by-4.0, two runs are byte-identical, and a missing examples file, a missing documents file and a documents file offered as examples each refuse with the stage named; SKIPs when the fixtures are absent" as *u8) 200}