@holoscript/core 8.0.14 → 8.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/README.md +6 -13
  2. package/bin/holo-decision.mjs +0 -0
  3. package/bin/holoscript.cjs +0 -0
  4. package/dist/{GLTFPipeline-6LS3UDYX.js → GLTFPipeline-FRBZIATS.js} +6 -6
  5. package/dist/{GLTFPipeline-VTI6PRRQ.cjs → GLTFPipeline-MTPP444P.cjs} +10 -10
  6. package/dist/{HoloCompositionParser-GILABNN3.js → HoloCompositionParser-2GVQAZ2X.js} +7 -7
  7. package/dist/HoloCompositionParser-3NDF6BMX.cjs +45 -0
  8. package/dist/HoloScriptPlusParser-URSIBEAW.cjs +30 -0
  9. package/dist/HoloScriptPlusParser-YCV6L7GI.js +13 -0
  10. package/dist/{HoloScriptRuntime-YBYXJHJN.cjs → HoloScriptRuntime-CRWI6C3P.cjs} +5 -5
  11. package/dist/{HoloScriptRuntime-UTRLJI5L.js → HoloScriptRuntime-IAZGHPFP.js} +4 -4
  12. package/dist/{SceneIRCompiler-VX75RB6H.js → SceneIRCompiler-BJQMKLWL.js} +6 -6
  13. package/dist/{SceneIRCompiler-7KQ5NKAU.cjs → SceneIRCompiler-RTPPDQAV.cjs} +11 -11
  14. package/dist/{chunk-Y2OCKXVD.js → chunk-22AULOAL.js} +5 -5
  15. package/dist/{chunk-D44CEFY4.cjs → chunk-2DJIS7TH.cjs} +5 -5
  16. package/dist/{chunk-LHUDAJQT.cjs → chunk-2PVEXEOL.cjs} +5 -5
  17. package/dist/{chunk-M7XR3F53.js → chunk-2UP2J3OK.js} +4 -4
  18. package/dist/{chunk-3KHRZTNW.js → chunk-3AUYBQ5I.js} +3 -3
  19. package/dist/{chunk-UKEK2NZJ.js → chunk-3MQAOMKD.js} +3 -3
  20. package/dist/{chunk-FWKEY4LD.js → chunk-4AGNARX6.js} +3 -3
  21. package/dist/{chunk-7ITJP33Q.cjs → chunk-4CQ7ULXZ.cjs} +3 -3
  22. package/dist/{chunk-ORBVCOTC.js → chunk-5LCJDX5A.js} +3 -3
  23. package/dist/{chunk-IK6Z2HNC.js → chunk-6OQHLNTT.js} +2 -2
  24. package/dist/{chunk-EI3J6LTW.cjs → chunk-6RDHWSZM.cjs} +217 -217
  25. package/dist/{chunk-73EDVY5D.js → chunk-7AY66PZP.js} +3 -3
  26. package/dist/{chunk-6FCNMTL5.js → chunk-7HDRN5BW.js} +4 -4
  27. package/dist/{chunk-TMNAKNV2.cjs → chunk-7YKNV2BE.cjs} +5 -5
  28. package/dist/{chunk-R5VKLUMR.js → chunk-AAUQTR7I.js} +4 -4
  29. package/dist/{chunk-HCONR4J6.cjs → chunk-AN3ZH7M7.cjs} +38 -38
  30. package/dist/{chunk-YW3I2FQL.js → chunk-ANMME7XT.js} +4 -2
  31. package/dist/{chunk-47XZ62KM.js → chunk-ATRAK4RC.js} +5 -5
  32. package/dist/{chunk-W4AJMMQR.js → chunk-AUF7HFOO.js} +60 -22
  33. package/dist/{chunk-SKVBUGMC.cjs → chunk-AUMTQV64.cjs} +7 -7
  34. package/dist/{chunk-N7MIIDLI.cjs → chunk-AUU4ACJP.cjs} +8 -8
  35. package/dist/{chunk-QQFB4RT2.cjs → chunk-BTVHY3UB.cjs} +2 -2
  36. package/dist/{chunk-SE2Y5BSL.cjs → chunk-CMEINO5I.cjs} +186 -70
  37. package/dist/{chunk-YMI3ED3B.cjs → chunk-CRUIGXF7.cjs} +5 -5
  38. package/dist/{chunk-2E6PP5UE.cjs → chunk-E2SNPMBO.cjs} +11 -11
  39. package/dist/{chunk-GI5YYZH6.js → chunk-E4YS5SIZ.js} +90 -25
  40. package/dist/{chunk-62OYZT6Q.js → chunk-EKNWUSGW.js} +3 -3
  41. package/dist/{chunk-RVN7OPCP.js → chunk-ETIJOUIO.js} +4 -4
  42. package/dist/{chunk-C73GVAYC.js → chunk-F33KLYOS.js} +5 -5
  43. package/dist/{chunk-4CRMVEON.cjs → chunk-F47FEV4X.cjs} +40 -40
  44. package/dist/{chunk-FGXJPJ3W.cjs → chunk-FCGTI7FO.cjs} +4 -4
  45. package/dist/{chunk-OSKGCXAQ.cjs → chunk-FGTXAVKG.cjs} +5 -5
  46. package/dist/{chunk-XZC75AJ4.cjs → chunk-FPGYWNNA.cjs} +5 -5
  47. package/dist/{chunk-5B2AJKA5.cjs → chunk-FQ4MYZYU.cjs} +20 -20
  48. package/dist/{chunk-KOGPVAP6.js → chunk-FT4FGTR6.js} +3 -3
  49. package/dist/{chunk-N7IYRAFG.cjs → chunk-FVNV4WHQ.cjs} +14 -14
  50. package/dist/{chunk-SJIRCTIS.cjs → chunk-HSGJFCVJ.cjs} +2 -2
  51. package/dist/{chunk-TKDDIE3T.cjs → chunk-ILO2KMER.cjs} +4 -4
  52. package/dist/{chunk-GGH3ZYDB.cjs → chunk-IPBSNGAN.cjs} +92 -27
  53. package/dist/{chunk-JQCXLKAU.js → chunk-IX2U3RQT.js} +3 -3
  54. package/dist/{chunk-P65OIMJT.cjs → chunk-IYK6LMQ7.cjs} +7 -7
  55. package/dist/{chunk-NWKARJM2.js → chunk-J3VVM6GV.js} +4 -4
  56. package/dist/{chunk-FOM36K5I.cjs → chunk-J74S4ZMF.cjs} +18 -18
  57. package/dist/{chunk-36NPLOI4.cjs → chunk-JERWCCEJ.cjs} +4 -2
  58. package/dist/{chunk-VXHB6ZHY.js → chunk-JTDDLCSP.js} +4 -4
  59. package/dist/{chunk-GYJLP4BO.cjs → chunk-K53L47NH.cjs} +30 -30
  60. package/dist/{chunk-FHR2AVMA.cjs → chunk-LJTM5ONX.cjs} +23 -23
  61. package/dist/{chunk-JCVSCKUH.js → chunk-LJVVOVA6.js} +4 -4
  62. package/dist/{chunk-LQNL3IYV.cjs → chunk-LNJKBQ2B.cjs} +38 -38
  63. package/dist/{chunk-2GKF7JQ6.js → chunk-M2GDE3NV.js} +3 -3
  64. package/dist/{chunk-Z7NUL73U.js → chunk-MSZNGI5P.js} +3 -3
  65. package/dist/{chunk-B6JHTTMR.cjs → chunk-N2BOTBPG.cjs} +15 -15
  66. package/dist/{chunk-L4DBUX3N.cjs → chunk-NFALJJCH.cjs} +12 -12
  67. package/dist/{chunk-YBM34FUJ.cjs → chunk-NRZRBK25.cjs} +6 -6
  68. package/dist/{chunk-SNMQUWIO.cjs → chunk-NTSLNIY7.cjs} +10 -10
  69. package/dist/{chunk-645EWDZW.cjs → chunk-NZJOAWJM.cjs} +4 -4
  70. package/dist/{chunk-LGRKBTPM.js → chunk-OG7RKWWX.js} +3 -3
  71. package/dist/{chunk-OOP4S3GU.cjs → chunk-OQVHCYY4.cjs} +5 -5
  72. package/dist/{chunk-5T6BWIB7.js → chunk-PFZ5WLIP.js} +4 -4
  73. package/dist/{chunk-CESMPUEZ.cjs → chunk-PHLNABJD.cjs} +159 -145
  74. package/dist/{chunk-CHIZSMWD.js → chunk-PLK3DLTF.js} +3 -3
  75. package/dist/{chunk-4NEPHK2K.js → chunk-PMACVMHL.js} +3 -3
  76. package/dist/{chunk-EYHPTJ3F.js → chunk-PV2OXNP5.js} +40 -26
  77. package/dist/{chunk-KLM6QD6D.cjs → chunk-Q6VW7MGX.cjs} +14 -14
  78. package/dist/{chunk-YDSNDCV3.js → chunk-QC3CAVFN.js} +186 -69
  79. package/dist/{chunk-REN3LHO6.cjs → chunk-QKLEDRHN.cjs} +19 -19
  80. package/dist/{chunk-2EGGAZT3.js → chunk-QS27OYBU.js} +3 -3
  81. package/dist/{chunk-4376VHNJ.js → chunk-RUB7WL6C.js} +3 -3
  82. package/dist/{chunk-TZQKJOPC.js → chunk-TW2AH2ZS.js} +3 -3
  83. package/dist/{chunk-Q4J2K7FI.js → chunk-TZM6DKSJ.js} +6 -6
  84. package/dist/{chunk-ESSEF6U2.js → chunk-U227RWXB.js} +3 -3
  85. package/dist/{chunk-ERYKKPHW.cjs → chunk-U6CQOM5Q.cjs} +13 -13
  86. package/dist/{chunk-VMCR5QVI.js → chunk-ULT2QAV5.js} +4 -4
  87. package/dist/{chunk-VZI7S7P6.cjs → chunk-VSO6HPDZ.cjs} +7 -7
  88. package/dist/{chunk-QLPRI3QW.js → chunk-WQJMSSJT.js} +4 -4
  89. package/dist/{chunk-GILYQ5VH.cjs → chunk-WXSDBWGM.cjs} +4 -4
  90. package/dist/{chunk-42Z3SVHQ.js → chunk-X5PMMK7H.js} +3 -3
  91. package/dist/{chunk-ML4V5PVU.cjs → chunk-X5ZLSPU2.cjs} +74 -32
  92. package/dist/{chunk-PSWCJQS4.js → chunk-X727CQ7X.js} +5 -5
  93. package/dist/{chunk-YM7UUYR5.cjs → chunk-XHZYS4QO.cjs} +5 -5
  94. package/dist/{chunk-PZ46WRHX.cjs → chunk-XRQCTTDC.cjs} +8 -8
  95. package/dist/{chunk-IXFNA5TT.js → chunk-YBIHSN55.js} +4 -4
  96. package/dist/{chunk-BLCWQ225.js → chunk-Z574GVI3.js} +4 -4
  97. package/dist/{chunk-ZVQMKUGJ.js → chunk-Z5V3KA7L.js} +2 -2
  98. package/dist/{chunk-7ZKQ32XK.js → chunk-ZGDEOXGU.js} +4 -4
  99. package/dist/{chunk-VTFLKSJL.cjs → chunk-ZHW6TDZ6.cjs} +14 -14
  100. package/dist/{chunk-KYJD2UMV.js → chunk-ZPHCTPR6.js} +4 -4
  101. package/dist/{chunk-VA7THINF.cjs → chunk-ZXXC2GXB.cjs} +38 -38
  102. package/dist/cli/holoscript-runner.cjs +168 -19
  103. package/dist/cli/holoscript-runner.js +162 -13
  104. package/dist/compiler/agent-inference.cjs +7 -7
  105. package/dist/compiler/agent-inference.js +3 -3
  106. package/dist/compiler/android-xr.cjs +6 -6
  107. package/dist/compiler/android-xr.js +4 -4
  108. package/dist/compiler/android.cjs +5 -5
  109. package/dist/compiler/android.js +3 -3
  110. package/dist/compiler/context.cjs +5 -5
  111. package/dist/compiler/context.js +2 -2
  112. package/dist/compiler/daimon-seed.cjs +8 -8
  113. package/dist/compiler/daimon-seed.js +3 -3
  114. package/dist/compiler/domain-block-utils.cjs +164 -164
  115. package/dist/compiler/domain-block-utils.js +3 -3
  116. package/dist/compiler/dtdl.cjs +6 -6
  117. package/dist/compiler/dtdl.js +3 -3
  118. package/dist/compiler/gltf-pipeline.cjs +8 -8
  119. package/dist/compiler/gltf-pipeline.js +1 -1
  120. package/dist/compiler/godot.cjs +5 -5
  121. package/dist/compiler/godot.js +4 -4
  122. package/dist/compiler/incremental.cjs +7 -7
  123. package/dist/compiler/incremental.js +2 -2
  124. package/dist/compiler/index.cjs +1603 -204
  125. package/dist/compiler/index.d.ts +8 -0
  126. package/dist/compiler/index.js +1431 -55
  127. package/dist/compiler/ios.cjs +5 -5
  128. package/dist/compiler/ios.js +3 -3
  129. package/dist/compiler/llm-provider-capabilities.cjs +5 -5
  130. package/dist/compiler/llm-provider-capabilities.js +2 -2
  131. package/dist/compiler/openxr.cjs +5 -5
  132. package/dist/compiler/openxr.js +4 -4
  133. package/dist/compiler/sdf.cjs +6 -6
  134. package/dist/compiler/sdf.js +4 -4
  135. package/dist/compiler/state.cjs +5 -5
  136. package/dist/compiler/state.js +3 -3
  137. package/dist/compiler/trait-composition.cjs +6 -6
  138. package/dist/compiler/trait-composition.js +2 -2
  139. package/dist/compiler/unity.cjs +5 -5
  140. package/dist/compiler/unity.js +4 -4
  141. package/dist/compiler/unreal.cjs +6 -6
  142. package/dist/compiler/unreal.js +4 -4
  143. package/dist/compiler/urdf.cjs +13 -13
  144. package/dist/compiler/urdf.js +4 -4
  145. package/dist/compiler/usd-physics.cjs +6 -6
  146. package/dist/compiler/usd-physics.js +3 -3
  147. package/dist/compiler/visionos.cjs +5 -5
  148. package/dist/compiler/visionos.js +4 -4
  149. package/dist/compiler/vrchat.cjs +6 -6
  150. package/dist/compiler/vrchat.js +4 -4
  151. package/dist/compiler/wasm.cjs +9 -9
  152. package/dist/compiler/wasm.js +4 -4
  153. package/dist/compiler/webgpu.cjs +5 -5
  154. package/dist/compiler/webgpu.js +4 -4
  155. package/dist/constants.cjs +99 -99
  156. package/dist/constants.js +3 -3
  157. package/dist/debugger.cjs +5 -5
  158. package/dist/debugger.js +3 -3
  159. package/dist/{dist-GRMOP2UL.cjs → dist-YGATNURH.cjs} +705 -9
  160. package/dist/{dist-ZBUKU2JG.js → dist-ZEZXRCBG.js} +701 -10
  161. package/dist/entries/scripting.cjs +8 -8
  162. package/dist/entries/scripting.js +4 -4
  163. package/dist/evolution/index.cjs +20 -20
  164. package/dist/evolution/index.js +8 -8
  165. package/dist/index.cjs +871 -809
  166. package/dist/index.d.ts +8 -0
  167. package/dist/index.js +132 -70
  168. package/dist/parser/HoloCompositionTypes.d.ts +1 -1
  169. package/dist/parser.cjs +21 -21
  170. package/dist/parser.js +7 -7
  171. package/dist/reconstruction/index.cjs +63 -63
  172. package/dist/reconstruction/index.js +7 -7
  173. package/dist/runtime.cjs +9 -9
  174. package/dist/runtime.js +3 -3
  175. package/dist/traits/botanical-lotus.d.ts +61 -0
  176. package/dist/traits/index.cjs +664 -671
  177. package/dist/traits/index.d.ts +65 -0
  178. package/dist/traits/index.js +14 -21
  179. package/dist/types/HoloScriptPlus.d.ts +1 -1
  180. package/package.json +66 -64
  181. package/dist/HoloCompositionParser-ZVRYVEA5.cjs +0 -45
  182. package/dist/HoloScriptPlusParser-WTPRPRPR.cjs +0 -30
  183. package/dist/HoloScriptPlusParser-ZP53ECSL.js +0 -13
@@ -1,12 +1,352 @@
1
1
  import { __require } from './chunk-W4GABFCR.js';
2
2
 
3
3
  // ../snn-webgpu/dist/index.js
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
6
  var __require2 = /* @__PURE__ */ ((x) => typeof __require !== "undefined" ? __require : typeof Proxy !== "undefined" ? new Proxy(x, {
5
7
  get: (a, b) => (typeof __require !== "undefined" ? __require : a)[b]
6
8
  }) : x)(function(x) {
7
9
  if (typeof __require !== "undefined") return __require.apply(this, arguments);
8
10
  throw Error('Dynamic require of "' + x + '" is not supported');
9
11
  });
12
+ var __esm = (fn, res, err) => function __init() {
13
+ if (err) throw err[0];
14
+ try {
15
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
16
+ } catch (e) {
17
+ throw err = [e], e;
18
+ }
19
+ };
20
+ var __export = (target, all) => {
21
+ for (var name in all)
22
+ __defProp(target, name, { get: all[name], enumerable: true });
23
+ };
24
+ var qec_codes_exports = {};
25
+ __export(qec_codes_exports, {
26
+ DEFAULT_PRIOR: () => DEFAULT_PRIOR,
27
+ HX: () => HX,
28
+ HZ: () => HZ,
29
+ LOOKUP_X: () => LOOKUP_X,
30
+ LOOKUP_Z: () => LOOKUP_Z,
31
+ N: () => N,
32
+ XL: () => XL,
33
+ XSTAB: () => XSTAB,
34
+ ZL: () => ZL,
35
+ ZSTAB: () => ZSTAB,
36
+ bpMinSum: () => bpMinSum,
37
+ bpOsdDecode: () => bpOsdDecode,
38
+ codeDistance: () => codeDistance,
39
+ decodeReceipt: () => decodeReceipt,
40
+ decodeShot: () => decodeShot,
41
+ decodeX: () => decodeX,
42
+ decodeXBP: () => decodeXBP,
43
+ decodeZ: () => decodeZ,
44
+ decodeZBP: () => decodeZBP,
45
+ isLogicalX: () => isLogicalX,
46
+ isLogicalZ: () => isLogicalZ,
47
+ osd0: () => osd0,
48
+ overlapParity: () => overlapParity,
49
+ priorLLR: () => priorLLR,
50
+ stabsToMatrix: () => stabsToMatrix,
51
+ syndromeCosetAudit: () => syndromeCosetAudit,
52
+ syndromeX: () => syndromeX,
53
+ syndromeZ: () => syndromeZ,
54
+ tannerGraph: () => tannerGraph,
55
+ weight: () => weight,
56
+ xorVec: () => xorVec
57
+ });
58
+ function syndromeX(eX) {
59
+ return ZSTAB.map((s) => overlapParity(eX, s));
60
+ }
61
+ function syndromeZ(eZ) {
62
+ return XSTAB.map((s) => overlapParity(eZ, s));
63
+ }
64
+ function buildLookup(stabs) {
65
+ const table = /* @__PURE__ */ new Map();
66
+ for (let m = 0; m < 1 << N; m++) {
67
+ const err = vec();
68
+ for (let q = 0; q < N; q++) err[q] = m >> q & 1;
69
+ const s = stabs.map((st) => overlapParity(err, st)).join("");
70
+ const w = weight(err);
71
+ const prev = table.get(s);
72
+ if (!prev || w < prev.w) table.set(s, { correction: err.slice(), w });
73
+ }
74
+ return table;
75
+ }
76
+ function decodeX(eX) {
77
+ return LOOKUP_X.get(syndromeX(eX).join("")).correction;
78
+ }
79
+ function decodeZ(eZ) {
80
+ return LOOKUP_Z.get(syndromeZ(eZ).join("")).correction;
81
+ }
82
+ function isLogicalX(residualX) {
83
+ return (overlapParity(residualX, ZL) & 1) === 1;
84
+ }
85
+ function isLogicalZ(residualZ) {
86
+ return (overlapParity(residualZ, XL) & 1) === 1;
87
+ }
88
+ function decodeShot(eX, eZ) {
89
+ const resX = xorVec(eX, decodeX(eX));
90
+ const resZ = xorVec(eZ, decodeZ(eZ));
91
+ return isLogicalX(resX) || isLogicalZ(resZ);
92
+ }
93
+ function codeDistance() {
94
+ let d = Infinity;
95
+ for (let m = 1; m < 1 << N; m++) {
96
+ const e = vec();
97
+ for (let q = 0; q < N; q++) e[q] = m >> q & 1;
98
+ if (syndromeX(e).every((b) => b === 0) && isLogicalX(e)) d = Math.min(d, weight(e));
99
+ if (syndromeZ(e).every((b) => b === 0) && isLogicalZ(e)) d = Math.min(d, weight(e));
100
+ }
101
+ return d;
102
+ }
103
+ function stabsToMatrix(stabs, n = N) {
104
+ return stabs.map((s) => {
105
+ const row = new Array(n).fill(0);
106
+ for (const q of s) row[q] = 1;
107
+ return row;
108
+ });
109
+ }
110
+ function priorLLR(p) {
111
+ const pf = Math.min(Math.max(2 * p / 3, 1e-9), 0.5 - 1e-9);
112
+ return Math.log((1 - pf) / pf);
113
+ }
114
+ function bpMinSum(H, s, lambda, { maxIter = 30, alpha = 0.8125, gamma = 0.2 } = {}) {
115
+ const m = H.length;
116
+ const n = H[0].length;
117
+ const checkVars = H.map((row) => row.map((h, i) => h ? i : -1).filter((i) => i >= 0));
118
+ const varChecks = Array.from(
119
+ { length: n },
120
+ (_, i) => H.map((row, a) => row[i] ? a : -1).filter((a) => a >= 0)
121
+ );
122
+ const v2c = Array.from({ length: n }, () => ({}));
123
+ const c2v = Array.from({ length: m }, () => ({}));
124
+ for (let i = 0; i < n; i++) for (const a of varChecks[i]) v2c[i][a] = lambda;
125
+ const e = new Array(n).fill(0);
126
+ const posterior = new Array(n).fill(lambda);
127
+ let converged = false;
128
+ let iters = 0;
129
+ for (let it = 1; it <= maxIter; it++) {
130
+ iters = it;
131
+ for (let a = 0; a < m; a++) {
132
+ const vars = checkVars[a];
133
+ for (const i of vars) {
134
+ let signProd = 1;
135
+ let minMag = Infinity;
136
+ for (const j of vars) {
137
+ if (j === i) continue;
138
+ const msg = v2c[j][a];
139
+ signProd *= msg < 0 ? -1 : 1;
140
+ minMag = Math.min(minMag, Math.abs(msg));
141
+ }
142
+ if (!isFinite(minMag)) minMag = 0;
143
+ c2v[a][i] = alpha * (s[a] ? -1 : 1) * signProd * minMag;
144
+ }
145
+ }
146
+ for (let i = 0; i < n; i++) {
147
+ let total = lambda;
148
+ for (const a of varChecks[i]) total += c2v[a][i];
149
+ posterior[i] = total;
150
+ for (const a of varChecks[i]) {
151
+ const newMsg = total - c2v[a][i];
152
+ v2c[i][a] = (1 - gamma) * newMsg + gamma * v2c[i][a];
153
+ }
154
+ e[i] = total < 0 ? 1 : 0;
155
+ }
156
+ let ok = true;
157
+ for (let a = 0; a < m; a++) {
158
+ let par = 0;
159
+ for (const i of checkVars[a]) par ^= e[i];
160
+ if (par !== s[a]) {
161
+ ok = false;
162
+ break;
163
+ }
164
+ }
165
+ if (ok) {
166
+ converged = true;
167
+ break;
168
+ }
169
+ }
170
+ return { e, converged, iters, posterior };
171
+ }
172
+ function osd0(H, s, reliability, hard) {
173
+ const m = H.length;
174
+ const n = H[0].length;
175
+ const asc = [...Array(n).keys()].sort((x2, y) => reliability[x2] - reliability[y]);
176
+ const reduced = [];
177
+ const parity = [];
178
+ for (const c of asc) {
179
+ let vv = H.map((row) => row[c]);
180
+ for (const b of reduced) if (vv[b.pivot]) vv = vv.map((x2, k) => x2 ^ b.vec[k]);
181
+ const piv = vv.findIndex((x2) => x2 === 1);
182
+ if (piv !== -1) {
183
+ reduced.push({ vec: vv, pivot: piv });
184
+ parity.push(c);
185
+ if (parity.length === m) break;
186
+ }
187
+ }
188
+ const paritySet = new Set(parity);
189
+ const e = new Array(n).fill(0);
190
+ for (let c = 0; c < n; c++) if (!paritySet.has(c)) e[c] = hard[c];
191
+ const sPrime = H.map((row, a) => {
192
+ let par = s[a];
193
+ for (let c = 0; c < n; c++) if (!paritySet.has(c)) par ^= row[c] & e[c];
194
+ return par;
195
+ });
196
+ const A = H.map((row, a) => parity.map((c) => row[c]).concat([sPrime[a]]));
197
+ let rp = 0;
198
+ for (let col = 0; col < m && rp < m; col++) {
199
+ let piv = -1;
200
+ for (let r = rp; r < m; r++)
201
+ if (A[r][col]) {
202
+ piv = r;
203
+ break;
204
+ }
205
+ if (piv === -1) continue;
206
+ [A[rp], A[piv]] = [A[piv], A[rp]];
207
+ for (let r = 0; r < m; r++)
208
+ if (r !== rp && A[r][col]) for (let k = col; k <= m; k++) A[r][k] ^= A[rp][k];
209
+ rp++;
210
+ }
211
+ const x = new Array(m).fill(0);
212
+ for (let r = 0; r < m; r++) {
213
+ let pc = -1;
214
+ for (let c = 0; c < m; c++)
215
+ if (A[r][c]) {
216
+ pc = c;
217
+ break;
218
+ }
219
+ if (pc !== -1) x[pc] = A[r][m];
220
+ }
221
+ for (let k = 0; k < m; k++) e[parity[k]] = x[k];
222
+ return e;
223
+ }
224
+ function bpOsdDecode(H, s, p, opts = {}) {
225
+ const lambda = priorLLR(p);
226
+ const { e, converged, iters, posterior } = bpMinSum(H, s, lambda, opts);
227
+ if (converged) return { correction: e, method: "bp", iters };
228
+ const reliability = posterior.map(Math.abs);
229
+ const hard = posterior.map((v) => v < 0 ? 1 : 0);
230
+ return { correction: osd0(H, s, reliability, hard), method: "osd0", iters };
231
+ }
232
+ function decodeXBP(eX, p = DEFAULT_PRIOR, opts) {
233
+ return bpOsdDecode(HX, syndromeX(eX), p, opts).correction;
234
+ }
235
+ function decodeZBP(eZ, p = DEFAULT_PRIOR, opts) {
236
+ return bpOsdDecode(HZ, syndromeZ(eZ), p, opts).correction;
237
+ }
238
+ function syndromeCosetAudit() {
239
+ const audit = (H, LOOKUP, isLogical, syndromeFn) => {
240
+ let exact = 0;
241
+ let cosetEq = 0;
242
+ let invalid = 0;
243
+ for (let m = 0; m < 16; m++) {
244
+ const s = [m >> 3 & 1, m >> 2 & 1, m >> 1 & 1, m & 1];
245
+ const cBp = bpOsdDecode(H, s, DEFAULT_PRIOR).correction;
246
+ const cOpt = LOOKUP.get(s.join("")).correction;
247
+ const valid = syndromeFn(cBp).every((b, i) => b === s[i]);
248
+ if (!valid) {
249
+ invalid++;
250
+ continue;
251
+ }
252
+ const diff = xorVec(cBp, cOpt);
253
+ const trivialSynd = syndromeFn(diff).every((b) => b === 0);
254
+ const notLogical = !isLogical(diff);
255
+ if (trivialSynd && notLogical) {
256
+ cosetEq++;
257
+ if (cBp.join("") === cOpt.join("")) exact++;
258
+ }
259
+ }
260
+ return { exact_match: exact, coset_equivalent: cosetEq, syndrome_invalid: invalid, total: 16 };
261
+ };
262
+ return {
263
+ x_errors: audit(HX, LOOKUP_X, isLogicalX, syndromeX),
264
+ z_errors: audit(HZ, LOOKUP_Z, isLogicalZ, syndromeZ)
265
+ };
266
+ }
267
+ function tannerGraph() {
268
+ const checks = [];
269
+ const edges = [];
270
+ ZSTAB.forEach((s, i) => {
271
+ checks.push({ id: `Z${i}`, type: "Z", detects: "X", support: s });
272
+ s.forEach((q) => edges.push([`Z${i}`, `q${q}`]));
273
+ });
274
+ XSTAB.forEach((s, i) => {
275
+ checks.push({ id: `X${i}`, type: "X", detects: "Z", support: s });
276
+ s.forEach((q) => edges.push([`X${i}`, `q${q}`]));
277
+ });
278
+ return {
279
+ data_qubits: Array.from({ length: N }, (_, q) => `q${q}`),
280
+ checks,
281
+ edges
282
+ };
283
+ }
284
+ function decodeReceipt(eX, eZ) {
285
+ const sX = syndromeX(eX);
286
+ const sZ = syndromeZ(eZ);
287
+ const cX = decodeX(eX);
288
+ const cZ = decodeZ(eZ);
289
+ return {
290
+ schema: "qec-decode-receipt/v0",
291
+ code: "[[9,1,3]] rotated surface",
292
+ layout: { z_stabilizers: ZSTAB, x_stabilizers: XSTAB, logical_x: XL, logical_z: ZL },
293
+ x_syndrome: sX.join(""),
294
+ z_syndrome: sZ.join(""),
295
+ x_correction: cX.join(""),
296
+ z_correction: cZ.join(""),
297
+ logical_error: isLogicalX(xorVec(eX, cX)) || isLogicalZ(xorVec(eZ, cZ))
298
+ };
299
+ }
300
+ var N;
301
+ var ZSTAB;
302
+ var XSTAB;
303
+ var ZL;
304
+ var XL;
305
+ var vec;
306
+ var weight;
307
+ var xorVec;
308
+ var overlapParity;
309
+ var LOOKUP_X;
310
+ var LOOKUP_Z;
311
+ var HX;
312
+ var HZ;
313
+ var DEFAULT_PRIOR;
314
+ var init_qec_codes = __esm({
315
+ "src/qec/qec-codes.ts"() {
316
+ N = 9;
317
+ ZSTAB = [
318
+ [0, 1, 3, 4],
319
+ // top-left plaquette
320
+ [4, 5, 7, 8],
321
+ // bottom-right plaquette
322
+ [1, 2],
323
+ // top boundary
324
+ [6, 7]
325
+ // bottom boundary
326
+ ];
327
+ XSTAB = [
328
+ [0, 3],
329
+ // left boundary
330
+ [1, 2, 4, 5],
331
+ // upper-right plaquette
332
+ [3, 4, 6, 7],
333
+ // lower-left plaquette
334
+ [5, 8]
335
+ // right boundary
336
+ ];
337
+ ZL = [0, 3, 6];
338
+ XL = [0, 1, 2];
339
+ vec = () => new Array(N).fill(0);
340
+ weight = (v) => v.reduce((a, b) => a + b, 0);
341
+ xorVec = (a, b) => a.map((x, i) => x ^ b[i]);
342
+ overlapParity = (v, support) => support.reduce((acc, q) => acc ^ v[q], 0);
343
+ LOOKUP_X = buildLookup(ZSTAB);
344
+ LOOKUP_Z = buildLookup(XSTAB);
345
+ HX = stabsToMatrix(ZSTAB);
346
+ HZ = stabsToMatrix(XSTAB);
347
+ DEFAULT_PRIOR = 0.05;
348
+ }
349
+ });
10
350
  var _bootstrapAttempted = false;
