Feature Library

Coupled oscillators on the GPU

0.94 GPU · 0.12 CPU ms
A still of the Coupled oscillators on the GPU demo
Still
The live demo starts when it’s in view.Trip a unit or open a line and watch the wheel · click the inset to swap views · on Fireflies, slide the coupling

Thousands of oscillators that pull each other into step, simulated in compute and drawn from the same buffers.

What it costs a frame

0.94 ms
0.12 ms
GPU
0.94 ms
CPU, median
0.12 ms
CPU, 95th pct
0.17 ms
Draw calls
0
Weight
Moderate

Measured 14 November 2026 on RTX 4060 Laptop, 13th Gen Intel(R) Core(TM) i9-13900H, Chrome 157, 1920×1080 at 1×. 600 frames × 3 rounds, median kept (rounds ranged GPU 0.57–1.48, CPU 0.12–0.13 ms). What ran: Measured on the power grid: 4,096 nodes, 32 steps a frame of the swing equation, the lines and the order parameter in compute, the map and the wheel inset drawn from the same buffers, timed by timestamp queries. A nuclear unit trips a second in, so the frames show a swing, governors and secondary control. Phones: tiers are being measured next.

On every machine it was measured on
MachineGPU msCPU msCPU p95
RTX 4060 Laptop · 13th Gen Intel(R) Core(TM) i9-13900Hreference · measuring tool0.940.120.17
apple · Apple A19 Proin a browser tab · 16 November 20266.630.220.28
Intel Arc 140V (Xe2-LPG) · Intel Core Ultra 7 258Vin a browser tab · 15 November 20262.360.250.39

Bars against one 16.7 ms frame. A browser-tab run is timed in a visible tab without the tool’s scripted input, so read it as close, not exact.

What it needs

Renders with
WebGPUNeeds WebGPU: current Chrome and Edge, Safari 26+, Firefox 141+ on Windows.
Your browser
Checking…Looking for WebGPU
Depends on
NothingNo other packages

What it’s for

  1. A live grid-frequency or control-room view that explains why inertia and reserves matter
  2. Teaching synchronisation: fireflies, metronomes, pacemaker cells, clapping audiences
  3. Any network whose nodes keep a rhythm and pull on their neighbours (clocks, generators, agents)
  4. A "what if this line opens" exploration on a network of your own
  5. A calm, living background whose nodes pulse at their own phases and drift into step

Pitfalls, in brief

  1. The step is semi-implicit in the damping, and still needs a floor on inertia: M ≥ max(dt² ΣK, 1.3 dt ΣΓ) per node (inertiaFloor).
  2. Even steps a frame: the node pass ping-pongs two state buffers, and the line pass, the reduction and the drawing read buffer A.
  3. The mean field lags one frame: the node pass reads the sums the last frame’s reduction wrote.
  4. Start a grid from its steady state (steady(), a Newton solve), never from zero angles: from zero every line sees the whole swing at once, overloads and trips, and the island falls apart in the first second.
  5. A line rating of Infinity is written as 1e30 for the GPU: WGSL makes no promise about infinities, and an inf in a uniform can turn a loading into NaN on some drivers.
5 more in brief
  1. Read-back is asynchronous and about ten times a second: the figures, the controller and secondary control run on that, not on the frame.
  2. The CPU and GPU twins do the same arithmetic but not the same rounding (f32 on the GPU, f64 between steps on the CPU), and a swing is chaotic: they agree in what happens (nadir, trips, recovery), not node for node.
  3. Grid ratings come from the steady flows of both scenarios and from an N-1 study (the heaviest meshed corridor opened, the steady state solved again): every line keeps 30 % over its evening flow after the opening, so an evening reroutes, while noon’s rerouted flows overload the local network, which heats and trips in about 9 s and cascades.
  4. Explicit bind group layouts: with layout "auto" each pipeline gets its own layout holding only the bindings it uses, and one bind group can no longer serve the node, line and reduction passes.
  5. The CPU twin is about a third of real time for 4,096 nodes on a laptop (about 0.4 ms a step).
10 pitfalls in full, the hook-up guide, the module source and its tests come with the part.

Where it comes from

From HaTac. Fully custom code.

Yoshiki Kuramoto, Self-entrainment of a population of coupled non-linear oscillators (1975): The model and its order parameter r e^{iψ}; the all-to-all coupling as one sum of the mean field.

G. Filatrella, A. H. Nielsen & N. F. Pedersen, Analysis of a power grid using a Kuramoto-like model (Eur. Phys. J. B, 2008): The swing equation read as second-order Kuramoto oscillators.

James Pantaleone, Synchronization of metronomes (American Journal of Physics, 2002): Metronomes pulled into step through the board they stand on; the demo’s boards are a hub-coupled analogue.

John Buck, Synchronous rhythmic flashing of fireflies (Quarterly Review of Biology, 1988): The fireflies preset.

Mark Jarzynski & Marc Olano, Hash Functions for GPU Rendering (JCGT, 2020): The PCG hash, bit for bit the same in WGSL and TypeScript, under the builders, the noise and the wheel’s jitter.

Magnus Hestenes & Eduard Stiefel, Methods of conjugate gradients (1952): The preconditioned solve inside the steady-state Newton step.

coupled oscillatorskuramotoswing equationsynchronisationorder parameterpower gridfrequencyinertiaload sheddingfirefliesmetronomessynchroscopenetworkcsr graphcompute shaderreductionraw webgpuwgslcpu twincanvas 2d fallbacktimestamp queriesno dependencies

Near it in the frame