Skip to content

test: browser notebook kernel imports this checkout's quantem.widget - #250

Closed
bobleesj wants to merge 162 commits into
electronmicroscopy:mainfrom
bobleesj:sep/browser-kernel-import
Closed

bobleesj wants to merge 162 commits into
electronmicroscopy:mainfrom
bobleesj:sep/browser-kernel-import

Conversation

@bobleesj

Copy link
Copy Markdown
Collaborator

Three browser tests failed on main with a freshly built bundle:
test_show2d_rgb.py[webgpu-gray] and [webgpu-color] (__cpuPixels 4 and 8) and
test_show3d_rgb_live_notebook_draws_on_webgpu (residency never ready).

Cause: the test harness, not the widget code. The JupyterLab kernel starts in the notebook root, not the
repository. With the documented PYTHONPATH=src, the relative entry points nowhere there, so the kernel
imported another quantem.widget on the machine (an editable install whose bundles predate true color on
WebGPU) and drew color panels with the old CPU pack. The stale-bundle guard from #4 checked only the pytest
process, which did import this checkout.

Fix (tests/browser/conftest.py): the JupyterLab fixture makes PYTHONPATH absolute for the server and
its kernels, and fails when a kernel started in the notebook root would import quantem.widget from outside this
checkout's src/.

Checks (headed Chrome, Apple GPU: adapter apple metal-3, subgroup 32)

  • With the relative PYTHONPATH=src that failed before: the three tests pass. Reverting the fixture change
    reproduces __cpuPixels = 4.
  • test_show2d_rgb.py, test_show3d_rgb.py, test_webgpu_cpu_parity.py: 22 passed, 1 failed:
    test_export_pixels_match_with_and_without_webgpu[show3d_panels] ([0, 0, 0, 13, 13]), an intermittent
    failure that also shows up on untouched main.
  • pytest -q: 768 passed, 144 skipped. npx vitest run: 398 passed. Public-repository test passes.

bobleesj and others added 30 commits October 21, 2026 09:15
Every widget slider comes from js/shared/Slider, which turns off MUI's
150 ms thumb, track and label easing. Widgets that own their drag never
told MUI a drag was active, so the thumb trailed the cursor (~37 px on
the Show3D frame slider). Slider.test.ts fails on any direct MUI Slider
import; ShowPDF is outside this pass.
- The grid shader draws non-integer enlargements (exact integer texel pick)
  and Smooth (bilinear on values); the Canvas2D fallback is gone for them.
- One GPU draw per slider move; the retained 2D copy happens on release.
- The settled frame uses the same shader when its range matches, so a
  settle no longer swaps in a CPU frame with different edge texels.
- Histogram drags preview on the GPU and commit state on release.
- Playback goes to 120 fps; GIF export stays at its 50 fps ceiling.
A histogram drag recolored every visible canvas pixel on the CPU each tick
even with WebGPU (a 48-panel sheet: ~46 ms a tick, half the moves dropped,
a 155 ms stall). WebGPU now colormaps the dragged window whenever the
preview's source pixels fit GPU_PREVIEW_MAX_SOURCE_PIXELS (12 M); only a
larger source (a single 4096^2 frame) keeps the canvas-pixel path.
Playback advanced one frame per display refresh, so 120 fps on a 60 Hz
screen played at 60. It now advances by elapsed time (up to 8 frames a
refresh): 30/60/90/120 fps measure 30.5/60.1/88.7/120.5 frames a second on
a 60 Hz display. Without Loop the last frame still shows before stopping.
The crosshair was drawn from an effect after React committed the hover,
one display frame behind the pointer, and drawn a second time on every
move. The hover frame now paints it directly (once per move); the effect
repaints only for size, DPR or color changes.
Every durable frame built a new OffscreenCanvas, configured its WebGPU
context and allocated a blit params buffer and bind group; a 48-panel
histogram drag did that 51 times per pointer move. The engine now pools
configured canvases by size (a canvas stays configured across
transferToImageBitmap) and keeps one blit binding per rgba buffer, one
colormap bind group per slot, and one params buffer and bind group per
explicit-range panel. Volume slices of different sizes share the pool
instead of reconfiguring one canvas back and forth.
…n release

- Show3D histogram drags (image and per-panel) and the moving-average
  slider paint from live refs on the GPU and skip the retained 2D copy
  until release; the per-panel histogram and avg_window commit widget
  state once, so the display effect no longer re-averages and colormaps
  on the CPU per move.
- Show3DSlices keyed its volume render effect on a range object rebuilt
  every render, so each playback step redrew the volume at full
  resolution over the live draft and reconfigured the canvas twice.
- LiveNumberSlider moves to shared/Slider for both widgets.
The frame-slider gestures call preventDefault on pointerdown, which also
stops MUI focusing a thumb: after a click or drag focus stayed on the
page (arrows did nothing) or on the loop-start thumb (arrows moved the
loop start). The gesture now focuses the frame thumb. Show3D's gesture
also ended on any element blur its window capture listener saw, so
moving focus between thumbs dropped the click's jump; only the window
losing focus ends it now.
…ut a GPU

With quantem.gpu usable the note said "needs an SSB session", without
it "needs a DirectPtycho session"; the test asserted the first, so CI,
which has no GPU route, failed. Both now name the DirectPtycho session.
… (mode="stream"), Show2D color export

- The console script is quantem-widget (was quantem); show2d and show3d write
  image files, a stack or a folder of images as one lossless Show2D or Show3D
  HTML page (--save-dir, --encoding, --image-bin, --max-mb, --no-link-contrast).
- Show3D thumbnail strip: thumbnails=, thumbnail_columns=1|2|3, or
  mode="stream", which Show3D.stream() opens in. Square thumbnails drawn on
  the GPU from the resident frames; hover shows a frame, click selects it.
