@graphty/webgpu-graph-algorithms 0.4.1 → 0.5.1

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 (93) hide show
  1. package/README.md +27 -21
  2. package/dist/browser.js +1 -1
  3. package/dist/chunks/{context-CRbw2Wyo.js → context-BR7fx3vR.js} +47 -5
  4. package/dist/chunks/context-BR7fx3vR.js.map +1 -0
  5. package/dist/node.js +1 -1
  6. package/dist/src/accelerator.d.ts +15 -12
  7. package/dist/src/accelerator.d.ts.map +1 -1
  8. package/dist/src/accelerator.js +35 -12
  9. package/dist/src/accelerator.js.map +1 -1
  10. package/dist/src/constants.d.ts +47 -0
  11. package/dist/src/constants.d.ts.map +1 -1
  12. package/dist/src/constants.js +47 -0
  13. package/dist/src/constants.js.map +1 -1
  14. package/dist/src/index.d.ts +8 -5
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +9 -5
  17. package/dist/src/index.js.map +1 -1
  18. package/dist/src/kernel/prelude.d.ts.map +1 -1
  19. package/dist/src/kernel/prelude.js +4 -1
  20. package/dist/src/kernel/prelude.js.map +1 -1
  21. package/dist/src/kernels.d.ts +3 -3
  22. package/dist/src/kernels.d.ts.map +1 -1
  23. package/dist/src/kernels.js +27 -11
  24. package/dist/src/kernels.js.map +1 -1
  25. package/dist/src/layouts/force-simulation.d.ts +3 -1
  26. package/dist/src/layouts/force-simulation.d.ts.map +1 -1
  27. package/dist/src/layouts/force-simulation.js +13 -3
  28. package/dist/src/layouts/force-simulation.js.map +1 -1
  29. package/dist/src/layouts/forceatlas2.d.ts +1 -3
  30. package/dist/src/layouts/forceatlas2.d.ts.map +1 -1
  31. package/dist/src/layouts/forceatlas2.js +2 -191
  32. package/dist/src/layouts/forceatlas2.js.map +1 -1
  33. package/dist/src/layouts/fruchterman-reingold.d.ts +195 -0
  34. package/dist/src/layouts/fruchterman-reingold.d.ts.map +1 -0
  35. package/dist/src/layouts/fruchterman-reingold.js +579 -0
  36. package/dist/src/layouts/fruchterman-reingold.js.map +1 -0
  37. package/dist/src/layouts/model-common.d.ts +102 -0
  38. package/dist/src/layouts/model-common.d.ts.map +1 -0
  39. package/dist/src/layouts/model-common.js +198 -0
  40. package/dist/src/layouts/model-common.js.map +1 -0
  41. package/dist/src/layouts/spring-electrical.d.ts +179 -0
  42. package/dist/src/layouts/spring-electrical.d.ts.map +1 -0
  43. package/dist/src/layouts/spring-electrical.js +508 -0
  44. package/dist/src/layouts/spring-electrical.js.map +1 -0
  45. package/dist/src/types/accelerator.d.ts +14 -157
  46. package/dist/src/types/accelerator.d.ts.map +1 -1
  47. package/dist/src/types/accelerator.js +4 -5
  48. package/dist/src/types/accelerator.js.map +1 -1
  49. package/dist/src/types/algorithms.d.ts +1 -1
  50. package/dist/src/types/algorithms.js +1 -1
  51. package/dist/src/types/layout.d.ts +32 -0
  52. package/dist/src/types/layout.d.ts.map +1 -1
  53. package/dist/src/types/options.d.ts +43 -1
  54. package/dist/src/types/options.d.ts.map +1 -1
  55. package/dist/src/wgsl/fa2-attraction.wgsl.d.ts +5 -2
  56. package/dist/src/wgsl/fa2-attraction.wgsl.d.ts.map +1 -1
  57. package/dist/src/wgsl/fa2-attraction.wgsl.js +6 -1
  58. package/dist/src/wgsl/fa2-attraction.wgsl.js.map +1 -1
  59. package/dist/src/wgsl/fa2-integrate.wgsl.d.ts +7 -2
  60. package/dist/src/wgsl/fa2-integrate.wgsl.d.ts.map +1 -1
  61. package/dist/src/wgsl/fa2-integrate.wgsl.js +28 -2
  62. package/dist/src/wgsl/fa2-integrate.wgsl.js.map +1 -1
  63. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts +4 -2
  64. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.d.ts.map +1 -1
  65. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js +14 -5
  66. package/dist/src/wgsl/fa2-repulsion-exact.wgsl.js.map +1 -1
  67. package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts +8 -1
  68. package/dist/src/wgsl/fa2-stats-finalize.wgsl.d.ts.map +1 -1
  69. package/dist/src/wgsl/fa2-stats-finalize.wgsl.js +33 -0
  70. package/dist/src/wgsl/fa2-stats-finalize.wgsl.js.map +1 -1
  71. package/dist/tsconfig.build.tsbuildinfo +1 -1
  72. package/dist/webgpu-graph-algorithms.js +1358 -284
  73. package/dist/webgpu-graph-algorithms.js.map +1 -1
  74. package/package.json +6 -3
  75. package/src/accelerator.ts +49 -14
  76. package/src/constants.ts +70 -0
  77. package/src/index.ts +19 -8
  78. package/src/kernel/prelude.ts +6 -0
  79. package/src/kernels.ts +27 -11
  80. package/src/layouts/force-simulation.ts +20 -3
  81. package/src/layouts/forceatlas2.ts +17 -220
  82. package/src/layouts/fruchterman-reingold.ts +737 -0
  83. package/src/layouts/model-common.ts +228 -0
  84. package/src/layouts/spring-electrical.ts +666 -0
  85. package/src/types/accelerator.ts +58 -174
  86. package/src/types/algorithms.ts +1 -1
  87. package/src/types/layout.ts +36 -0
  88. package/src/types/options.ts +45 -1
  89. package/src/wgsl/fa2-attraction.wgsl.ts +6 -1
  90. package/src/wgsl/fa2-integrate.wgsl.ts +28 -2
  91. package/src/wgsl/fa2-repulsion-exact.wgsl.ts +14 -5
  92. package/src/wgsl/fa2-stats-finalize.wgsl.ts +33 -0
  93. package/dist/chunks/context-CRbw2Wyo.js.map +0 -1
