Skip to content

Phase 2: Pyodide harness, CI, and the ICA benchmark gate #375

Open

Description

@neuromechanist

Phase 2 of #324.
Base: epic/324-pyodide-browser.
Depends on: phase 1.
Blocks: phase 3 and phase 5.
Parallel with: phase 4.

Why

This phase is the epic's go/no-go gate.
Two commitments in #324 rest on numbers nobody has measured yet:
that picard should be the browser default ICA, and that routing matmuls through scipy.linalg.blas under Emscripten is worth a code change.
Measure both before building on either.

It also converts phase 1's static resolution check into a live one: does micropip.install("eegprep") actually work, and does a real pipeline run.

Scope

Build the harness:

  • tools/pyodide/ runner that boots Pyodide under node, micropip-installs the wheel built from the working tree, and executes a Python script inside it.
    Keep it out of the installed package; tools/ is not shipped.

Add a CI job to .github/workflows/test.yml:

  • build the wheel, install it under Pyodide, import eegprep, and run a short continuous-data pipeline on sample_data.
  • The job must fail on a resolution error, not skip.

Benchmark and publish:

  • ICA wall clock at 64 channels x 60 s x 250 Hz, for runica and eeg_picard, native and Pyodide, reporting iterations to convergence as well as seconds.
    Iteration count is the number that actually justifies picard on a single WebAssembly thread; wall clock alone hides it.
  • A matmul microbenchmark at the shapes runica's inner loop actually uses, comparing numpy @ against scipy.linalg.blas dgemm/sgemm, native and Pyodide.
    Take the shapes from runica.py:684 and :692, which are (ncomps, ncomps) @ (ncomps, block) and (ncomps, ncomps) @ (ncomps, ncomps).
  • Commit the results as a Markdown table under docs/source/ and publish the raw output as a CI artifact.

What the numbers decide

Record the answers on #324, because later phases read them:

  1. Does picard's iteration advantage survive Pyodide, and by how much?
    Confirms or overturns the recorded decision to default to picard in the browser.
  2. Is the scipy BLAS path materially faster than numpy @ at runica's shapes under Emscripten?
    If the gap is small, phase 3 shrinks to a documentation note and should say so rather than ship a helper nobody needs.

Known complication the benchmark must surface

eeg_picard.py delegates to the third-party picard package, and picard's hot matmuls live inside it, not in eegprep: picard/_core_picard.py:84, :163, :206, :207, and picard/_tools.py:70, :71, :84, :86.
eegprep's own file has only two cheap post-processing matmuls at eeg_picard.py:63 and :65.
So no eegprep-side BLAS helper can speed up picard's inner loop.
Benchmark picard as it actually is, and report that constraint explicitly so phase 3 scopes honestly.

Non-goals

No BLAS helper implementation; that is phase 3 and only if the numbers justify it.
No ICLabel work.
No attempt to patch or vendor python-picard.

Acceptance criteria

  • tools/pyodide/ harness runs locally with one documented command.
  • CI job installs the built wheel under Pyodide via micropip and fails loudly on resolution errors.
  • CI runs an importable smoke pipeline on sample_data under Pyodide.
  • Benchmark covers runica and picard, native and Pyodide, reporting both seconds and iterations to convergence, at 64 ch x 60 s x 250 Hz.
  • Matmul microbenchmark covers numpy @ versus scipy.linalg.blas at runica's real inner-loop shapes.
  • Results committed as a Markdown table under docs/source/ and published as a CI artifact.
  • Both decisions above answered in a comment on Epic: eegprep in the browser (Pyodide) with a small ONNX ICLabel #324.
  • Pyodide version pinned explicitly, with the pin and the reason recorded.
  • Pre-commit, ruff, ruff format, ty clean; existing suite unaffected.

/goal prompt

/goal Prove what eegprep actually does under Pyodide and produce the numbers that decide phases 3 and 5.

Source of truth: the built wheel from this working tree, sample_data, runica.py:684 and :692 for inner-loop shapes, and the picard call sites listed on the issue. Read AGENTS.md first.

