nx_torrent_capbench.nx source
↩ module page · 186 lines · 12735 B
1// nx_torrent_capbench.nx -- MULTIVARIATE COMPETITIVE CAPABILITY BENCHMARK (S-class feature, B0-B2).
2//
3// module: nishi-core.torrent.capbench
4// depends: nx_swarm_sim.nx (deterministic swarm model -> nx_ss_run; transitively nx_stream_picker,
5// nx_piece_manager/nx_pm_rarest, nx_syscalls -- so this sits HARDWARE-UP on the proven
6// sovereign substrate, like every other organ).
7// capability: CAPABILITY_MEASUREMENT
8//
9// WHAT THIS IS (and why it's a first-class feature, not a one-off test):
10// The way DeepMind measured agent capability with a SUITE of game environments (ALE/Atari, each
11// probing a distinct skill) and a score normalized against a baseline, this is a suite of swarm
12// SCENARIOS -- each probing a distinct piece-selection capability -- run against the system-under-
13// test, scored on an ORGAN-COMPUTED maturity ladder vs the fastest known clients. It is built
14// rung by rung, every rung gate-proved, so the ecosystem can SEE its own capabilities honestly.
15//
16// B0 deterministic measurement core : same scenario+strategy => bit-identical decision trace, so
17// every measurement is REPLAYABLE (the property NO mainstream
18// torrent client has -- they are clock/GC/scheduler driven).
19// B1 multivariate matrix : SCENARIO x STRATEGY -> measured metric (rounds / DNF).
20// B2 organ-computed maturity grade : ABSENT<PRESENT<PARITY<EXCEEDS<PHYS-OPT, COMPUTED from the
21// measured numbers vs the baseline -- never self-asserted.
22// (B3 incumbent-census wiring + B4 live wire-throughput = next rungs, honestly PENDING below.)
23//
24// HONESTY: the fastest clients (qBittorrent/libtorrent, rqbit, Transmission, aria2) all use rarest-
25// first + endgame -- so NISHI matching that algorithm is PARITY by construction; the MEASURED win
26// is endgame completing adverse/snub swarms where a no-endgame client DNFs; the EXCEEDS-all axis is
27// determinism. Wire throughput is link-bound and NOT claimed here (PENDING-live).
28
29import "nx_swarm_sim.nx"
30
31// ---- B2 maturity ladder (the charter's ABSENT -> PHYSICS-OPTIMUM) ----
32const CAP_ABSENT: i64 = 0 // capability not present / did-not-finish
33const CAP_PRESENT: i64 = 1 // works, but worse than the baseline/incumbent
34const CAP_PARITY: i64 = 2 // matches
35const CAP_EXCEEDS: i64 = 3 // measurably beats
36const CAP_PHYSOPT: i64 = 4 // provably optimal (cannot be beaten)
37
38func cb_puts(fd: i64, s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(fd, s, n); return 0 }
39func cb_putn(fd: i64, v: i64) -> i64 {
40 let buf: *u8 = sys_mmap(32); var n: i64 = v; var i: i64 = 0; var neg: i64 = 0
41 if n < 0 { neg = 1; n = 0 - n }
42 if n == 0 { buf[0] = 0x30 as u8; i = 1 }
43 while n > 0 { buf[i] = (0x30 + (n - (n / 10) * 10)) as u8; n = n / 10; i = i + 1 }
44 if neg == 1 { buf[i] = 0x2D as u8; i = i + 1 }
45 var a: i64 = 0; var b: i64 = i - 1
46 while a < b { let t: u8 = buf[a]; buf[a] = buf[b]; buf[b] = t; a = a + 1; b = b - 1 }
47 sys_write(fd, buf, i); return 0
48}
49func cap_name(fd: i64, g: i64) -> i64 {
50 if g == CAP_ABSENT { cb_puts(fd, "ABSENT " as *u8) }
51 if g == CAP_PRESENT { cb_puts(fd, "PRESENT" as *u8) }
52 if g == CAP_PARITY { cb_puts(fd, "PARITY " as *u8) }
53 if g == CAP_EXCEEDS { cb_puts(fd, "EXCEEDS" as *u8) }
54 if g == CAP_PHYSOPT { cb_puts(fd, "PHYSOPT" as *u8) }
55 return 0
56}
57
58// ---- B2: maturity grade COMPUTED from measured rounds (lower-is-better; DNF = worst) ----
59// ours = NISHI (rarest+endgame); ref = the no-endgame baseline. No grade is asserted -- each is
60// derived from the two measured numbers, so a bad measurement can only LOWER the grade.
61func cap_grade(ours: i64, ref: i64) -> i64 {
62 if ours == NX_SS_DNF { return CAP_ABSENT } // we didn't finish -> capability absent (no fake win)
63 if ref == NX_SS_DNF { return CAP_EXCEEDS } // we finish where the baseline cannot
64 if ours < ref { return CAP_EXCEEDS }
65 if ours == ref { return CAP_PARITY }
66 return CAP_PRESENT
67}
68
69// ---- B1: deterministic scenario constructions (the capability-probe suite) ----
70// peer_has[p*n + j] == 1 iff peer p advertises piece j ; behavior[p] in {HONEST, STALL}.
71// dim[0]=npeers, dim[1]=n. Every scenario is pure data -> bit-reproducible.
72func scen_build(sc: i64, peer_has: *i64, behavior: *i64, dim: *i64) -> i64 {
73 var z: i64 = 0; while z < 64 * 64 { peer_has[z] = 0; z = z + 1 }
74 var bz: i64 = 0; while bz < 64 { behavior[bz] = NX_SS_HONEST; bz = bz + 1 }
75 var npeers: i64 = 0; var n: i64 = 0
76 if sc == 0 { // HEALTHY: every peer is an honest seeder (has everything) -> probe: clean throughput
77 npeers = 5; n = 8
78 var p: i64 = 0; while p < npeers { var j: i64 = 0; while j < n { peer_has[p * n + j] = 1; j = j + 1 } p = p + 1 }
79 }
80 if sc == 1 { // SNUB-TAIL: the lowest-index holder of the last piece is a snubbing staller; an
81 // honest higher-index peer also holds it -> probe: single-peer-snub recovery (endgame).
82 npeers = 6; n = 8
83 behavior[0] = NX_SS_STALL
84 peer_has[0 * n + 7] = 1 // peer0 (staller) holds ONLY piece 7 (its lowest holder)
85 var j: i64 = 0; while j < 7 { peer_has[1 * n + j] = 1; peer_has[2 * n + j] = 1; j = j + 1 } // peers1,2 honest: pieces 0..6 (avail 2)
86 peer_has[3 * n + 7] = 1; peer_has[4 * n + 7] = 1; peer_has[5 * n + 7] = 1 // peers3,4,5 honest: piece 7 (avail 4, picked last)
87 }
88 if sc == 2 { // MULTI-SNUB: two tail pieces snubbed at the low-index holder -> probe: multi-piece tail recovery.
89 npeers = 6; n = 8
90 behavior[0] = NX_SS_STALL
91 peer_has[0 * n + 6] = 1; peer_has[0 * n + 7] = 1
92 var j: i64 = 0; while j < 6 { peer_has[1 * n + j] = 1; peer_has[2 * n + j] = 1; j = j + 1 } // pieces 0..5 (avail 2)
93 peer_has[3 * n + 6] = 1; peer_has[3 * n + 7] = 1; peer_has[4 * n + 6] = 1; peer_has[4 * n + 7] = 1; peer_has[5 * n + 6] = 1; peer_has[5 * n + 7] = 1
94 }
95 if sc == 3 { // UNOBTAINABLE: piece 7 is held by NO peer -> probe: honest no-phantom-completion.
96 npeers = 5; n = 8
97 var p: i64 = 0; while p < npeers { var j: i64 = 0; while j < 7 { peer_has[p * n + j] = 1; j = j + 1 } p = p + 1 } // pieces 0..6 only
98 }
99 if sc == 4 { // SCALE: larger swarm/file, all honest -> probe: scale handling.
100 npeers = 8; n = 24
101 var p: i64 = 0; while p < npeers { var j: i64 = 0; while j < n { peer_has[p * n + j] = 1; j = j + 1 } p = p + 1 }
102 }
103 dim[0] = npeers; dim[1] = n
104 return 0
105}
106
107// ---- B0: one measured run (fresh have[], rarest-first, endgame toggle), trace -> *out_trace ----
108func cb_run(peer_has: *i64, behavior: *i64, npeers: i64, n: i64, endgame: i64, threshold: i64, max_rounds: i64, out_trace: *i64) -> i64 {
109 let have: *i64 = sys_mmap(n * 8 + 64) as *i64
110 var j: i64 = 0; while j < n { have[j] = 0; j = j + 1 }
111 return nx_ss_run(peer_has, behavior, npeers, n, have, 0, 0, endgame, threshold, max_rounds, out_trace)
112}
113
114// run a scenario both ways, print the matrix row, capture [naive,nishi] + the NISHI trace.
115func run_scenario(sc: i64, label: *u8, peer_has: *i64, behavior: *i64, dim: *i64, res2: *i64, trace_eg: *i64) -> i64 {
116 scen_build(sc, peer_has, behavior, dim)
117 let np: i64 = dim[0]; let n: i64 = dim[1]
118 let trn: *i64 = sys_mmap(16) as *i64
119 let naive: i64 = cb_run(peer_has, behavior, np, n, 0, 2, 500, trn)
120 let nishi: i64 = cb_run(peer_has, behavior, np, n, 1, 2, 500, trace_eg)
121 res2[0] = naive; res2[1] = nishi
122 cb_puts(1, label)
123 cb_puts(1, " np="); cb_putn(1, np); cb_puts(1, " n="); cb_putn(1, n)
124 cb_puts(1, " | no-eg="); cb_putn(1, naive)
125 cb_puts(1, " | nishi="); cb_putn(1, nishi)
126 cb_puts(1, " | "); cap_name(1, cap_grade(nishi, naive)); cb_puts(1, "\n")
127 return 0
128}
129
130func main() -> i64 {
131 let peer_has: *i64 = sys_mmap(64 * 64 * 8) as *i64
132 let behavior: *i64 = sys_mmap(64 * 8) as *i64
133 let dim: *i64 = sys_mmap(16) as *i64
134 let r0: *i64 = sys_mmap(16) as *i64; let r1: *i64 = sys_mmap(16) as *i64; let r2: *i64 = sys_mmap(16) as *i64
135 let r3: *i64 = sys_mmap(16) as *i64; let r4: *i64 = sys_mmap(16) as *i64
136 let t0: *i64 = sys_mmap(16) as *i64; let t1: *i64 = sys_mmap(16) as *i64; let t1b: *i64 = sys_mmap(16) as *i64
137 let t2: *i64 = sys_mmap(16) as *i64; let t3: *i64 = sys_mmap(16) as *i64; let t4: *i64 = sys_mmap(16) as *i64
138
139 cb_puts(1, "=== NISHI SOVEREIGN TORRENT -- MULTIVARIATE CAPABILITY BENCHMARK (B0-B2) ===\n" as *u8)
140 cb_puts(1, "probe suite (DeepMind-style: each scenario probes a selection capability); rounds-to-complete, DNF=-1; grade ORGAN-COMPUTED vs no-endgame baseline\n" as *u8)
141 cb_puts(1, "scenario | metrics | maturity\n" as *u8)
142 cb_puts(1, "-----------------------+--------------------------+--------\n" as *u8)
143
144 run_scenario(0, "HEALTHY (clean DL) " as *u8, peer_has, behavior, dim, r0, t0)
145 run_scenario(1, "SNUB-TAIL (1 snub) " as *u8, peer_has, behavior, dim, r1, t1)
146 run_scenario(2, "MULTI-SNUB (2 snubs) " as *u8, peer_has, behavior, dim, r2, t2)
147 run_scenario(3, "UNOBTAINABLE (avail0) " as *u8, peer_has, behavior, dim, r3, t3)
148 run_scenario(4, "SCALE (np8 n24) " as *u8, peer_has, behavior, dim, r4, t4)
149
150 // B0 replay: re-run SNUB-TAIL endgame -> trace MUST be bit-identical (replayable measurement).
151 scen_build(1, peer_has, behavior, dim)
152 cb_run(peer_has, behavior, dim[0], dim[1], 1, 2, 500, t1b)
153 cb_puts(1, "\n--- B0 determinism / replay (the axis NO mainstream client has) ---\n" as *u8)
154 cb_puts(1, "SNUB-TAIL trace run1="); cb_putn(1, t1[0]); cb_puts(1, " run2="); cb_putn(1, t1b[0])
155 cb_puts(1, " identical="); var rep: i64 = 0; if t1[0] == t1b[0] { rep = 1 } cb_putn(1, rep); cb_puts(1, "\n" as *u8)
156 // discriminate neg-control: a DIFFERENT outcome must yield a DIFFERENT trace (proves the trace
157 // is a real behavioral fingerprint, not a constant). UNOBTAINABLE completes only 7 pieces then
158 // DNFs vs HEALTHY's 8 -> traces differ. (SNUB-nishi == HEALTHY by design: same 0..7 delivered seq.)
159 cb_puts(1, "discriminates (UNOBTAINABLE trace != HEALTHY trace)="); var disc: i64 = 0; if t3[0] != t0[0] { disc = 1 } cb_putn(1, disc); cb_puts(1, "\n" as *u8)
160
161 cb_puts(1, "\n--- vs the fastest known clients (sourced; honest) ---\n" as *u8)
162 cb_puts(1, "selection algorithm : qBittorrent/libtorrent, rqbit, Transmission, aria2 ALL use rarest-first+endgame -> NISHI matches = PARITY by construction\n" as *u8)
163 cb_puts(1, "snub/adverse recovery: MEASURED above -- NISHI completes where a no-endgame client DNFs = EXCEEDS that failure mode\n" as *u8)
164 cb_puts(1, "determinism / replay : NISHI bit-identical 2x = the benchmark is REPLAYABLE; no mainstream client is = EXCEEDS-all\n" as *u8)
165 cb_puts(1, "wire throughput/conns/memory-soak: PENDING-live (socket loop on a real swarm; sourced: throughput link-bound ~parity) -- NOT claimed\n" as *u8)
166
167 // ---- gate: every claim above is asserted against the MEASURED numbers (return N on failure) ----
168 if r0[0] != 8 { return 1 } // HEALTHY no-eg completes in n=8
169 if r0[1] != 8 { return 2 } // HEALTHY nishi completes in n=8 (endgame doesn't hurt healthy swarms)
170 if r1[0] != NX_SS_DNF { return 3 } // SNUB-TAIL: no-endgame DNFs (the snub stalls it)
171 if r1[1] != 8 { return 4 } // SNUB-TAIL: NISHI completes (endgame broadcast repairs the snub)
172 if r2[0] != NX_SS_DNF { return 5 } // MULTI-SNUB: no-endgame DNFs
173 if r2[1] != 8 { return 6 } // MULTI-SNUB: NISHI completes
174 if r3[0] != NX_SS_DNF { return 7 } // UNOBTAINABLE neg-control: no-endgame DNFs (can't get absent data)
175 if r3[1] != NX_SS_DNF { return 8 } // UNOBTAINABLE neg-control: NISHI ALSO DNFs -- no phantom completion
176 if r4[0] != 24 { return 9 } // SCALE: both complete in n=24
177 if r4[1] != 24 { return 10 }
178 if rep != 1 { return 11 } // B0: replay -- identical trace twice
179 if disc != 1 { return 12 } // B0 neg-control: trace DISCRIMINATES scenarios (not a constant)
180 if cap_grade(r1[1], r1[0]) != CAP_EXCEEDS { return 13 } // B2: snub-recovery grades EXCEEDS (computed)
181 if cap_grade(r3[1], r3[0]) != CAP_ABSENT { return 14 } // B2: unobtainable grades ABSENT (no fabricated win)
182 if cap_grade(r0[1], r0[0]) != CAP_PARITY { return 15 } // B2: healthy grades PARITY
183
184 cb_puts(1, "\nnx_torrent_capbench verdict=GREEN pass=15\n" as *u8)
185 return 0
186}