/ concept-collection / turing-surface
Sign in
concept-collection / turing-surface
523 lines · 26.2 KBPreviewCodeBlameHistoryRaw
1# turing-surface
3Reaction–diffusion systems (Turing patterns) on **closed surfaces given by
4spherical-harmonic embeddings**, solved live in the browser with a spectral
5method whose transforms run on the GPU via WebGPU.
7This is the sibling of
8[turing-sphere](https://github.com/concept-collection/turing-sphere), which
9solves the same systems on the round sphere. Everything there is here; what is
10added is a *surface*.
12> [!NOTE]
13> **The geometry is in the operator.** The models solve with the surface's
14> Laplace–Beltrami operator, iterated by a fixed-count preconditioned
15> Richardson solve ([`solvers/richardson.m`](solvers/richardson.m), applying
16> [`lib/dlap.m`](lib/dlap.m)). The iteration count is fixed at compile time
17> with no residual check, so a shape/timestep/diffusivity combination outside
18> its convergence radius diverges over many steps rather than being caught —
19> the tests pin the known cases. See
20> [Where the geometry enters the operator](#where-the-geometry-enters-the-operator).
22## What a surface is here
24A geometry is an embedding of the sphere into R³: three scalar fields x, y, z
25over the (θ, φ) parametrization, each carried as spherical-harmonic
26coefficients. The unit sphere is the case where all three are pure degree-1
27harmonics.
29You write one down as MATLAB, in [`geometries/`](geometries/):
31```matlab
32function [gx, gy, gz] = shape(theta, phi, waist, stretch)
33 st = sin(theta);
34 r = 1 - waist * (st .^ 2);
35 gx = r .* (st .* cos(phi));
36 gy = r .* (st .* sin(phi));
37 gz = (1 + stretch) * (r .* cos(theta));
38end
39```
41That is ordinary element-wise MATLAB and goes through the same compiler and the
42same WGSL backend the models do. It is evaluated once on the solver's grid, and
43then **analysed into coefficients**, which is the form everything downstream
44uses. Two things follow from going through the coefficients rather than keeping
45the pointwise values:
47- **It is exactly band-limited at lmax.** The surface has as many derivatives as
48 the scheme needs and no aliased content the solver cannot see. What the solver
49 and the renderer both use is the *synthesis* of the coefficients, so for a
50 shape with sharp features the surface being solved on is not quite the one
51 that was written down — which is the honest thing for a spectral method to do.
52- **It can be evaluated on any grid.** The renderer draws the surface on the
53 (possibly finer) display grid by synthesizing the same coefficients there.
54 That is exact interpolation, not subdivision — the same argument that lets the
55 species fields be oversampled, and it is checked directly in the tests.
57Four geometries ship: [sphere](geometries/sphere.m) (the reference case),
58[ellipsoid](geometries/ellipsoid.m), [peanut](geometries/peanut.m) — a dumbbell
59whose waist is a saddle — and [bumpy](geometries/bumpy.m). Each is editable in
60the page, with its own parameters. Changing a shape does not recompile the
61solver and does not disturb the run: the geometry is data whose shape in the
62bindings depends only on the grid, so a swap is six buffer writes and the
63pattern carries straight on.
65A **morph** slider blends the drawn surface back to the unit sphere. The
66parametrization is the sphere's either way, so sweeping it shows which point
67went where.
69## The scheme, and where the geometry enters
71It solves the N-species system
73```
74d(u_k)/dt = D_k*lap_g(u_k) + f_k(t, u_1, ..., u_N), k = 1, ..., N
75```
77where `lap_g` is the Laplace–Beltrami operator of the surface. On the round
78sphere `lap_g` is diagonal in spherical-harmonic space with eigenvalues
79`-l(l+1)`, which is what makes turing-sphere's implicit diffusion a single
80divide. On a general surface it is not diagonal, and not even constant-
81coefficient, so that divide has to become a solve.
83The models split the operator:
85```
86lap_g = lap_s + dlap
87```
89with `lap_s` the round-sphere one. `(I - dt*D*lap_s)` is still exactly
90invertible, so the implicit step
92```
93(I - dt*D*lap_g) Unew = B
94```
96rearranges into a fixed point that keeps the whole geometry on the right-hand
97side,
99```
100Unew = (B + dt*D*dlap(Unew)) ./ (1 + dt*D*lam)
101```
103and the loop iterates it from the round-sphere answer. That is preconditioned
104Richardson, with the operator we can invert exactly as the preconditioner; it
105converges while `dt*D*dlap` stays small against `(I - dt*D*lap_s)`, which is
106what keeps the cost to a few transforms per step rather than a full elliptic
107solve.
109The pieces of that sentence are separate files, because they are separate
110ideas. The **operator**`dlap` applied to a spectral field — is
111[`lib/dlap.m`](lib/dlap.m). The **solver** — the fixed point above, iterated
112`niter` times — is [`solvers/richardson.m`](solvers/richardson.m):
114```matlab
115function X = richardson(B, dtD, lam, filt, Vtx, Vty, Vtz, Vpx, Vpy, Vpz, niter)
116 X = B ./ (1 + dtD * lam);
117 for k = 1:niter
118 dL = dlap(X, filt, Vtx, Vty, Vtz, Vpx, Vpy, Vpz, lam);
119 X = (B + dtD * dL) ./ (1 + dtD * lam);
120 end
121end
122```
124And a **model** is a reaction plus one solve per species — the whole of
125[`models/schnakenberg.m`](models/schnakenberg.m)'s step is:
127```matlab
128function [Un, Vn, u, v] = step(U, V, lam, filt, wlm, gx, gy, gz, Vtx, Vty, Vtz, Vpx, Vpy, Vpz, a, b, D1, D2, dt, nlm, niter)
129 u = synth(U);
130 v = synth(V);
131 uuv = u .* u .* v;
133 Bu = U + dt * analys(a - u + uuv);
134 Bv = V + dt * analys(b - uuv);
136 Un = solve(Bu, dt * D1, lam, filt, wlm, Vtx, Vty, Vtz, Vpx, Vpy, Vpz, nlm, niter);
137 Vn = solve(Bv, dt * D2, lam, filt, wlm, Vtx, Vty, Vtz, Vpx, Vpy, Vpz, nlm, niter);
138end
139```
141`solve` is a one-line, host-generated shim (`src/mgpu/libs.ts`) forwarding to
142whichever solver the app's **solver control** currently selects — every
143solver composes from `dlap` (the matvec is
144`(1 + dtD.*lam).*x - dtD.*dlap(x)`, the preconditioner the elementwise
145divide), and the choice is part of what compiles, so switching recompiles,
146like changing `niter` already does. A model may equally name a solver
147directly in those call lines. The operator and every solver are files in the
148page's editor, next to the model and the surface — edit one and recompile,
149same as the model. The Richardson solver is written as a full re-evaluation
150rather than an accumulated correction on purpose: where `dlap` computes to
151zero there is no correction to mis-round, and the divide is turing-sphere's
152arithmetic unchanged.
154Three solvers ship. [`solvers/bicgstab.m`](solvers/bicgstab.m) solves the
155same system by preconditioned BiCGSTAB — same `dlap`, same preconditioner, a
156Krylov recurrence instead of a stationary one, at two `dlap` evaluations per
157iteration instead of one. Its scalars (`rho`, `alpha`, `omega`) never touch
158the CPU: `dot` is a GPU reduction into a 1-element buffer, the recurrences on
159its results compile to 1-element kernels, and a single-element value
160broadcasts into the vector updates. Inner products carry the half-spectrum
161weight `wlm` (m > 0 counts twice), making them the real L2 inner products on
162the sphere. With no residual test, every ratio `a/b` is written in the
163guarded form `a*b/(b*b + 1e-30)`, so a converged (or broken-down) iteration
164goes stationary instead of dividing noise by noise. The difference is not
165academic: at the app's default lmax, Schnakenberg on the peanut sits outside
166the Richardson iteration's convergence radius for `niter ≥ 2` and diverges,
167while BiCGSTAB on the identical operator converges monotonically — the tests
168pin both behaviors, side by side.
170[`solvers/gmres.m`](solvers/gmres.m) is right-preconditioned GMRES(niter) —
171one Arnoldi sweep, no restart — with the residual minimized over the whole
172Krylov space. Its bookkeeping is what the other solvers never need: a basis
173of niter+1 spectral fields, a Hessenberg matrix, Givens rotations, a
174triangular back-substitution. The basis lives in a *bank* (`getslab` /
175`setslab`: the k-th 2 × nlm field of a wider array), the small matrices are
176element-addressed (`getat` / `setat`), and both are functional updates the
177planner compiles to static-offset buffer copies — MATLAB's own `H(i,j) = h`
178cannot lower, because numbl must prove an indexed write in bounds before the
179loop unrolls, and a loop variable has no value yet at that point. Written as
180calls, the index resolves at *planning*, where unrolling has made it a
181literal. The same resolution lets an inner loop bound depend on the outer
182loop's variable, which is what makes the `for i = 1:j` orthogonalization
183sweep compile.
185### Where the geometry enters the operator
187[`lib/dlap.m`](lib/dlap.m) is Algorithm 3 of the evolving-surface notes: the
188field's θ/φ derivatives (the `dtheta`/`dphi` transforms,
189[`src/sht/deriv.ts`](src/sht/deriv.ts)) are contracted through the inverse
190metric quantities into a tangential gradient; each Cartesian component is
191re-analysed and differentiated again; the results recombine into the surface
192divergence, and `lam .* F` adds back what the round-sphere part already
193carries. The metric quantities `Vt*`/`Vp*`
194([`src/geom/metric.ts`](src/geom/metric.ts)) are built once from the
195embedding's derivatives when the geometry is (re)built — the geometry is
196static, so per step they are just six more buffers the kernels read. `filt`
197zeroes the top two spectral degrees wherever the operator re-differentiates,
198because the derivative recurrences cannot exactly represent a derivative
199there.
201On the sphere `dlap` computes to (numerical) zero, so any `niter` lands
202within transform round-off of the exact round-sphere answer — asserted in the
203tests. Off the sphere the correction genuinely moves the answer, and
204convergence is a real constraint: the fixed-count loop has no residual check,
205so the tests also pin which shape/niter combinations are known to sit outside
206the convergence radius and diverge.
208### Subroutines
210A model file is not limited to `init` and `step`: it can define further
211functions and call them, and every model compiles against the shared library
212files — [`lib/`](lib/) for operators, [`solvers/`](solvers/) for solvers —
213with MATLAB's visibility rules (a file's namesake function is public; a
214model-local function of the same name shadows it). numbl specializes each
215callee for the argument types at its call sites, and the host then splices
216the lowered body into the caller, one clone per call site
217([`src/mgpu/inlineCalls.ts`](src/mgpu/inlineCalls.ts)): arguments bind by
218renaming rather than copying, and assignments to a callee output become
219assignments to the caller's variable, which is what lets a solver iterate its
220result in place. Expansion runs before the fusion pass, so a call fuses
221exactly as the same code written inline would — the boundary costs nothing,
222and `describe()`'s op listing names the expanded internals
223(`richardson#1.X`). Recursion cannot unroll into a fixed op sequence and is
224refused at compile time, like a runtime loop bound.
226### `for` loops, unrolled
228A plan is a fixed list of GPU operations with no branching, which is what makes
229a timestep pure command recording — one submit, no CPU in the loop. A counted
230loop still fits: the planner
231([`src/mgpu/plan.ts`](src/mgpu/plan.ts)) unrolls it, planning the body once per
232iteration. The loop that matters is `solvers/richardson.m`'s `for k = 1:niter`,
233expanded into each model's step at every solve call site.
235Nothing else had to change for that, because numbl gives a variable one cName
236for every assignment to it: the buffer an iteration writes is the buffer the
237next one reads, which is exactly a loop-carried value. The loop variable gets no
238buffer at all — it is bound as a derived scalar to that iteration's literal, so
239a kernel reading `k` folds the number in.
241Two consequences worth stating:
243- **The bounds must be known when the model compiles.** `niter` is supplied as a
244 fixed scalar rather than a tunable one, so changing it recompiles — unlike a
245 parameter, which is a uniform. A bound may also be an enclosing unrolled
246 loop's variable (`for i = 1:j` — each unrolled `j` plans its own inner trip
247 count, which is how GMRES's triangular sweeps compile). A genuinely runtime
248 bound is refused at compile time with a source position, not silently
249 mis-compiled, and there is a test for that.
250- **Fusion survives.** numbl's inline pass recurses into loop bodies, so a line
251 inside the loop is still one kernel. It runs there with no protected names,
252 though, which means an assignment whose only visible use is later in the same
253 body can be elided — correct for a body-local temp, wrong if something outside
254 the loop wanted it. [`src/mgpu/compile.ts`](src/mgpu/compile.ts) snapshots what
255 each loop body assigns before the pass and refuses the ones that escape, so
256 that case is a compile error rather than a stale read.
258Unrolling is exactly linear in the trip count: 26 GPU ops per species per
259iteration (the operator's twelve transforms and the solve's kernels), asserted
260in the tests.
262## MATLAB, compiled to WebGPU
264Unchanged from turing-sphere, and it now compiles the geometry files too. numbl
265parses and lowers each function for the concrete argument types of the current
266grid; user-function calls are expanded into the caller, one clone per call
267site; the inline pass folds single-use temps back into their consumer, so one
268line of MATLAB becomes one expression tree; and this repo emits one WGSL compute
269kernel per element-wise statement
270([`src/mgpu/wgsl.ts`](src/mgpu/wgsl.ts)). `synth` / `analys` (and the
271derivative pair `dtheta` / `dphi`) are external operations whose type rules
272numbl learns from a `.mtoc2.js` workspace file, and which the backend maps onto
273the spherical-harmonic pipelines; `dot` is one more, mapped onto a
274single-dispatch reduction ([`src/mgpu/reduce.ts`](src/mgpu/reduce.ts)) whose
2751-element result stays on the GPU — scalars computed from it become 1-element
276kernels, and reading one inside a vector expression broadcasts it. The
277indexed-access ops (`getslab`/`setslab`, `getat`/`setat`) compile to
278static-offset buffer copies, their indices evaluated at planning time where
279the unrolled loop's variable is a literal. Anything it cannot express is
280refused at compile time with a source position.
282The Schnakenberg step above compiles to 65 GPU operations at one solve
283iteration: 28 transforms, 35 generated kernels, and 2 buffer copies feeding the
284new state back.
286Two consequences carried over:
288- **The step is synchronous.** WebGPU's encode path is synchronous and every
289 pipeline is built once at compile time, so a timestep is pure command
290 recording; the only `await` in the loop is the single readback per rendered
291 frame.
292- **Parameters are uniforms, not constants.** Moving a slider rewrites a small
293 buffer instead of triggering a recompile. Editing the MATLAB recompiles;
294 changing `dt` does not. `niter` is the deliberate exception, above.
296## Provenance
298- **turing-sphere**, which this is a fork of: the solver, the transforms
299 backend, the compilation path, the benchmarks and the analytic tests.
300- **Transforms:** [shtns-webgpu](https://github.com/concept-collection/shtns-webgpu) —
301 fp32 spherical harmonic transforms in WGSL compute shaders, modeled on
302 [SHTNS](https://nschaeff.bitbucket.io/shtns/). Vendored under
303 [`src/sht/`](src/sht/) (CECILL-2.1), including the f64 CPU reference transform
304 used for testing.
305- **Rendering:** three.js meshes with per-vertex colormaps, adapted from the
306 `SphereEmbedding` view in
307 [figpack](https://github.com/flatironinstitute/figpack)'s experimental
308 extension package ([`src/render/`](src/render/)). That view displays a
309 time-varying embedded geometry with fields on it, which is the same picture
310 this draws — including its sphere/surface morph, which turing-sphere had
311 dropped as having nothing to morph to.
313turing-sphere additionally carries a comparison against a native build of
314upstream SHTNS ([`bench/shtns/`](https://github.com/concept-collection/turing-sphere/tree/main/bench/shtns)).
315That is not duplicated here: the transforms are the same code, and its C-side
316transcription of the model would have to be maintained against a step this
317project intends to change.
319Because the algorithm is compiled to compute shaders, **WebGPU is required**
320there is no CPU fallback (the f64 CPU transform remains, for tests).
322## Numerics
324- Grid: Gauss–Legendre × equispaced-φ, dealiased for the cubic reactions with
325 the `(pdeg+1)` rule: `nlat ≥ ((pdeg+1)·lmax+1)/2`, `nphi ≥ (pdeg+1)·lmax+1`
326 (rounded up to a power of two for the GPU FFT path). At the default lmax 63
327 that is a 128×256 grid.
328- Spectral layout: SHTNS conventions — orthonormal + Condon–Shortley, complex
329 coefficients for m ≥ 0, m-major ordering.
330- fp32 transforms introduce ~1e-6 relative error per step; for pattern formation
331 from 1e-2 seeded noise this is inconsequential. The geometry goes through one
332 analysis/synthesis round trip and picks up the same round-off: the unit sphere
333 comes back with radius 1 to ~2e-5 under Dawn, ~4e-4 under SwiftShader.
334- The shipped geometries are all degree ≤ 5, far below any lmax the app offers,
335 so band-limiting removes nothing from them. A shape you write yourself may not
336 be so lucky — see the note in [`geometries/bumpy.m`](geometries/bumpy.m).
338## Desktop vs browser
340[`scripts/bench.ts`](scripts/bench.ts) runs the same thing the app runs — same
341`.m`, same generated WGSL, same transforms — from Node on desktop WebGPU (Google
342Dawn), and the app prints the command line that reproduces whatever it is
343currently simulating:
345```
346npm run bench -- --preset schnak-spots --geometry ellipsoid --lmax 63 --niter 1 \
347 --solver richardson \
348 --steps 2000 --seed 1 --a 0.1 --b 0.9 --D1 0.0004 --D2 0.008 --dt 0.05 \
349 --gax 1.5 --gay 1 --gaz 0.6
350```
352Copy it from under the stats line and compare the `ms/step` it reports with the
353app's. Both sides go through the one shared
354[`src/bench/runSpec.ts`](src/bench/runSpec.ts) — the app formats a run into that
355command, the benchmark parses it back — so there is no second copy of the
356defaults for the two runs to drift apart on. Geometry parameters take a `g`
357prefix (`--gwaist`) so a shape parameter can never collide with a model one.
359The app reports **two** numbers and only the first is comparable to the
360benchmark: `solver` is the batch of steps alone, waited for but not read back;
361`ms/frame` additionally carries a GPU→CPU readback per species, the
362colormapping, and the vertex upload. Those per-frame costs are fixed and do not
363shrink when the GPU gets faster, so on a quick GPU a frame can easily cost ten
364times the steps inside it. That is expected and is not the solver being slower
365in the browser.
367To attribute the gap rather than guess at it:
369```
370node scripts/compare-perf.mjs [--lmax 63] [--steps 300]
371```
373measures the same solver work in both — batched, nothing read back, no rendering
374on either side — and reports each with its CPU-encoding share, the Fourier
375stage, and the adapter. It stops you first if the two are not even the same
376device, which is a common cause of "the browser is much slower". Both sides
377resolve the geometry and the iteration count from the same constants, because
378the iteration count is unrolled into the step and a mismatch would compare two
379different amounts of work.
381The app's **Benchmark** button runs the same measurement in the page, plus the
382**ramp** — the first third of the run against the last. GPUs downclock when
383idle and an animation-paced loop leaves them idle most of every frame, so a
384large ramp means the steady-state number is limited by clocks rather than work.
386### Is it really the same computation?
388```
389node scripts/compare-env.mjs [--lmax 31] [--steps 200] [--preset schnak-spots]
390```
392runs one identical spec on the desktop and in a real browser and compares the
393final spectral state. The pipeline is deterministic given (model source,
394geometry, parameters, lmax, niter, seed, steps), so the two should agree to fp32
395round-off — not bit for bit, since GPUs differ in fused-multiply-add and other
396latitude fp32 allows. It also reports which Fourier stage each side chose, since
397FFT and DFT are genuinely different algorithms that round differently.
399Desktop WebGPU comes from the `webgpu` package (prebuilt Dawn, ~70 MB), an
400optional dependency so that an unsupported platform fails the install of that
401package alone. Its binaries need glibc 2.29+. Other flags: `--steps`,
402`--warmup`, `--batch`, `--json`, `--help`; `DAWN_FLAGS='backend=vulkan'`
403(`;`-separated) passes Dawn options through.
405## Tests
407There is no second implementation of the solver to diff against, so the `.m`
408path is checked against **closed-form answers** and against **exact structural
409properties**. Four modules, run in both environments:
411[`test/analyticChecks.ts`](test/analyticChecks.ts) — cases whose evolution is
412known exactly, run through the whole real pipeline. All three are statements
413about the round sphere, so all three build on the sphere geometry:
415- **A** — a linear reaction leaves every mode independent, growing by exactly
416 `(1 + dt*c) / (1 + dt*D*l(l+1))` per step. Pins the transform round trip, the
417 eigenvalue mapping, the IMEX update and the state feedback at once. ~2e-7 over
418 20 steps.
419- **B** — a nonlinear reaction on a uniform field stays uniform, so each step is
420 exactly the scalar ODE map. 1.5e-8 over 25 steps.
421- **C** — a 1e-6 perturbation of the Schnakenberg fixed point follows the
422 linearized 2×2 IMEX recurrence, and `(l=24, m=7)` is confirmed unstable.
423 Looser (~4e-3) because fp32 keeps about four digits of a perturbation that
424 small.
426[`test/geometryChecks.ts`](test/geometryChecks.ts) — the surface and the loop:
428- every geometry compiles and closes; the sphere has radius 1 everywhere and is
429 **exactly degree 1** in the harmonics, which is what makes the reference case
430 exact rather than merely accurate;
431- the peanut matches its own closed-form radial profile at every grid point, and
432 **the same coefficients give the same surface on a 2× grid** — the 2× Gauss
433 latitudes share no point with the 1× ones, so agreeing there is agreeing
434 everywhere, which is what "rendered exactly, not subdivided" means;
435- unrolling is **exactly linear** in the trip count; on the sphere the
436 geometric correction computes to (numerical) zero, so 0, 1 and 4 iterations
437 agree to transform round-off; on the peanut it **measurably moves the
438 answer**;
439- a niter × geometry sweep stays finite except the combinations **known to sit
440 outside the Richardson convergence radius**, which are pinned as diverging —
441 and on exactly those combinations **bicgstab and gmres keep converging**,
442 also pinned;
443- at equal niter, **bicgstab and gmres land far closer to the converged
444 answer** than richardson on the same operator;
445- a runtime loop bound is refused at compile time;
446- swapping the surface mid-run leaves the spectral state untouched.
448[`test/modelChecks.ts`](test/modelChecks.ts) compiles every model the app offers
449and asserts **how many kernels it compiles to**, split into the base step and
450what one solve iteration adds. That is a fusion guard: if numbl's inline pass
451stops folding, the results stay correct while every operator becomes its own
452dispatch, which is invisible in the numbers. It also compiles a model built of
453**user-defined subroutines** — multi-output, scalar-returning, a solver-like
454local with its own loop — asserts recursion is refused, and checks the
455**reduction and indexing primitives** directly against exact expected values:
456the `dot` sum and the `wlm`-weighted inner product against the CPU, scalar
457arithmetic on a GPU-resident result bit for bit, the 1-element broadcast, and
458element/slab round-trips through `setat`/`getat` and `setslab`/`getslab`.
460[`test/transformChecks.ts`](test/transformChecks.ts) compares the WGSL transforms
461against shtns-webgpu's f64 CPU twin.
463- `npm run test:node` — under Dawn on the desktop, via `vite-node`. Needs a GPU;
464 `--skip-without-gpu` lets a machine without one say so and move on (which is
465 what CI does, since the browser suite covers the same modules).
466- `npm run test:gpu` — builds and drives headless Chrome, on SwiftShader in CI.
467 Also runs the soak. A few geometry tolerances are set by SwiftShader's fp32,
468 which is about an order of magnitude looser than Dawn's.
470Other commands:
472- `npm run bench -- --help` — the desktop benchmark.
473- `npm run bench:sht -- --help` — the transforms alone, no solver.
474- `npx vite-node scripts/diagnose-sht.ts` — when the transform tests fail on a
475 GPU, say *which* stage is wrong.
476- `npx vite-node scripts/diagnose-leg.ts [--m 0]` — read the Legendre recurrence
477 out of the production shader term by term.
478- `npx vite-node scripts/longrun-node.ts [lmax]` — run to t = 100 and confirm the
479 pattern saturates rather than decaying or diverging.
480- `node scripts/soak.mjs [steps] [lmax]` — drive the demo for many steps,
481 sampling JS heap and catching crashes.
482- `node scripts/screenshot.mjs out.png [light|dark] [minSteps]` — screenshot the
483 demo after a number of steps.
484- `node scripts/check-live.mjs [url]` — smoke-check a deployed URL.
485- `test.html?soak=<steps>&lmax=<n>` — solver-only soak with no rendering.
487## Development
489```
490npm install
491npm run dev # local dev server
492npm run build # type-check + production build to dist/
493```
495### The numbl dependency
497numbl is a local `file:../../numbl` dependency, so a sibling checkout of
498[numbl](https://github.com/flatironinstitute/numbl) is required. We use its
499compiler internals — parser, lowerer, IR, inline pass — which its package
500`exports` map does not publish, so they are reached through the `numbl-src` path
501alias in [`vite.config.ts`](vite.config.ts).
503The exact surface we depend on is written down in
504[`src/mgpu/numbl.d.ts`](src/mgpu/numbl.d.ts) and TypeScript checks against
505*that*, not against numbl's sources. This keeps this project's compiler settings
506independent of numbl's, and means a change to one of those shapes upstream
507breaks the build here with a clear diff rather than deep inside numbl's tree.
508The `For` IR node is spelled out there, since the planner now walks it.
510CI clones numbl to the sibling path that the `file:` dependency expects, pinned
511to a commit, with `--ignore-scripts` (npm runs a linked package's `prepare`
512script, and numbl's is husky). numbl's own `node_modules` are not needed: the
513slice we import is self-contained TypeScript.
515The `scripts/*.ts` entry points that touch the compiler go through `vite-node`,
516so they resolve imports exactly as the browser build does. Plain `node` cannot:
517numbl's sources import each other as `./foo.js` while the files are `.ts`.
519Deployed to GitHub Pages by `.github/workflows/deploy.yml` on push to `main`.
521## License
523CECILL-2.1 (inherited from SHTNS via shtns-webgpu, whose sources are vendored).
moveopenescclose