Repository navigation
W2: sensor-field core, worker and parity - #591
Merged
neuromechanist merged 24 commits intoNov 25, 2026
Merged
neuromechanist merged 24 commits into
neuromechanist merged 24 commits into
Conversation
Partial pivoting in binary64 with the factors kept, so one matrix is solved for many maps in the same operation order as a fresh solve (neuroschema 0.6.0 linalg.py). Tested through the sensor-field and sensor-layout parity suites.
EEGLAB topoplot v4 map per neuroschema 0.6.0 and the ADR 0137 amendment: mean-removed interpolation, exact merge means, 8-sensor minimum, flat_field and near_flat notes, 5% minmax margin. Geometry (factorized G, evaluation matrix) is shared by every map of a view.
Positions to topoplot layout: exact BIDS frame table, scalp rows, montage or sphere center with the six bounds, cart2topo. The name rules it reads (fold, clean, finish, types, fiducials) live in sensor-names.ts for W2b to build on.
Every case of sensor-field.v1.json (42) and sensor-layout.v1.json (66, plus every frame name and cart2topo point) within the specs' parity bounds; refusals by exact word. Tested: 166/166 pass.
Mean removal (offset invariance, exact flat fields), the exact merge mean, the near-flat threshold either side, the 8-sensor minimum after merge and drop, the 5% minmax margin and EEGLAB absmax axis. Tested: 25/25 pass.
Types, name exclusions, unhyphenated keys and fiducials checked on all 5,895 sensor-labels.v1 channels, plus fold, clean and finish edge cases. Tested: 9/9 pass.
The renderer's own lines at the spec's six levels, outside parity: masked corners draw nothing, saddles split by the square's mean. Tested: straight lines, closed rings, masks, saddles (6/6).
Geometry cached by layout SHA-256 and usable rows, maps on screen first then batches, Float32 grids and contour segments transferred, cancel between batches. The client imports no numerics. Tested over a real MessageChannel: 15/15.
Diverging (ColorBrewer RdBu reversed), sequential (the viewer's viridis stops) and the Turbo LUT, with their Apache-2.0 notices; --qv-* tokens, data colors theme-independent, head line per theme. Tested: tokens equal the tables, viridis equals viridisColor, Turbo digest (7/7).
Each E and w value is loaded once for eight sums; every sum still runs over the sensors in order, so cells are bit-identical to the one-map loop. 128-sensor view (128 maps) 44 to 36 ms in Node. Tested: parity 47/47.
Each square is visited once and traced only for the levels inside its corner range, edges computed only when crossed. 128 maps: about 15 to 7 ms. Tested: contours 6/6, worker 15/15.
Vitest gates the full worker path at twice the budget (first maps 50 ms, 128-sensor view 100 ms, 256 at 300) for 128 and 256 IC maps; the Playwright spec times a real module worker in Chromium against the budgets themselves. Tested: both pass on this machine.
Worker at most 12 KB and the lazy chunk at most 30 KB gzipped, bundled alone with Bun (and in dist/ when built); runs in CI's test job. Tested: worker 5.2 KB, main thread so far 3.4 KB; a 4 KB budget fails it; bun run build passes.
976562.5 and 976562.4990234375 differ by exactly 1e-9 of the magnitude; the mutation of <= to < survived every other test and fails this one.
Deploying nemar-website with
|
| Latest commit: |
7862d85
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://5d29ebb9.nemar-website.pages.dev |
| Branch Preview URL: | https://feature-issue-588-w2-sensor.nemar-website.pages.dev |
1 task
center([v]) is v + 0, written without allocating a group array per sensor per map. Bit-identical: parity 47/47, the 42 core mutations still all killed.
MontageCenterUnavailable lets W3 catch the site's own wiring fault by type and leave the map undrawn with a sentence. Tested: layout parity 119/119.
Review of #591: grids leave as the algorithm's own Float64Array, transferred (Float32 flattened near-flat maps); geometry once per draw; contours only for maps on screen (contoursOf traces the rest); larger later batches; messageerror handled; a dropped worker's events ignored. Tested: the received grid of all 33 drawn vectors within the parity bound; stub-transport error paths (56/56).
Owner ruling: keep ADR 0137's budget. The perf test gates at the budget itself (first maps 50 ms, 128-map view 100 ms, 256 at 300) in its own CI step, alone on the runner, and is skipped inside the parallel suite. Tested on M4: 6.8 / 20.9 ms and 12.8 / 68.3 ms medians.
The CI size step now runs after astro build, even when Vitest failed, and measures dist/ once a page imports the client; until then Astro's own Vite builds the client as an entry with its worker. Shared chunks count. Tested: worker 5.2 KB, main thread 5.5 KB; lowered budgets and an entry-only count fail it.
entryFor works on halved operands, so an axis wider than the largest double (a flat field at 1.5e308, absmax +-1.575e308) places its cells, and a position that is not finite takes the middle entry, never an empty one. Tested: flat_huge_duplicate_pair paints entry 249 in every cell; both mutations fail.
public/licenses/quality-views/NOTICE.txt carries Turbo's and ColorBrewer's Apache-2.0 notices with the license's full text, served beside the bundles; COLOR_MAPS_NOTICE names it for legends and exports. Tested: the file holds both copyrights and the full license.
CI's Node has no global ErrorEvent, so two stub-transport tests failed there (one by timeout). The stub now raises an Event carrying the message the client reads. Tested: 56/56 with ErrorEvent deleted, the pushed version fails the same 2 that way.
4 tasks
neuromechanist
merged commit Nov 25, 2026
3689f2f
into
feature/issue-586-epic-pipeline-progress
3 of 4 checks passed
13 of 15 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase W2 of #588 (epic nemarOrg/nemar-cli#2324, nemar-cli ADR 0137 and its amendment of 2026-11-24, website ADR 0035): the scalp map's core, its module worker, and parity with neuroschema 0.6.0's reference.
Changes
src/lib/quality-views/sensor-field.ts:nemar.sensor-field.v1as neuroschema'sdocs/views/sensor-field.mdstates it.It is EEGLAB's topoplot with v4 interpolation, the Green's function d²(ln d − 1) solved by LU with partial pivoting, on a 67-by-67 grid masked at the head.
The amendment's rules are in: mean-removed interpolation z = m + spline(v − m), merges within 1e-3 at the exact mean
first + sum(x − first) / k, at least 8 interpolated sensors (too_few_sensors), theflat_fieldandnear_flatnotes, theminmaxaxis widened by 5% of the range (absmaxby EEGLAB'scaxis), six contour levels, and EEGLAB's head.head_outside_gridandinterpolation_failedare refused with their words.The geometry (factorized G, evaluation matrix) is built once per layout and set of usable sensors and shared by every map of a view.
linalg.ts: the LU solver, with its factors kept, so a cached solve gives the same bits as a fresh one.sensor-layout.ts:nemar.sensor-layout.v1.It uses the exact BIDS frame table and alias, refuses
frame_unknownand never assumes a frame, and lays out scalp rows only.Template positions are centered on the montage's center; measured positions on the algebraic sphere, with the six bounds (
positions_flat,positions_partial).The conversion is cart2topo, with theta in (−180, 180].
sensor-names.ts: the parts ofnemar.sensor-labels.v1the layout reads (fold, clean, finish, type classes, non-EEG prefixes, fiducials, the twenty montage names), for W2b to build on.worker.ts,worker-protocol.ts,worker-client.ts: the module worker.The geometry is cached by the layout file's SHA-256 and the usable rows (LRU of 6), with the cached places compared so a reused key never serves stale geometry.
The maps on screen go first in batches of 8, then the rest in batches of 64, with a cancel read between batches.
Each grid leaves as the algorithm's own
Float64Array, transferred; each geometry is sent once per draw; contour lines are traced in the worker for the maps on screen, andcontoursOftraces any other map's lines when it is shown.The client imports none of the interpolation, never rejects on worker trouble (
unavailablewith a reason, includingmessageerror), ignores a dropped worker's late events, and runs the same handler over aMessageChannelwhere a browser has noWorkerat all.No CSP change:
worker-src 'self'already allows it.contours.ts: marching squares, the renderer's own lines (outside parity). All levels are traced in one pass, masked corners draw nothing, and saddles are split by the square's mean.colormap.ts,turbo-lut.ts,--qv-*tokens intokens.css: three maps and the theme-aware head line.The diverging map is ColorBrewer RdBu reversed and colorblind-safe; the sequential map is the signal viewer's viridis stops, color for color; Turbo is Google's 256-entry table, rounded to 8 bits.
entryForplaces a value on halved operands, so an axis wider than the largest double still paints, and a position that is not finite takes the middle entry, never black.The Apache-2.0 notices for Turbo and ColorBrewer ship with the site, with the license's full text, in
public/licenses/quality-views/NOTICE.txt(COLOR_MAPS_NOTICE), and are listed inTHIRD_PARTY_NOTICES.md.scripts/check-quality-views-size.mjs, run in CI afterastro build: the worker at most 12 KB gzipped and the main-thread code (the client's chunk and every chunk it imports statically) at most 30 KB.It measures
dist/once a page imports the client; until then Astro's own Vite builds the client as an entry, with the worker emitted by Vite's worker plugin.test/quality-views-perf.test.ts: the drawing budget gated at the budget itself, in its own CI step, alone on the runner (bun run test:quality-views-perf);e2e/quality-views-perf.spec.tstimes a real module worker in Chromium.if: ${{ !cancelled() }}, so they run even when Vitest is red on the drift tests.Parity
Every case of
sensor-field.v1.json(42) andsensor-layout.v1.json(66) is replayed within the specs' bounds, and every refusal gives its exact word.Every ALS and RAS frame name gives
frame_als's orframe_ras's layout, and everycart2topopoint converts.Worst unmasked-cell error per drawn sensor-field case, as a share of the bound
1e-6 * range + 1e-12 * magnitude:The refused cases all match by word:
too_few_sensors: seven_sensors, merged_to_seven;head_outside_grid: far_sensor;interpolation_failed: overflow;frame_unknown: positions_frame_unknown, positions_montage_beside_a_frame;positions_flat: positions_flat_disk, positions_three, positions_ring.Worst layout errors over all drawn layout cases:
Performance
The owner's ruling keeps ADR 0137's budget: first maps within 50 ms and the whole 128-map view within 100 ms (256 within 300 ms).
Each view is the heaviest of its size, one independent-component map per sensor, with 8 maps on screen asked for first; the median is over 5 views, each with an empty layout cache, after one warm-up view.
Measured after the review round (the runner in CI run 45718762963 on
03998a1):ubuntu-latest), gate step aloneubuntu-latest), gate step aloneBefore the round, the same views measured 36.0 ms (M4, Node, 128) and 47.3 ms (M4, Chromium, 128); the runner's 102.5 ms was measured inside the parallel suite.
What changed:
In Chromium the worker's own time is now the whole view's to within 0.3 ms (33.8 of 33.9 ms at 128), so messaging and copying no longer cost anything measurable.
Sizes, from Vite 7.3.3 (Astro's) building the client as an entry: the worker is 5.2 KB gzipped (12.5 KB minified) against 12 KB.
The main thread is 5.5 KB gzipped against 30 KB, counting the shared chunk; the fallback chunk for a browser without workers (4.7 KB) is imported only dynamically and is listed, not counted.
Mutation testing
Each mutation edits the source and runs the field parity, rules, layout parity and solver suites: 42 mutations, 0 survivors.
The table gives the failing tests per suite.
<=to<>=for>The checks added in the review round, by the same method (worker and colormap suites, and the size script itself):
messageerrorThe 42 core mutations above were run again after the round: all still killed.
Deviations
sensor-field.mdsay so:1e-6 * range + 1e-12 * magnitude;head_outside_gridandinterpolation_failed.views/montagesis not copied yet (ADR 0035 decision 2 copies it with the montages).So
sensorLayouttakes the montage center as an injectedmontageCenterand throws when it is missing.The tests read each template center from the vector's own expected center (ALS to RAS).
For those six cases the center check is therefore not independent; the frame rules, the rotation and the projection still are.
The cases are
positions_template,positions_template_midline,template_montage,template_full_1005,template_midline_9andtemplate_coronal_9.sensor-names.tsis not in the plan's file list.The layout's scalp-row rule needs the name rules, which W2b's
sensor-labels.tsshould import rather than repeat.r2 * (ln(r2) / 2 − 1)with no square root and nohypot.It differs from the reference in the last bits; the worst cell is 2.1e-6 of the bound.
astro buildit also runs;dist/is measured from the first page that imports it.The perf gate runs the in-thread worker path in Node, because Node has no Web Worker; the real worker is timed by the e2e spec, which, like every e2e spec here, runs locally only.
The gate is skipped inside the parallel
bun run test, where timings would measure the other test files, and runs in a CI step of its own.Float64Array, not the plan's Float32: the narrower type rounded near-flat maps onto one value (the review's finding), and transferring the algorithm's own array costs no copy at all.Contour lines are unjoined segments, traced in the worker for the maps on screen only.
topo.tsis untouched; W3 moves the viewer.What W3 needs
scripts/copy-quality-views-vocabulary.mjsandtest/quality-views-vocabulary-drift.test.tstoviews/montages/*.json, PROVENANCE.json included: it carries the montages' sources and licenses, and it is not a montage (sensorLayoutalready refuses the name).montageCenterfrom the files tosensorLayout.montageCentersFromintest/quality-views-vectors.tswith the files, so the six template center checks become independent.prepareSensorField/drawSensorFields(or the worker) andsensorLayout, and delete the TPS code,projectPositionsandrenderTopomap.viridisColor/VIRIDIS_CSSforcolormap.ts'sSEQUENTIAL_STOPSandcolorAt, whichtest/quality-views-colormap.test.tspins to the same colors. Updateieeg-spatial/live-activity.ts.sensorLayoutthrowsMontageCenterUnavailablewhen no montage center is given; W3 must catch it by type and leave the map undrawn with its reason, never end the view.COLOR_MAPS_NOTICE(W4, W8).worker-client.tsmakes the CI size step measuredist/as well.A note for neuroschema (spec level)
A single sensor far behind the head, or far to its left, is interpolated (EEGLAB's square has no absolute value) and stretches the grid until almost no cell lies inside the head.
On the 64-sensor cap of the vectors with one sensor added at theta 180 or −90: radius 10 leaves 611 of 3,409 cells inside, 100 leaves 56, and from 200 (300 in the review's probe) a single cell, so the map is drawn as one cell rather than refused.
Farther out the grid misses the head entirely and the whole map is refused with
head_outside_grid(the vectors'far_sensor: one sensor at radius 1e10, theta −135).One bad position thus wrecks the map; a sensor far in front or to the right is simply not interpolated.
This follows the specification as written, so the site keeps it; the coordinator is filing it with neuroschema.
Testing
bun run typecheck: 0 errors, 0 warnings.bun run lint: clean.Targeted Vitest, the quality-view files: 283 passed, 4 skipped (the perf gate without
QUALITY_VIEWS_PERF=gate, and the vocabulary drift's nemar-cli checks with no local nemar-cli checkout).Full
bun run test: 6,994 passed, 52 skipped.bun run test:quality-views-perfpasses on this machine and on the CI runner (its own step in run 45718762963): 128 maps in 58.5 ms, 256 in 180.2 ms, first maps 23.5 and 39.3 ms.bunx astro build(4 s), thenbun scripts/check-quality-views-size.mjs --require-buildpasses.bun run test:e2e e2e/quality-views-perf.spec.tspasses, 2/2, in local Chromium.Mutation tables above.
CI run 45718762963 on
03998a1was also red on two of the new stub-transport tests: the runner's Node has no globalErrorEvent. Fixed in7862d85(the stub raises anEventwith the message). CI run 45719315333 on7862d85fails only the 6 expected drift tests; its budget step measured 20.5 / 63.5 ms (128) and 34.8 / 179.9 ms (256), and the size step 5.2 KB and 5.5 KB.Expected red in CI, as in W1: the vocabulary and pipeline drift tests compare with nemar-cli
dev, which does not carry neuroschema 0.6.0 until epic nemarOrg/nemar-cli#2324 merges there.The budget steps run regardless (
!cancelled()) and do not depend on nemar-cli.Refs #588, nemarOrg/nemar-cli#2324