Constraints: tools/ is developer tooling and must not be installed as part of the package; do not implement a BLAS helper in this phase; do not patch or vendor python-picard; pin the Pyodide version explicitly.

Finish line: the CI job installs the wheel under Pyodide and runs a smoke pipeline; the benchmark table is committed under docs/source/ with seconds and iteration counts for runica and picard, native and Pyodide; the matmul microbenchmark is committed; and you have posted a comment on #324 answering, with numbers, whether picard keeps its advantage in the browser and whether the scipy BLAS path is worth a code change.

If the numbers contradict either recorded decision, say so plainly in the comment rather than working around them. Report any review finding you chose not to fix, with the reason.

Activity

  1. added
    phase
    on Sep 17, 2026
  2. neuromechanist commented on Sep 17, 2026

    @neuromechanist
    MemberAuthor

    🤖 Added scope to this phase from a blocker phase 1 uncovered.

    docopt is sdist-only and blocks micropip.install("eegprep").

    pybids -> num2words -> docopt, and docopt 0.6.2 publishes no wheel at all on PyPI, only docopt-0.6.2.tar.gz. Verified against the PyPI JSON API. micropip installs wheels and does not build sdists, so the base requirement set still cannot resolve in the browser even after phase 1 removed oct2py, psutil, and pyedflib.

    num2words declares docopt unconditionally although only its own command line entry point uses it, so nothing in eegprep's import path ever touches it.

    Decision: pre-install a built docopt wheel from this phase's harness. docopt is pure Python, so building a py3-none-any wheel from the sdist once and installing it ahead of eegprep is the cheapest fix. It keeps pybids in the base install, which matters because NEMAR datasets are BIDS and the assistant needs to load them.

    Rejected alternatives, recorded so they are not relitigated: moving pybids to a [bids] extra would cost BIDS loading in the browser, and fixing num2words upstream is the correct long-term answer but would gate this epic on an external maintainer. Worth opening upstream separately.

    Add to this phase's scope and acceptance criteria:

    • Harness builds or vendors a pure-Python docopt wheel and installs it before eegprep.
    • micropip.install("eegprep") succeeds end to end under the harness. This is the real version of phase 1's gate, which Phase 1: Move oct2py, psutil, and pyedflib out of the base install #374's static check could only approximate.
    • tools/check_pyodide_base_resolution.py has its docopt entry moved out of KNOWN_GAPS once the harness handles it, so the script stops passing over a live blocker.
    • Record whether any other sdist-only package appears once the full closure actually resolves.

    Note for the phase agent: #374's check script currently reports docopt as a non-blocking known gap and still exits 0. Do not treat a green run of that script as evidence the browser install works.

  3. neuromechanist commented on Sep 17, 2026

    @neuromechanist
    MemberAuthor

    🤖 # Research

    The live browser gate is missing: .github/workflows/test.yml only runs Python checks for master/develop, while tools/check_pyodide_base_resolution.py treats docopt==0.6.2 as non-blocking even though its sdist cannot be installed by micropip. runica reports its effective training iterations through the returned learning-rate history, and the installed python-picard==0.8.2 API exposes return_n_iter=True; neither production path needs modification.

    Relevant code

    • tools/check_pyodide_base_resolution.py#L38-L49 - current docopt gap
    • .github/workflows/test.yml#L1-L15 - current trigger scope
    • src/eegprep/functions/sigprocfunc/runica.py#L252-L258 - block heuristic
    • src/eegprep/functions/sigprocfunc/runica.py#L1290-L1371 - iteration history
    • src/eegprep/functions/popfunc/eeg_picard.py#L48-L66 - exact wrapper configuration

    Proposed Fix

    Add a developer-only Node/Pyodide 0.29.5 runner that serves staged local wheels and sample files over localhost, builds a hash-checked pure-Python docopt wheel from the locked sdist before installing the working-tree EEGPrep wheel, and propagates every load/install/script failure. Add smoke and deterministic benchmark scripts, a CI job triggered for both the epic branch and develop, raw-output artifacts, and a committed results table. Keep the Picard benchmark on its underlying picard(..., return_n_iter=True) API with the wrapper parameters, and leave BLAS production work to phase 3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    phase

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions