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