@@ -0,0 +1,508 @@
1
+ /**
2
+ * The spring-electrical preset on the exact repulsion tier (spec 7.20 "the preset"; contract 3.13): ngraph.forcelayout's
3
+ * physics under ngraph's option names and defaults -- Coulomb repulsion `-g m_i m_j / d^2` (K3, LAW 2), Hooke springs
4
+ * `k_s (d - L)` (K2, LAW 2), drag and the semi-implicit Euler step with the unit speed clamp over a per-node velocity
5
+ * (K5, APPLY 2), the kinetic energy folded into the trace (K1, STATS_MODE 2; PD-4) -- as the ForceModel that
6
+ * ForceSimulation drives over the four FA2 kernels K1 K2 K3 K5 per iteration and toScene per batch. No K4: there is no
7
+ * speed controller. The velocity is the model's `velocity` buffer bound into the `oldForce` slot of K3 and K5 (PD-2),
8
+ * left alone by the FA2 text because the model compiles `SWING_MODE = 1` (PD-20). Mass is `1 + degree / 3` and the
9
+ * weights are ignored (PD-11); `SpringElectricalOptions.gravity` is ngraph's Coulomb constant, written into
10
+ * `Fa2Params.coulomb` while FA2's centre gravity is 0 (PD-12). Settlement is the shared rule of spec 7.17
11
+ * (DEP-P5-A); `reheat()` leaves the velocities alone (ngraph has no reheat).
12
+ *
13
+ * Model decisions this file shares with forceatlas2.ts: the K1-K5 dispatches of one batch share ONE compute pass and
14
+ * toScene runs in a second pass that ends it; the fill kernel takes its FillParams from a model-owned 256-byte uniform
15
+ * buffer; `repulsion: "grid"` is E_UNSUPPORTED at load() (the simulation's tier rule).
16
+ */
17
+ import { MAX_ITERATIONS_PER_STEP, SE_DEFAULTS, SE_SCALE_REFERENCE_NODES, TRACE_RECORD_BYTES, UNIFORM_SLOT_BYTES, } from "../constants.js";
18
+ import { BufferUsage } from "../device/webgpu-constants.js";
19
+ import { WebGpuGraphError } from "../errors.js";
20
+ import { plan1d } from "../kernel/dispatch.js";
21
+ import { FA2_PARAMS, FA2_STATE, FA2_TRACE, FILL_PARAMS, graphBindings, kernelSpec } from "../kernels.js";
22
+ import { ForceSimulation, } from "./force-simulation.js";
23
+ import { resolveLayoutTuning } from "./forceatlas2.js";
24
+ import { describeValue, FILL_PARAMS_BUFFER, FORCE_BYTES_PER_NODE, invalid, isPositiveInteger, pickCenter, pickDim, pickNumber, pickSeed, scalar, seedWord, subset, vector, } from "./model-common.js";
25
+ // ============================================================ constants
26
+ /** The stage names of one iteration in dispatch order plus the per-batch toScene (no K4: spec 7.20). */
27
+ const SE_STAGES = ["K1", "K2", "K3", "K5", "toScene"];
28
+ /** The one-workgroup dispatch of K1. */
29
+ const ONE_WORKGROUP = { x: 1, y: 1, z: 1, items: 1, stride: null };
30
+ /** The model's constant override set (PD-1, PD-20): the spring / coulomb laws, ngraph's Euler step, the kinetic-energy statistic, SWING_MODE 1 so the FA2 text never touches the oldForce slot. */
31
+ const SE_OVERRIDES = Object.freeze({
32
+ LINLOG: false,
33
+ DISTRIBUTED: false,
34
+ TIER: 0,
35
+ SWING_MODE: 1,
36
+ STRONG_GRAVITY: false,
37
+ GRAVITY_CENTER: 0,
38
+ LAW: 2,
39
+ APPLY: 2,
40
+ STATS_MODE: 2,
41
+ });
42
+ /** Every override K1 accepts, with its default. */
43
+ const K1_DEFAULTS = { STATS_MODE: 0 };
44
+ /** Every override K2 accepts, with its default (plus the two standard graph overrides). */
45
+ const K2_DEFAULTS = {
46
+ LINLOG: false,
47
+ DISTRIBUTED: false,
48
+ TIER: 0,
49
+ USE_PERM: false,
50
+ HAS_WEIGHTS: false,
51
+ LAW: 0,
52
+ };
53
+ /** Every override K3 accepts, with its default. */
54
+ const K3_DEFAULTS = { SWING_MODE: 0, STRONG_GRAVITY: false, GRAVITY_CENTER: 0, LAW: 0 };
55
+ /** Every override K5 accepts, with its default. */
56
+ const K5_DEFAULTS = { SWING_MODE: 0, APPLY: 0 };
57
+ /** The name of the model's velocity buffer (bound into the `oldForce` slot of K3 / K5, PD-2). */
58
+ const VELOCITY_BUFFER = "velocity";
59
+ /** The resolved record with no option given: SE_DEFAULTS plus the origin centre and the null seed; the two force constants null = size-scaled at load. */
60
+ const DEFAULT_RESOLVED = Object.freeze({
61
+ ...SE_DEFAULTS,
62
+ gravity: null,
63
+ springCoefficient: null,
64
+ center: [0, 0, 0],
65
+ seed: null,
66
+ });
67
+ /**
68
+ * The size factor of the default force constants: 1 up to SE_SCALE_REFERENCE_NODES nodes (ngraph's constants as
69
+ * they are), then SE_SCALE_REFERENCE_NODES / n, so the per-node force stays at the level ngraph's constants were
70
+ * tuned for instead of pinning every node at the unit speed clamp.
71
+ * @param n - the node count
72
+ * @returns the factor in (0, 1]
73
+ */
74
+ export function springSizeFactor(n) {
75
+ return Math.min(1, SE_SCALE_REFERENCE_NODES / Math.max(1, n));
76
+ }
77
+ /**
78
+ * An optional force constant: undefined keeps the fallback; null means the size-scaled default; else a finite number
79
+ * passing `ok`.
80
+ * @param name - the option name
81
+ * @param given - the value given
82
+ * @param fallback - the previous record's value or the default
83
+ * @param ok - the range predicate
84
+ * @param range - the range text of the error
85
+ * @returns the number or null
86
+ */
87
+ function pickNullable(name, given, fallback, ok, range) {
88
+ if (given === undefined) {
89
+ return fallback;
90
+ }
91
+ if (given === null) {
92
+ return null;
93
+ }
94
+ return pickNumber(name, given, 1, ok, `${range} or null`);
95
+ }
96
+ // ============================================================ the resolver
97
+ /**
98
+ * Applies SE_DEFAULTS to the option record; validates ranges (spec 7.20; ngraph's constraints): `springLength` > 0,
99
+ * `springCoefficient` > 0, `dragCoefficient` >= 0, `timeStep` > 0, `gravity` any finite number (negative repels; ngraph's
100
+ * comment: "if you make it positive nodes start attract each other"). `gravity` and `springCoefficient` left out (or
101
+ * null) resolve to null: ngraph's constant times springSizeFactor(n), applied in paramsFor once n is known. With `previous` the record is a PATCH over it and
102
+ * `maxInFlight` may not change (the uniform ring is sized by it at construction).
103
+ * @param options - the caller's options (or a setParams patch)
104
+ * @param previous - the current resolved record when resolving a patch
105
+ * @returns the frozen resolved record
106
+ */
107
+ export function resolveSpringElectricalOptions(options, previous) {
108
+ const o = options ?? {};
109
+ const base = previous ?? DEFAULT_RESOLVED;
110
+ if (previous !== undefined && o.maxInFlight !== undefined && o.maxInFlight !== previous.maxInFlight) {
111
+ throw new WebGpuGraphError("E_INVALID_ARGUMENT", `maxInFlight cannot change after creation (the uniform ring is sized by it): got ${describeValue(o.maxInFlight)}, current ${previous.maxInFlight}`, { argument: "maxInFlight", value: o.maxInFlight, expected: previous.maxInFlight });
112
+ }
113
+ const resolved = {
114
+ springLength: pickNumber("springLength", o.springLength, base.springLength, (v) => v > 0, "> 0"),
115
+ springCoefficient: pickNullable("springCoefficient", o.springCoefficient, base.springCoefficient, (v) => v > 0, "> 0"),
116
+ gravity: pickNullable("gravity", o.gravity, base.gravity, () => true, "a finite number (negative repels)"),
117
+ dragCoefficient: pickNumber("dragCoefficient", o.dragCoefficient, base.dragCoefficient, (v) => v >= 0, ">= 0"),
118
+ timeStep: pickNumber("timeStep", o.timeStep, base.timeStep, (v) => v > 0, "> 0"),
119
+ dim: pickDim(o.dim, base.dim),
120
+ scale: pickNumber("scale", o.scale, base.scale, (v) => v > 0, "> 0"),
121
+ center: pickCenter(o.center, base.center),
122
+ seed: pickSeed(o.seed, base.seed),
123
+ settleThreshold: pickNumber("settleThreshold", o.settleThreshold, base.settleThreshold, (v) => v >= 0, ">= 0"),
124
+ settleWindow: pickNumber("settleWindow", o.settleWindow, base.settleWindow, isPositiveInteger, "an integer >= 1"),
125
+ iterationsPerStep: pickNumber("iterationsPerStep", o.iterationsPerStep, base.iterationsPerStep, (v) => isPositiveInteger(v) && v <= MAX_ITERATIONS_PER_STEP, `an integer in [1, ${MAX_ITERATIONS_PER_STEP}]`),
126
+ maxInFlight: pickNumber("maxInFlight", o.maxInFlight, base.maxInFlight, isPositiveInteger, "an integer >= 1"),
127
+ };
128
+ return Object.freeze(resolved);
129
+ }
130
+ /**
131
+ * The mass of the preset: `1 + degree / 3` per node (ngraph index.js:391-395; the undirected snapshot's outDegree is
132
+ * the degree), as the Float32Array the simulation packs into pos.w.
133
+ * @param s - the snapshot
134
+ * @returns n masses
135
+ */
136
+ function massOf(s) {
137
+ const degree = s.outDegree();
138
+ const out = new Float32Array(s.nodeCount);
139
+ for (let i = 0; i < s.nodeCount; i++) {
140
+ out[i] = 1 + degree[i] / 3;
141
+ }
142
+ return out;
143
+ }
144
+ /** The spring-electrical model (spec 7.20: K1 K2 K3 K5 per iteration; toScene once per batch). Stages: ["K1", "K2", "K3", "K5", "toScene"]. */
145
+ export class SpringElectricalModel {
146
+ /**
147
+ * Creates the model for one simulation.
148
+ * @param tuning - the resolved GPU-only tuning
149
+ * @param resolved - the resolved option record at creation
150
+ */
151
+ constructor(tuning, resolved) {
152
+ /** The model kind of spec 7.19. */
153
+ this.kind = "springElectrical";
154
+ /** The stage names in dispatch order (the `upTo` vocabulary of recordIteration and debugRunStages). */
155
+ this.stages = SE_STAGES;
156
+ /** Fa2Params: the per-iteration uniform block (the simulation writes the shared fields into it). */
157
+ this.params = FA2_PARAMS;
158
+ /** Fa2State: the state header block. */
159
+ this.state = FA2_STATE;
160
+ /** Fa2Trace: one record per iteration of a batch. */
161
+ this.trace = FA2_TRACE;
162
+ /** The resources of the last bind(), or null before the first. */
163
+ this.resources = null;
164
+ /** The kernels and bind groups of the last bind(), or null before it (and for n === 0). */
165
+ this.bound = null;
166
+ /** The K1-K5 compute pass of the batch being recorded, keyed by CommandBatch.id; null between batches. */
167
+ this.openPass = null;
168
+ this.tuning = tuning;
169
+ this.current = resolved;
170
+ }
171
+ /**
172
+ * force 12n (zeroed), velocity 12n (zeroed: every load() starts at rest, `allocate()` / `clearKept()` honour
173
+ * `zero`) and the 256-byte FillParams uniform buffer. n = 0 reports one node's worth of bytes so no zero-length
174
+ * buffer is ever created.
175
+ * @param n - the node count
176
+ * @param _dim - the layout dimension (the arrays are stride 3 in both)
177
+ * @returns the three model-owned buffer specs
178
+ */
179
+ buffers(n, _dim) {
180
+ const bytes = Math.max(1, n) * FORCE_BYTES_PER_NODE;
181
+ const usage = BufferUsage.STORAGE | BufferUsage.COPY_SRC | BufferUsage.COPY_DST;
182
+ return [
183
+ { name: "force", byteLength: bytes, usage, zero: true },
184
+ { name: VELOCITY_BUFFER, byteLength: bytes, usage, zero: true },
185
+ {
186
+ name: FILL_PARAMS_BUFFER,
187
+ byteLength: UNIFORM_SLOT_BYTES,
188
+ usage: BufferUsage.UNIFORM | BufferUsage.COPY_DST,
189
+ zero: false,
190
+ },
191
+ ];
192
+ }
193
+ /**
194
+ * { mass: 1 + degree / 3, weights: none } (PD-11): the preset has no mass or weight option, and K2 compiles
195
+ * HAS_WEIGHTS = false. No `fixed` (setFixed is the live API). The tier rule is the simulation's (load() throws
196
+ * E_UNSUPPORTED for the grid tier before calling this).
197
+ * @param s - the snapshot being loaded
198
+ * @param _options - the simulation's current option record (unused: nothing in it affects the inputs)
199
+ * @returns the per-load inputs
200
+ */
201
+ inputs(s, _options) {
202
+ return { mass: massOf(s), weights: { data: null, source: "none", column: null } };
203
+ }
204
+ /**
205
+ * The constant SE_OVERRIDES (PD-1): no option changes a law, so setParams never recompiles.
206
+ * @param _options - an option record (unused)
207
+ * @returns the model's own override set
208
+ */
209
+ overrides(_options) {
210
+ return SE_OVERRIDES;
211
+ }
212
+ /**
213
+ * The six module specs of an override set in dispatch order -- K1, K2, K3, K5, toScene, fill -- each with only the
214
+ * override names its entry declares (K2 also USE_PERM / HAS_WEIGHTS), for warm() and the compile matrix.
215
+ * @param overrides - the merged override set (the model's plus USE_PERM / HAS_WEIGHTS)
216
+ * @param _subgroups - accepted for the ForceModel interface and unused (the composer picks the twin from caps)
217
+ * @returns the specs
218
+ */
219
+ specs(overrides, _subgroups) {
220
+ return [
221
+ kernelSpec("fa2-stats-finalize", subset(overrides, K1_DEFAULTS)),
222
+ kernelSpec("fa2-attraction", subset(overrides, K2_DEFAULTS)),
223
+ kernelSpec("fa2-repulsion-exact", subset(overrides, K3_DEFAULTS)),
224
+ kernelSpec("fa2-integrate", subset(overrides, K5_DEFAULTS)),
225
+ kernelSpec("fa2-to-scene"),
226
+ kernelSpec("fill"),
227
+ ];
228
+ }
229
+ /**
230
+ * Compiles (through the cache) and binds every kernel against the buffers of this load(): K1, K2 (or the fill of
231
+ * force when arcCount === 0), K3 and K5 with the velocity in their `oldForce` slot (PD-2), toScene; writes the
232
+ * FillParams { count: 3n, value: 0, mode: 0 } into the model's uniform buffer. With n === 0 nothing is bound.
233
+ * @param resources - the graph, the shared and model buffers, the ring and the cache
234
+ * @param overrides - the merged override set
235
+ */
236
+ async bind(resources, overrides) {
237
+ this.dropBound();
238
+ this.resources = resources;
239
+ const { n, pipelines, caps, core, perm, ring, device } = resources;
240
+ if (n === 0) {
241
+ return;
242
+ }
243
+ const [k1, k2, k3, k5, toScene, fill] = await Promise.all([
244
+ pipelines.kernel(kernelSpec("fa2-stats-finalize", subset(overrides, K1_DEFAULTS))),
245
+ pipelines.kernel(kernelSpec("fa2-attraction", subset(overrides, K2_DEFAULTS))),
246
+ pipelines.kernel(kernelSpec("fa2-repulsion-exact", subset(overrides, K3_DEFAULTS))),
247
+ pipelines.kernel(kernelSpec("fa2-integrate", subset(overrides, K5_DEFAULTS))),
248
+ pipelines.kernel(kernelSpec("fa2-to-scene")),
249
+ pipelines.kernel(kernelSpec("fill")),
250
+ ]);
251
+ if (this.resources !== resources) {
252
+ // a newer bind() superseded this one while the pipelines compiled; its own bind groups stand
253
+ return;
254
+ }
255
+ const pos = resources.buffer("positions");
256
+ const scene = resources.buffer("scenePositions");
257
+ const fixed = resources.buffer("fixed");
258
+ const partials = resources.buffer("partials");
259
+ const state = resources.buffer("state");
260
+ const trace = resources.buffer("trace");
261
+ const force = resources.buffer("force");
262
+ const velocity = resources.buffer(VELOCITY_BUFFER);
263
+ const fillParamsBuffer = resources.buffer(FILL_PARAMS_BUFFER);
264
+ const params = ring.binding(FA2_PARAMS);
265
+ const fillParams = {
266
+ buffer: fillParamsBuffer.buffer,
267
+ offset: fillParamsBuffer.offset,
268
+ size: FILL_PARAMS.byteLength,
269
+ window: null,
270
+ };
271
+ const fillBytes = new ArrayBuffer(FILL_PARAMS.byteLength);
272
+ FILL_PARAMS.write(new DataView(fillBytes), { count: 3 * n, value: 0, mode: 0 });
273
+ device.queue.writeBuffer(fillParamsBuffer.buffer, fillParamsBuffer.offset, fillBytes);
274
+ const hasArcs = core.colIdx !== null;
275
+ const wg = k1.workgroupSize;
276
+ this.bound = {
277
+ n,
278
+ plan: plan1d(n, wg, caps),
279
+ fillPlan: plan1d(3 * n, wg, caps),
280
+ k1,
281
+ k1Bound: k1.bind({ partials, S: state, T: trace, P: params }),
282
+ k2,
283
+ k2Bound: hasArcs
284
+ ? k2.bind({ ...graphBindings(core, perm, resources.weights), pos, force, P: params })
285
+ : null,
286
+ k3,
287
+ k3Bound: k3.bind({ pos, S: state, force, oldForce: velocity, fixedMask: fixed, partials, P: params }),
288
+ k5,
289
+ k5Bound: k5.bind({ force, oldForce: velocity, fixedMask: fixed, S: state, pos, partials, P: params }),
290
+ toScene,
291
+ toSceneBound: toScene.bind({ pos, scene, P: params }),
292
+ fill,
293
+ fillForceBound: hasArcs ? null : fill.bind({ dst: force, P: fillParams }),
294
+ };
295
+ }
296
+ /**
297
+ * The Fa2Params values of one iteration: the shared fields, the FA2 fields at 0 (no centre gravity, PD-12; no
298
+ * FR temperature) and ngraph's five constants with `gravity` in `coulomb`.
299
+ * @param iteration - the global iteration index
300
+ * @param options - the simulation's current option record
301
+ * @returns the uniform values
302
+ */
303
+ paramsFor(iteration, options) {
304
+ const { n } = this.requireResources();
305
+ const resolved = resolveSpringElectricalOptions(options, this.current);
306
+ const { nearMax, extentFactor } = this.tuning;
307
+ return {
308
+ n,
309
+ dim: resolved.dim,
310
+ flags: 0,
311
+ tierStart: 0,
312
+ tierEnd: n,
313
+ iterationIndex: iteration,
314
+ seed: seedWord(resolved.seed),
315
+ nearMax,
316
+ scalingRatio: 0,
317
+ gravity: 0,
318
+ jitterTolerance: 0,
319
+ scale: resolved.scale,
320
+ center: [resolved.center[0], resolved.center[1], resolved.center[2], 0],
321
+ settleThreshold: resolved.settleThreshold,
322
+ extentFactor,
323
+ gridMax: 0,
324
+ levels: 0,
325
+ pad: [0, 0, 0, 0],
326
+ frK: 0,
327
+ temperature: 0,
328
+ springLength: resolved.springLength,
329
+ springCoefficient: resolved.springCoefficient ?? SE_DEFAULTS.springCoefficient * springSizeFactor(n),
330
+ coulomb: resolved.gravity ?? SE_DEFAULTS.gravity * springSizeFactor(n),
331
+ dragCoefficient: resolved.dragCoefficient,
332
+ timeStep: resolved.timeStep,
333
+ };
334
+ }
335
+ /**
336
+ * Records one iteration into the batch: K1, K2 (or the fill of force when arcCount === 0), K3, K5 in the batch's
337
+ * ONE K1-K5 compute pass, then toScene in a second pass that ends it, stopping after stage `upTo` when given.
338
+ * With n === 0 nothing is recorded; a call before bind() completed is E_NOT_LOADED.
339
+ * @param batch - the batch being recorded
340
+ * @param slot - the UniformRing slot holding this iteration's Fa2Params
341
+ * @param tier - "exact" (the grid tier is E_UNSUPPORTED; the simulation never passes "grid")
342
+ * @param upTo - a stage name to stop after; undefined records every stage including toScene
343
+ */
344
+ recordIteration(batch, slot, tier, upTo) {
345
+ if (tier === "grid") {
346
+ throw new WebGpuGraphError("E_UNSUPPORTED", "the grid repulsion tier lands in P4", {
347
+ feature: "repulsion.grid",
348
+ hint: 'pass repulsion: "exact"',
349
+ });
350
+ }
351
+ const resources = this.requireResources();
352
+ const stop = upTo === undefined ? SE_STAGES.length - 1 : this.stageIndex(upTo);
353
+ const { bound } = this;
354
+ if (bound === null) {
355
+ if (resources.n === 0) {
356
+ return;
357
+ }
358
+ throw new WebGpuGraphError("E_NOT_LOADED", "the spring-electrical model is not bound (bind() has not completed)", { state: "loaded" });
359
+ }
360
+ const offset = resources.ring.offsetOf(slot);
361
+ const pass = this.openPass !== null && this.openPass.id === batch.id ? this.openPass.pass : batch.pass("se");
362
+ this.openPass = { id: batch.id, pass };
363
+ bound.k1.dispatch(pass, bound.k1Bound, ONE_WORKGROUP, [offset]);
364
+ if (stop < 1) {
365
+ return;
366
+ }
367
+ if (bound.k2Bound !== null) {
368
+ bound.k2.dispatch(pass, bound.k2Bound, bound.plan, [offset]);
369
+ }
370
+ else if (bound.fillForceBound !== null) {
371
+ bound.fill.dispatch(pass, bound.fillForceBound, bound.fillPlan, [0]);
372
+ }
373
+ if (stop < 2) {
374
+ return;
375
+ }
376
+ bound.k3.dispatch(pass, bound.k3Bound, bound.plan, [offset]);
377
+ if (stop < 3) {
378
+ return;
379
+ }
380
+ bound.k5.dispatch(pass, bound.k5Bound, bound.plan, [offset]);
381
+ if (stop < 4) {
382
+ return;
383
+ }
384
+ // the second pass ends the K1-K5 pass; the batch is complete after toScene, so nothing reuses it
385
+ this.openPass = null;
386
+ const scenePass = batch.pass("se-to-scene");
387
+ bound.toScene.dispatch(scenePass, bound.toSceneBound, bound.plan, [offset]);
388
+ }
389
+ /**
390
+ * kineticEnergy = 0 and temperature = 0 in the header (the velocities start at 0 through the buffer's `zero`).
391
+ * @param state - the state writer of the simulation
392
+ */
393
+ onLoad(state) {
394
+ state.set("kineticEnergy", 0);
395
+ state.set("temperature", 0);
396
+ }
397
+ /**
398
+ * Nothing: the velocities carry on (ngraph has no reheat; a drag lands in the next batch through the override
399
+ * list, spec 7.12).
400
+ * @param _state - the state writer of the simulation (unused)
401
+ */
402
+ onReheat(_state) {
403
+ // intentionally empty (D8; DEP-P5-A)
404
+ }
405
+ /**
406
+ * Replaces the record with the patch applied (every option is a numeric tweak; nothing recompiles, no reset).
407
+ * @param patch - the setParams patch
408
+ * @param _state - the state writer of the simulation (unused)
409
+ */
410
+ onSetParams(patch, _state) {
411
+ this.current = resolveSpringElectricalOptions(patch, this.current);
412
+ }
413
+ /**
414
+ * Decodes the state header and the k trace records of a completed batch into SpringElectricalStats: the exact
415
+ * tier with null grid fields; msPerIteration null (the simulation owns the clock); `kineticEnergy` is the last
416
+ * folded value (one iteration behind the last integrate, PD-4).
417
+ * @param state - a DataView over the 256-byte state header
418
+ * @param trace - a DataView over the k Fa2Trace records of the batch
419
+ * @returns the stats
420
+ */
421
+ readStats(state, trace) {
422
+ const header = FA2_STATE.read(state);
423
+ const centroid = vector(header, "centroid");
424
+ const records = [];
425
+ const count = Math.floor(trace.byteLength / TRACE_RECORD_BYTES);
426
+ for (let i = 0; i < count; i++) {
427
+ const record = FA2_TRACE.read(trace, i * TRACE_RECORD_BYTES);
428
+ records.push({
429
+ kineticEnergy: scalar(record, "modelScalar"),
430
+ meanDisplacement: scalar(record, "meanDisplacement"),
431
+ settledCount: scalar(record, "settledCount"),
432
+ });
433
+ }
434
+ return {
435
+ iteration: scalar(header, "iteration"),
436
+ meanDisplacement: scalar(header, "meanDisplacement"),
437
+ rmsRadius: scalar(header, "rmsRadius"),
438
+ layoutRadius: scalar(header, "radius"),
439
+ centroid: [centroid[0], centroid[1], centroid[2]],
440
+ repulsionTier: "exact",
441
+ maxCellOccupancy: null,
442
+ outsideGrid: null,
443
+ msPerIteration: null,
444
+ kineticEnergy: scalar(header, "kineticEnergy"),
445
+ trace: records,
446
+ };
447
+ }
448
+ /**
449
+ * The resources of the last bind(), or E_NOT_LOADED before it.
450
+ * @returns the resources
451
+ */
452
+ requireResources() {
453
+ if (this.resources === null) {
454
+ throw new WebGpuGraphError("E_NOT_LOADED", "the spring-electrical model has not been bound (load() first)", { state: "created" });
455
+ }
456
+ return this.resources;
457
+ }
458
+ /**
459
+ * The index of a stage name in SE_STAGES, or E_INVALID_ARGUMENT.
460
+ * @param upTo - the stage name
461
+ * @returns its index
462
+ */
463
+ stageIndex(upTo) {
464
+ for (let i = 0; i < SE_STAGES.length; i++) {
465
+ if (SE_STAGES[i] === upTo) {
466
+ return i;
467
+ }
468
+ }
469
+ throw invalid("upTo", upTo, SE_STAGES.join(" | "));
470
+ }
471
+ /** Drops the bind groups of the previous bind() (the buffers changed) and forgets the pass of a batch recorded before the rebind. */
472
+ dropBound() {
473
+ this.openPass = null;
474
+ const { bound } = this;
475
+ if (bound === null) {
476
+ return;
477
+ }
478
+ for (const kernel of [bound.k1, bound.k2, bound.k3, bound.k5, bound.toScene, bound.fill]) {
479
+ kernel.invalidate();
480
+ }
481
+ this.bound = null;
482
+ }
483
+ }
484
+ // ============================================================ the factory
485
+ /**
486
+ * The resolve callback of the simulation's setParams: the patch over the current record, re-validated.
487
+ * @param patch - the setParams patch
488
+ * @param current - the simulation's current option record
489
+ * @returns the new record
490
+ */
491
+ function resolvePatch(patch, current) {
492
+ return resolveSpringElectricalOptions(patch, resolveSpringElectricalOptions(current));
493
+ }
494
+ /**
495
+ * Spec 3.3 createSpringElectrical, verbatim: a GpuLayoutSimulation running ngraph's spring-electrical model on the
496
+ * exact repulsion tier with ngraph's defaults (spec 7.20) and the GPU-only tuning of GpuLayoutTuning.
497
+ * @param ctx - the context (E_DISPOSED / E_DEVICE_LOST through assertReady)
498
+ * @param options - the spring-electrical options and the GPU-only tuning knobs in one record
499
+ * @returns the simulation in state "created"; load() next
500
+ */
501
+ export function createSpringElectrical(ctx, options) {
502
+ ctx.assertReady();
503
+ const resolved = resolveSpringElectricalOptions(options);
504
+ const tuning = resolveLayoutTuning(options);
505
+ const model = new SpringElectricalModel(tuning, resolved);
506
+ return new ForceSimulation(ctx, model, resolved, tuning, resolvePatch);
507
+ }
508
+ //# sourceMappingURL=spring-electrical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"spring-electrical.js","sourceRoot":"","sources":["../../../src/layouts/spring-electrical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EACH,uBAAuB,EACvB,WAAW,EACX,wBAAwB,EACxB,kBAAkB,EAClB,kBAAkB,GACrB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhD,OAAO,EAAqB,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAIlE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAUzG,OAAO,EAGH,eAAe,GAIlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACH,aAAa,EACb,kBAAkB,EAClB,oBAAoB,EACpB,OAAO,EACP,iBAAiB,EAEjB,UAAU,EACV,OAAO,EACP,UAAU,EACV,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,GACT,MAAM,mBAAmB,CAAC;AAE3B,yEAAyE;AAEzE,wGAAwG;AACxG,MAAM,SAAS,GA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