11
351
  var _bootstrapResult = false;
12
352
  function ensureNodeWebGpuSync() {
@@ -1073,10 +1413,10 @@ function collectRegionPixels(fixtures, region) {
1073
1413
  for (const fixture of fixtures) {
1074
1414
  for (const sample of fixture.regions) {
1075
1415
  if (sample.region !== region) continue;
1076
- const weight = Math.max(1, Math.round(sample.weight ?? 1));
1416
+ const weight2 = Math.max(1, Math.round(sample.weight ?? 1));
1077
1417
  for (const color of sample.pixels) {
1078
1418
  const parsed = parseColor(color);
1079
- for (let i = 0; i < weight; i += 1) pixels.push(parsed);
1419
+ for (let i = 0; i < weight2; i += 1) pixels.push(parsed);
1080
1420
  }
1081
1421
  }
1082
1422
  }
@@ -2026,10 +2366,10 @@ function denseToCSR(adjacency, n) {
2026
2366
  rowPtr[row] = colIdx.length;
2027
2367
  for (let col = 0; col < n; col++) {
2028
2368
  if (row === col) continue;
2029
- const weight = adjacency[row * n + col];
2030
- if (Number.isFinite(weight) && weight < TROPICAL_INF) {
2369
+ const weight2 = adjacency[row * n + col];
2370
+ if (Number.isFinite(weight2) && weight2 < TROPICAL_INF) {
2031
2371
  colIdx.push(col);
2032
- values.push(weight);
2372
+ values.push(weight2);
2033
2373
  }
2034
2374
  }
2035
2375
  }
@@ -2058,12 +2398,12 @@ function fromEdges(nodeCount, edges) {
2058
2398
  }
2059
2399
  }
2060
2400
  const grouped = /* @__PURE__ */ new Map();
2061
- for (const [key, weight] of minWeightByEdge) {
2401
+ for (const [key, weight2] of minWeightByEdge) {
2062
2402
  const [fromRaw, toRaw] = key.split(":");
2063
2403
  const from = Number(fromRaw);
2064
2404
  const to = Number(toRaw);
2065
2405
  if (!grouped.has(from)) grouped.set(from, []);
2066
- grouped.get(from).push({ to, weight });
2406
+ grouped.get(from).push({ to, weight: weight2 });
2067
2407
  }
2068
2408
  const rowPtr = new Uint32Array(nodeCount + 1);
2069
2409
  const colIdx = [];
@@ -3340,7 +3680,358 @@ function completenessStatus2(count, total) {
3340
3680
  }
3341
3681
  return count === total ? "complete" : "partial";
3342
3682
  }
3683
+ var qec_exports = {};
3684
+ __export(qec_exports, {
3685
+ CONVERGED_BIT: () => CONVERGED_BIT,
3686
+ DEFAULT_PRIOR: () => DEFAULT_PRIOR,
3687
+ E_CHECK: () => E_CHECK,
3688
+ E_VAR: () => E_VAR,
3689
+ HX: () => HX,
3690
+ HZ: () => HZ,
3691
+ LOOKUP_X: () => LOOKUP_X,
3692
+ LOOKUP_Z: () => LOOKUP_Z,
3693
+ N: () => N,
3694
+ NCHECK: () => NCHECK,
3695
+ NVAR: () => NVAR,
3696
+ QECDecoder: () => QECDecoder,
3697
+ QEC_BP_WGSL: () => QEC_BP_WGSL,
3698
+ XL: () => XL,
3699
+ XSTAB: () => XSTAB,
3700
+ ZL: () => ZL,
3701
+ ZSTAB: () => ZSTAB,
3702
+ bpMinSum: () => bpMinSum,
3703
+ bpOsdDecode: () => bpOsdDecode,
3704
+ codeDistance: () => codeDistance,
3705
+ decodeReceipt: () => decodeReceipt,
3706
+ decodeShot: () => decodeShot,
3707
+ decodeX: () => decodeX,
3708
+ decodeXBP: () => decodeXBP,
3709
+ decodeZ: () => decodeZ,
3710
+ decodeZBP: () => decodeZBP,
3711
+ isLogicalX: () => isLogicalX,
3712
+ isLogicalZ: () => isLogicalZ,
3713
+ osd0: () => osd0,
3714
+ overlapParity: () => overlapParity,
3715
+ packSyndrome: () => packSyndrome,
3716
+ priorLLR: () => priorLLR,
3717
+ stabsToMatrix: () => stabsToMatrix,
3718
+ syndromeCosetAudit: () => syndromeCosetAudit,
3719
+ syndromeX: () => syndromeX,
3720
+ syndromeZ: () => syndromeZ,
3721
+ tannerEdgesMatchZstab: () => tannerEdgesMatchZstab,
3722
+ tannerGraph: () => tannerGraph,
3723
+ unpackCorrection: () => unpackCorrection,
3724
+ weight: () => weight,
3725
+ xorVec: () => xorVec
3726
+ });
3727
+ init_qec_codes();
3728
+ init_qec_codes();
3729
+ var NVAR = 9;
3730
+ var NCHECK = 4;
3731
+ var CONVERGED_BIT = 31;
3732
+ var E_CHECK = [0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 3, 3];
3733
+ var E_VAR = [0, 1, 3, 4, 4, 5, 7, 8, 1, 2, 6, 7];
3734
+ function tannerEdgesMatchZstab() {
3735
+ const rebuilt = Array.from({ length: NCHECK }, () => []);
3736
+ for (let e = 0; e < E_CHECK.length; e++) rebuilt[E_CHECK[e]].push(E_VAR[e]);
3737
+ const norm = (rows) => JSON.stringify(rows.map((r) => [...r].sort((a, b) => a - b)));
3738
+ return norm(rebuilt) === norm(ZSTAB);
3739
+ }
3740
+ var QEC_BP_WGSL = (
3741
+ /* wgsl */
3742
+ `
3743
+ struct Params { lambda: f32, count: u32, pad0: u32, pad1: u32 };
3744
+ @group(0) @binding(0) var<storage, read> syndromes: array<u32>;
3745
+ @group(0) @binding(1) var<storage, read_write> corrections: array<u32>;
3746
+ @group(0) @binding(2) var<uniform> params: Params;
3747
+
3748
+ const ALPHA: f32 = 0.8125;
3749
+ const GAMMA: f32 = 0.2;
3750
+ const MAXITER: u32 = 30u;
3751
+ const NVAR: u32 = 9u;
3752
+ const NCHECK: u32 = 4u;
3753
+ const NEDGE: u32 = 12u;
3754
+
3755
+ @compute @workgroup_size(64)
3756
+ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
3757
+ let idx = gid.x;
3758
+ if (idx >= params.count) { return; }
3759
+
3760
+ var eCheck = array<u32,12>(0u,0u,0u,0u,1u,1u,1u,1u,2u,2u,3u,3u);
3761
+ var eVar = array<u32,12>(0u,1u,3u,4u,4u,5u,7u,8u,1u,2u,6u,7u);
3762
+
3763
+ let sPacked = syndromes[idx];
3764
+ var s = array<u32,4>(0u,0u,0u,0u);
3765
+ for (var a = 0u; a < NCHECK; a = a + 1u) { s[a] = (sPacked >> a) & 1u; }
3766
+
3767
+ let lambda = params.lambda;
3768
+ var v2c = array<f32,12>(lambda,lambda,lambda,lambda,lambda,lambda,lambda,lambda,lambda,lambda,lambda,lambda);
3769
+ var c2v = array<f32,12>(0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0);
3770
+ var ecorr = array<u32,9>(0u,0u,0u,0u,0u,0u,0u,0u,0u);
3771
+ var converged = false;
3772
+
3773
+ for (var it = 0u; it < MAXITER; it = it + 1u) {
3774
+ // check-node update (syndrome-signed normalized min-sum)
3775
+ for (var e = 0u; e < NEDGE; e = e + 1u) {
3776
+ let a = eCheck[e];
3777
+ var signProd = 1.0;
3778
+ var minMag = 1e30;
3779
+ for (var f = 0u; f < NEDGE; f = f + 1u) {
3780
+ if (eCheck[f] != a || f == e) { continue; }
3781
+ let msg = v2c[f];
3782
+ if (msg < 0.0) { signProd = -signProd; }
3783
+ let mag = abs(msg);
3784
+ if (mag < minMag) { minMag = mag; }
3785
+ }
3786
+ var sgn = 1.0;
3787
+ if (s[a] == 1u) { sgn = -1.0; }
3788
+ c2v[e] = ALPHA * sgn * signProd * minMag;
3789
+ }
3790
+ // variable-node update + posterior + hard decision (with damping)
3791
+ for (var i = 0u; i < NVAR; i = i + 1u) {
3792
+ var total = lambda;
3793
+ for (var e = 0u; e < NEDGE; e = e + 1u) { if (eVar[e] == i) { total = total + c2v[e]; } }
3794
+ for (var e = 0u; e < NEDGE; e = e + 1u) { if (eVar[e] == i) { let newMsg = total - c2v[e]; v2c[e] = (1.0 - GAMMA) * newMsg + GAMMA * v2c[e]; } }
3795
+ if (total < 0.0) { ecorr[i] = 1u; } else { ecorr[i] = 0u; }
3796
+ }
3797
+ // convergence: parity of ecorr over each check == s
3798
+ var ok = true;
3799
+ for (var a = 0u; a < NCHECK; a = a + 1u) {
3800
+ var par = 0u;
3801
+ for (var e = 0u; e < NEDGE; e = e + 1u) { if (eCheck[e] == a) { par = par ^ ecorr[eVar[e]]; } }
3802
+ if (par != s[a]) { ok = false; }
3803
+ }
3804
+ if (ok) { converged = true; break; }
3805
+ }
3806
+
3807
+ var packed = 0u;
3808
+ for (var i = 0u; i < NVAR; i = i + 1u) { packed = packed | (ecorr[i] << i); }
3809
+ if (converged) { packed = packed | (1u << 31u); }
3810
+ corrections[idx] = packed;
3811
+ }
3812
+ `
3813
+ );
3814
+ function unpackCorrection(word) {
3815
+ const correction = new Array(NVAR).fill(0);
3816
+ for (let i = 0; i < NVAR; i++) correction[i] = word >>> i & 1;
3817
+ const converged = (word >>> CONVERGED_BIT & 1) === 1;
3818
+ return { correction, converged };
3819
+ }
3820
+ function packSyndrome(s) {
3821
+ let packed = 0;
3822
+ for (let a = 0; a < NCHECK; a++) packed |= (s[a] & 1) << a;
3823
+ return packed >>> 0;
3824
+ }
3825
+ var QECDecoder = class {
3826
+ constructor(ctx) {
3827
+ this.ctx = ctx;
3828
+ this._pipeline = null;
3829
+ }
3830
+ /** Build the compute pipeline. Idempotent. Throws if the WGSL Tanner graph drifted from ZSTAB. */
3831
+ async initialize() {
3832
+ if (this._pipeline) return;
3833
+ if (!tannerEdgesMatchZstab()) {
3834
+ throw new Error(
3835
+ "QECDecoder: WGSL Tanner edges (E_CHECK/E_VAR) do not reconstruct ZSTAB \u2014 refusing to build a decoder that diverges from the CPU-validated code."
3836
+ );
3837
+ }
3838
+ const module = this.ctx.createShaderModule(QEC_BP_WGSL, "qec-bp-decoder");
3839
+ this._pipeline = await this.ctx.createComputePipelineAsync(module, "main", "auto", "qec-bp");
3840
+ }
3841
+ pipeline() {
3842
+ if (!this._pipeline) {
3843
+ throw new Error("QECDecoder not initialized. Call initialize() first.");
3844
+ }
3845
+ return this._pipeline;
3846
+ }
3847
+ /**
3848
+ * Decode a batch of packed syndromes on the GPU with pure BP. Returns packed correction words
3849
+ * (bits 0..8 = qubit corrections, bit 31 = converged) — one per input, in order.
3850
+ */
3851
+ async decodeBatch(packedSyndromes, p = DEFAULT_PRIOR) {
3852
+ const pipeline = this.pipeline();
3853
+ const device = this.ctx.device;
3854
+ const B = packedSyndromes.length;
3855
+ if (B === 0) return new Uint32Array(0);
3856
+ const inBuf = device.createBuffer({
3857
+ size: B * 4,
3858
+ usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
3859
+ });
3860
+ device.queue.writeBuffer(
3861
+ inBuf,
3862
+ 0,
3863
+ packedSyndromes.buffer,
3864
+ packedSyndromes.byteOffset,
3865
+ packedSyndromes.byteLength
3866
+ );
3867
+ const outBuf = device.createBuffer({
3868
+ size: B * 4,
3869
+ usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_SRC
3870
+ });
3871
+ const readBuf = device.createBuffer({
3872
+ size: B * 4,
3873
+ usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST
3874
+ });
3875
+ const params = new ArrayBuffer(16);
3876
+ new Float32Array(params, 0, 1)[0] = priorLLR(p);
3877
+ new Uint32Array(params, 4, 1)[0] = B;
3878
+ const paramBuf = device.createBuffer({
3879
+ size: 16,
3880
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3881
+ });
3882
+ device.queue.writeBuffer(paramBuf, 0, params);
3883
+ const bind = device.createBindGroup({
3884
+ layout: pipeline.getBindGroupLayout(0),
3885
+ entries: [
3886
+ { binding: 0, resource: { buffer: inBuf } },
3887
+ { binding: 1, resource: { buffer: outBuf } },
3888
+ { binding: 2, resource: { buffer: paramBuf } }
3889
+ ]
3890
+ });
3891
+ const enc = device.createCommandEncoder();
3892
+ const pass = enc.beginComputePass();
3893
+ pass.setPipeline(pipeline);
3894
+ pass.setBindGroup(0, bind);
3895
+ pass.dispatchWorkgroups(Math.ceil(B / 64));
3896
+ pass.end();
3897
+ enc.copyBufferToBuffer(outBuf, 0, readBuf, 0, B * 4);
3898
+ device.queue.submit([enc.finish()]);
3899
+ await readBuf.mapAsync(GPUMapMode.READ);
3900
+ const out = new Uint32Array(readBuf.getMappedRange().slice(0));
3901
+ readBuf.unmap();
3902
+ inBuf.destroy();
3903
+ outBuf.destroy();
3904
+ readBuf.destroy();
3905
+ paramBuf.destroy();
3906
+ return out;
3907
+ }
3908
+ /**
3909
+ * Full-pipeline decode: run GPU BP over the batch, then fall to the host OSD-0 guard for any
3910
+ * syndrome BP did not converge on — the standard BP-on-accelerator / OSD-on-host split. Each
3911
+ * result carries whether the GPU fast path succeeded.
3912
+ */
3913
+ async decodeWithFallback(syndromes, p = DEFAULT_PRIOR) {
3914
+ const packed = new Uint32Array(syndromes.map((s) => packSyndrome(s)));
3915
+ const out = await this.decodeBatch(packed, p);
3916
+ return syndromes.map((s, i) => {
3917
+ const { correction, converged } = unpackCorrection(out[i]);
3918
+ if (converged) return { correction, gpuConverged: true, method: "gpu-bp" };
3919
+ return { correction: bpOsdDecode(HX, s, p).correction, gpuConverged: false, method: "host-osd0" };
3920
+ });
3921
+ }
3922
+ /**
3923
+ * Exhaustively validate the GPU decoder over all 16 X-syndromes against the exact ML lookup:
3924
+ * every GPU-converged decode must be syndrome-valid + coset-equivalent, the full pipeline must
3925
+ * solve all 16, and the GPU converged flag must match the CPU BP reference.
3926
+ */
3927
+ async validateExhaustive(p = DEFAULT_PRIOR) {
3928
+ const { LOOKUP_X: LOOKUP_X2, syndromeX: syndromeX2, xorVec: xorVec2, isLogicalX: isLogicalX2, bpMinSum: bpMinSum2 } = await Promise.resolve().then(() => (init_qec_codes(), qec_codes_exports));
3929
+ const syndromes = [];
3930
+ for (let m = 0; m < 16; m++) syndromes.push([m & 1, m >> 1 & 1, m >> 2 & 1, m >> 3 & 1]);
3931
+ const results = await this.decodeWithFallback(syndromes, p);
3932
+ let gpuConverged = 0;
3933
+ let gpuConvergedCorrect = 0;
3934
+ let fullValidCoset = 0;
3935
+ let convMatch = 0;
3936
+ const lambda = priorLLR(p);
3937
+ const okOf = (c, s) => {
3938
+ const valid = syndromeX2(c).every((b, i) => b === s[i]);
3939
+ const diff = xorVec2(c, LOOKUP_X2.get(s.join("")).correction);
3940
+ return valid && syndromeX2(diff).every((b) => b === 0) && !isLogicalX2(diff);
3941
+ };
3942
+ for (let m = 0; m < 16; m++) {
3943
+ const s = syndromes[m];
3944
+ const r = results[m];
3945
+ const cpuConv = bpMinSum2(HX, s, lambda).converged;
3946
+ if (r.gpuConverged === cpuConv) convMatch++;
3947
+ if (r.gpuConverged) {
3948
+ gpuConverged++;
3949
+ if (okOf(r.correction, s)) gpuConvergedCorrect++;
3950
+ }
3951
+ if (okOf(r.correction, s)) fullValidCoset++;
3952
+ }
3953
+ return {
3954
+ syndromesTested: 16,
3955
+ gpuBpConverged: gpuConverged,
3956
+ gpuConvergedAllValidCoset: gpuConvergedCorrect === gpuConverged,
3957
+ fullPipelineAll16ValidCoset: fullValidCoset === 16,
3958
+ convergedFlagMatchesCpu: convMatch
3959
+ };
3960
+ }
3961
+ /**
3962
+ * Measure batched decode throughput on the real device: warm up, then time `reps` dispatches
3963
+ * of a `batchSize` batch (submit → onSubmittedWorkDone) with no per-dispatch readback. The
3964
+ * honest GPU metric is throughput, not single-shot latency.
3965
+ */
3966
+ async benchmarkThroughput(batchSize, reps, p = DEFAULT_PRIOR) {
3967
+ const pipeline = this.pipeline();
3968
+ const device = this.ctx.device;
3969
+ const B = batchSize;
3970
+ const batch = new Uint32Array(B);
3971
+ let seed = 12345 >>> 0;
3972
+ for (let i = 0; i < B; i++) {
3973
+ seed = seed + 1831565813 | 0;
3974
+ let t = Math.imul(seed ^ seed >>> 15, 1 | seed);
3975
+ t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t;
3976
+ batch[i] = (t ^ t >>> 14) >>> 0 & 15;
3977
+ }
3978
+ const inBuf = device.createBuffer({
3979
+ size: B * 4,
3980
+ usage: GPUBufferUsage.STORAGE | GPUBufferUsage.COPY_DST
3981
+ });
3982
+ device.queue.writeBuffer(inBuf, 0, batch.buffer, batch.byteOffset, batch.byteLength);
3983
+ const outBuf = device.createBuffer({ size: B * 4, usage: GPUBufferUsage.STORAGE });
3984
+ const params = new ArrayBuffer(16);
3985
+ new Float32Array(params, 0, 1)[0] = priorLLR(p);
3986
+ new Uint32Array(params, 4, 1)[0] = B;
3987
+ const paramBuf = device.createBuffer({
3988
+ size: 16,
3989
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
3990
+ });
3991
+ device.queue.writeBuffer(paramBuf, 0, params);
3992
+ const bind = device.createBindGroup({
3993
+ layout: pipeline.getBindGroupLayout(0),
3994
+ entries: [
3995
+ { binding: 0, resource: { buffer: inBuf } },
3996
+ { binding: 1, resource: { buffer: outBuf } },
3997
+ { binding: 2, resource: { buffer: paramBuf } }
3998
+ ]
3999
+ });
4000
+ const dispatch = () => {
4001
+ const enc = device.createCommandEncoder();
4002
+ const pass = enc.beginComputePass();
4003
+ pass.setPipeline(pipeline);
4004
+ pass.setBindGroup(0, bind);
4005
+ pass.dispatchWorkgroups(Math.ceil(B / 64));
4006
+ pass.end();
4007
+ device.queue.submit([enc.finish()]);
4008
+ };
4009
+ const converged = await this.decodeBatch(batch, p);
4010
+ let convergedCount = 0;
4011
+ for (let i = 0; i < B; i++) if (converged[i] >>> CONVERGED_BIT & 1) convergedCount++;
4012
+ for (let r = 0; r < 3; r++) dispatch();
4013
+ await device.queue.onSubmittedWorkDone();
4014
+ const t0 = performance.now();
4015
+ for (let r = 0; r < reps; r++) dispatch();
4016
+ await device.queue.onSubmittedWorkDone();
4017
+ const t1 = performance.now();
4018
+ inBuf.destroy();
4019
+ outBuf.destroy();
4020
+ paramBuf.destroy();
4021
+ const totalDecodes = B * reps;
4022
+ const wallSeconds = (t1 - t0) / 1e3;
4023
+ return {
4024
+ batchSize: B,
4025
+ reps,
4026
+ totalDecodes,
4027
+ wallSeconds: Number(wallSeconds.toFixed(4)),
4028
+ decodesPerSecond: Math.round(totalDecodes / wallSeconds),
4029
+ nsPerDecodeAmortized: Number(((t1 - t0) * 1e6 / totalDecodes).toFixed(3)),
4030
+ gpuFastPathFraction: Number((convergedCount / B).toFixed(4))
4031
+ };
4032
+ }
4033
+ };
3343
4034
 
3344
- export { BufferManager, CPUReferenceSimulator, DEFAULT_DECODE_PARAMS, DEFAULT_ENCODE_PARAMS, DEFAULT_LIF_PARAMS, DecodingMode, EncodingMode, GPUContext, HoloMeshProphecyTransport, LIFSimulator, LocalProphecyTransport, PAPER_2_CANONICAL_CONFIG, PROPHECY_SPIKE_FEATURE_COUNT, PipelineFactory, ProphecyNotImplementedError, ProphecyOrchestrator, SNNNetwork, SpikeDecoder, SpikeEncoder, TROPICAL_INF, TropicalActivationTrait, TropicalShortestPaths, assertGraphShape, computeDispatchSize, createTrainedSpikeRateProvider, csrToDense, decodeProphecySpikeRates, decodeSpikeRateWindow, denseToCSR, encodeProphecySceneProbeFeatures, ensureNodeWebGpu, ensureNodeWebGpuSync, extractBotanicalLotusMaterial, extractBotanicalMaterialFromPhotoFixtures, fromEdges, generateSynapticInput, generateWeightMatrix, normalizeAdjacency, normalizeBotanicalMaterialExtraction, runLIFDeterminismProbe, toBotanicalLotusTrait, trainProphecySpikeRateModel };
3345
- //# sourceMappingURL=dist-ZBUKU2JG.js.map
3346
- //# sourceMappingURL=dist-ZBUKU2JG.js.map
4035
+ export { BufferManager, CPUReferenceSimulator, DEFAULT_DECODE_PARAMS, DEFAULT_ENCODE_PARAMS, DEFAULT_LIF_PARAMS, DecodingMode, EncodingMode, GPUContext, HoloMeshProphecyTransport, LIFSimulator, LocalProphecyTransport, PAPER_2_CANONICAL_CONFIG, PROPHECY_SPIKE_FEATURE_COUNT, PipelineFactory, ProphecyNotImplementedError, ProphecyOrchestrator, QECDecoder, SNNNetwork, SpikeDecoder, SpikeEncoder, TROPICAL_INF, TropicalActivationTrait, TropicalShortestPaths, assertGraphShape, computeDispatchSize, createTrainedSpikeRateProvider, csrToDense, decodeProphecySpikeRates, decodeSpikeRateWindow, denseToCSR, encodeProphecySceneProbeFeatures, ensureNodeWebGpu, ensureNodeWebGpuSync, extractBotanicalLotusMaterial, extractBotanicalMaterialFromPhotoFixtures, fromEdges, generateSynapticInput, generateWeightMatrix, normalizeAdjacency, normalizeBotanicalMaterialExtraction, packSyndrome, qec_exports as qec, runLIFDeterminismProbe, tannerEdgesMatchZstab, toBotanicalLotusTrait, trainProphecySpikeRateModel, unpackCorrection };
4036
+ //# sourceMappingURL=dist-ZEZXRCBG.js.map
4037
+ //# sourceMappingURL=dist-ZEZXRCBG.js.map