- Show2D exports color panels as true color with encoding="full".
- An exported page saved again from its Export menu keeps the offline runtime
  (it opened blank); exported Show2D pages list only exports they can make.
- Docs: CLI reference, agent recipe for turning images into HTML, Show3D
  thumbnails; changelog.
Show3D drew RGB stacks on the CPU canvas while its badge said WebGPU, and
Show2D packed color panels in a JavaScript loop on every page.

- Show3D: RGB frames are WebGPU-resident slots (uploadRgbData, 3 floats per
  pixel) drawn by a direct true-color pass (DIRECT_SLOT_RGB_SHADER) for scrub,
  playback, multi-panel grids with zoom/pan and the moving average. The status
  line reads "true-color display · WebGPU resident"; the JavaScript pack runs
  only without a WebGPU engine.
- Show2D: color panels pack through the colormap engine
  (renderRgbToImageBitmapAsync: WebGPU, or the Canvas2D engine without it) and
  commit together with the grayscale panels.
- The title badge takes the path that drew the frame (drawnBy), so it never
  says WebGPU for CPU pixels.
- Both paths quantize round(clamp(v, 0, 1) * 255), NaN to 0; the WebGPU
  passthrough truncated before. Colormap passes refuse rgb slots.

Browser tests: tests/browser/test_show3d_rgb.py (1 and 2 panels, export and
live notebook, readback == given bytes, 60 WebGPU presents/s and no CPU pack)
and tests/browser/test_show2d_rgb.py (color + gray and color + color, live).
quantem-widget show2d/show3d pages, Show3D thumbnail strip (mode="stream"), true color on WebGPU
- Each gallery panel gets a WebGPU canvas over its 2D canvas. Contrast
  drags, zoom, pan and the settled frame draw the panel's resident slot
  through one shader (renderSlotsDirectToCanvases: one submission, each
  panel with its own range, LUT and view), in the input's animation frame,
  instead of 48 colormap passes into pooled OffscreenCanvases, a queue
  wait, 48 ImageBitmaps and two drawImage per panel.
- The 2D canvas gets the frame once a panel has not changed for 150 ms:
  the current state is drawn again and copied in the same task, before the
  canvas texture is presented. Copy and SVG export flush that copy first.
- Rotated or flipped kernel-less exports, packed uint8 folder frames,
  binned previews with detail tiles, true color and panels whose slot lags
  the data keep the 2D path, which hides the GPU canvas.
- A histogram drag writes auto_contrast and contrast_preset once on
  release; the first move used to write them and re-render the widget.
A display_bin gallery (what Show2D suggests for 48 x 4096^2, over the
browser's message limit) kept the old bitmap path, and once zoomed in
far enough to stream full-resolution detail tiles every visible panel
did: a histogram drag drew about half the moves at ~70 ms. Binned
previews now draw on the panel's WebGPU canvas, and a detail tile is
uploaded to its own slot and drawn over the preview in the same pass,
clipped to the tile, with the same range, LUT and view.
…on WebGPU to 1/100 px, chart the drift and its fitted velocity, sync the result to Python as viewer.drift, and add a drift-corrected panel
…4K stream

- Show3D linked-contrast colorbar showed 0 to 1; it reads the stack range
- thumbnail strip: no seam between cells (cover a fractional 1fr column), no black empty slots, More > Thumbnails brings a closed strip back
- frame counter keeps the live total while frames stream in and the view is parked
- binned HTML export names the original stack and the mean bin in its header
- an empty Show3D.stream shows only its waiting panel until the first frame
- io.download(verbose=False) hides the Hugging Face progress bars
- Show2D scale, denoise, bin, sigma, ROI and FFT controls carry accessible names
- bench_interactivity takes the window position from QUANTEM_WIDGET_WINDOW_POSITION
show2d: gallery panels draw straight into WebGPU canvases
Show2D/Show3D: fixes from a full drive on 2K/4K gold data and a live 4K stream
…vice and on the CPU path recovers a known subpixel drift, sends viewer.drift with the picked frames and nm/s to Python, and adds the drift-corrected panel
…k there is a right click) and passes on the Apple GPU; browser tests say to run on a Mac first, headless
A headed run against a bundle built before a pull or merge loads and draws through the
frontend code it was built from, so it tests old frontend code against new tests.

The chrome fixture now fails every browser test at once, naming what is stale, when a widget
bundle is older than the js/ sources or quantem.widget is imported from outside this checkout.
QUANTEM_WIDGET_ALLOW_STALE_BUNDLE=1 skips the check for an installed-wheel run.
…the stale-bundle check

The browser tier now refuses a quantem.widget imported from outside the checkout. The CUDA and MPS
release gate runs tests/browser/test_showptycho_release.py against the installed candidate wheel on
purpose, so that step sets QUANTEM_WIDGET_ALLOW_STALE_BUNDLE=1.
Browser tests refuse a stale frontend bundle
The JupyterLab kernel starts in the notebook root, so a relative
PYTHONPATH=src resolved to nothing there and the kernel imported another
quantem.widget (an editable install with bundles older than true color on
WebGPU). The stale-bundle guard checked only the pytest process, so the
Show2D and Show3D color tests failed against old frontend code. The
fixture now makes PYTHONPATH absolute for the kernel and fails when the
kernel would import quantem.widget from outside this checkout.
@github-actions

Copy link
Copy Markdown

This PR is 3 commits behind electronmicroscopy/quantem.widget:main.

Fetch that remote and update local main before you branch, or rebase this branch onto it before review.
A warning is enough. The PR can stay open while main moves.

@bobleesj

Copy link
Copy Markdown
Collaborator Author

Opened against the wrong repository by mistake; moved to the fork.

@bobleesj bobleesj closed this Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant