Repository navigation
Phase 6: validation harness per backend and end-to-end workflow - #332
Merged
neuromechanist merged 20 commits intoSep 23, 2026
Conversation
validate_implementations.py gains --backend {torch,numpy,mlx}, a comma-separated list, or all. Each backend runs the bundled sample with the harness's canonical params (NumPy through its own key map, MLX through AMICAMLXNG) against one shared reference run; an explicit --backend adds a parity summary table with runtime. The default torch-only run prints the same report as before (diffed).
Tested: dispatch and argument-parsing tests (no binary), and the AMICA_RUN_FORTRAN-gated per-backend parity test against the v0.3.3 native binary (3 passed).
With Phase 4 merged, the torch and MLX runs share one AMICA(backend=...) path, so the MLX row exercises the wrapper a user calls. Numbers unchanged (same summary table as the direct AMICAMLXNG run). Tested: harness dispatch tests (29 passed); all-backend run against the v0.3.3 native binary.
35 British spellings in comments, docstrings and Markdown (behaviour, colour, neighbour, cancelled, licence, optimiser, ...). Proper nouns (Centre de Recherche...) and 'analogue' left as is; no identifiers touched. Tested: ruff, typos.
Seven torch_impl/core.py:<line> citations outside the MLX module pointed at drifted lines; they now name the method (or are dropped where the sentence already names it). Also replaces a stale pamica.py:802-813 citation (a file renamed in #34) in AMICATorchNG._newton_direction. Fortran line citations unchanged. Tested: ruff.
getting-started gains a complete Apple Silicon (MLX) section (install, fit/transform/save/load, params file, AMICAICA, precision). The validation guide documents running the harness per backend and records the per-backend parity rows with their expected bars. The differences page records do_sphere=False (#328) and NumPy refit warm-start (#312), both verified against the code. AGENTS.md, changelog and the native-backend and testing pages follow. Tested: mkdocs build --strict (scratch env); anchors checked in the built site.
An audit of the non-slow suite found 63 tests (13 files) writing ./output via AMICA_NumPy's default outdir; the slow CLI, end-to-end and pdf-family tests wrote test_output, _ng_e2e_tmp and scratch_amica_parity into the repo. A session-scoped autouse fixture now runs each session (per xdist worker) from a temporary directory, the harness resolves its bundled inputs from its own location, and the slow tests write under tmp_path. Stale .gitignore entries removed. Tested: full non-slow suite (1335 passed, nothing written to the repo); coverage reports still land in the repo root with and without xdist.
New mne_tests/test_end_to_end_workflow.py mirrors our own pipeline on the bundled EEG: average reference, AMICAICA with pcakeep = n_channels - 1 on each backend, get_sources vs transform, a single-component exclusion (exact back-projection, residual kept, rank drops by one), EEGLAB export reloaded by loadmodout with the padded sphere, AMICA save/load, an input.param-driven fit, and torch vs MLX Hungarian-matched sources >= 0.999. Not marked slow (about 5 s); MLX tests skip without MLX or an Apple GPU. Tested: 12 passed locally (torch and MLX); measured tolerances recorded in the module.
AMICA_NumPy.get_sensor_mixing_matrix returned pinv(sphere) @ stored A without the transpose the torch and MLX backends apply (the stored W is the unmixing transposed, issue #24), so its columns were rows of the true mixing matrix: about 10% off the torch maps after five iterations and no inverse of get_weights() @ sphere. New cross-backend test pins torch/NumPy agreement (4.6e-12 full rank, 9.5e-11 at pcakeep=20), MLX agreement at float32 tolerance, and the identity on every backend. Tested: new test fails without the fix (4 NumPy cases) and passes with it (10 passed); backend-guard and share-comps suites green.
pytorch_debug_test/out.txt and pytorch_output_test/out.txt were run logs committed in August 2025 by the long-removed basic PyTorch backend; nothing reads them. The only reference, a typos exclusion for the first directory, goes with them. Tested: typos.
States why the rows name an explicit release binary instead of the resolver default (its cached 'latest' is never refreshed) and how to fetch it. Tested: mkdocs build --strict.
AMICA_NumPy defaulted outdir to ./output, so every fit wrote out.txt at construction, writestep checkpoints, history and its final results into the caller's working directory. The default is now outdir=None, which writes nothing (as torch and MLX never do unless asked); an explicit outdir (keyword, params file, or the CLI's --outdir, whose own default stays output) writes exactly as before. Behavior change recorded in the changelog and the NumPy API page; the conftest chdir stays as defense in depth. Tested: new test_numpy_outdir.py (default leaves the working directory empty with every write path on; explicit and params-file outdir write as before; fails on the old code) and a CLI test that a run without --outdir still writes ./output; NumPy suites (107 passed).
plot_components drew stored-A columns (rows of the true mixing matrix) as mixing vectors, and it and plot_pdf_fits built activations as stored W times raw data (no transpose, sphere or mean); plot_model_comparison skipped the sphere. One helper, _component_maps_and_sources, now computes exactly what get_sensor_mixing_matrix and transform return, and all three plots use it. load_results reads a rank-reduced fit's zero-padded sphere instead of raising. Tested: new test_numpy_viz.py compares the helper and the plotted lines/histograms with the live accessors, full rank and pcakeep=20 (10 passed; 8 fail on the old code).
Pins the literal default run (no --backend: one validation_report.txt, no parity_summary.md, exit 0), renders format_parity_summary with populated rows from two real runs (torch as the stand-in reference, NumPy through compare_results) and checks every numeric column, and runs the no-MLX exit over both 'torch,mlx' and 'all'. Tested: 32 passed, 3 skipped (the AMICA_RUN_FORTRAN-gated parity test).
unlabelled and relabelled, missed by the first sweep's word-boundary match. Test names containing 'honour' (identifiers) are left as is. Tested: typos, ruff.
The MLX section duplicated the backends guide's end-to-end and precision sections; it is now install, AMICA(backend="mlx") fit/transform, an AMICAICA one-liner and the float32 note, linking to the guide for the full workflow. The install heading no longer uses a bare GPU abbreviation. Tested: mkdocs build --strict; linked anchors checked.
progress_summary.md's harness line now matches AGENTS.md (every backend, #315), and the testing guide explains the conftest session chdir and how a test resolves repository paths. Tested: mkdocs build --strict.
default_reference_binary's docstring is now the single full description of the reference-binary resolution order; the --native-engine help summarizes it and points there. The native-backend page runs the harness with uv run. Tested: --help renders; harness tests (32 passed).
The NumPy-vs-torch sensor-map gate (1e-9) failed on the macOS arm64 runner at 1.3e-9: the backends start within 1e-13 and EM amplifies the gap about sixfold per iteration, so five iterations was platform-sensitive. Two iterations keep the same gate with a 1e-12 gap while the pre-fix transposed maps still differ by 2.6-3%. Tested locally: module passes.
neuromechanist
merged commit Sep 23, 2026
e38aa11
into
feature/issue-324-epic-mlx-first-class
9 checks passed
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.
Summary
validate_implementations.py --backend {torch,numpy,mlx}(or a comma-separated list, orall) compares each backend against one shared Fortran reference run with the same canonical settings; the default staystorchand prints the same report as before (diffed).NumPy receives the settings through its own
_CANONICAL_TO_NUMPY_KEYtable, PyTorch and MLX throughAMICA(backend=...); an explicit--backendalso prints and saves a per-backend summary with runtimes (parity_summary.md), and--backend mlxwithout MLX exits with status 2 and the install hint.The harness now resolves its bundled inputs from its own location, so it runs from any working directory.
New
pamica/tests/mne_tests/test_end_to_end_workflow.pymirrors our own pipeline on the bundled EEG for torch and MLX: average reference,AMICAICAwithpcakeep = n_channels - 1,get_sourcesvstransform, a one-component exclusion (exact back-projection, residual kept, rank drops by one), EEGLAB export reloaded byloadmodoutwith the padded sphere,AMICA.save/load, aninput.param-driven fit, and torch vs MLX Hungarian-matched sources >= 0.999 (measured 0.999999999). Not marked slow (about 2 to 5 s).Fix:
AMICA_NumPy.get_sensor_mixing_matrixwas missing the transpose the other two backends apply, so its columns were rows of the true mixing matrix (about 10% off the torch maps after five iterations, and not an inverse ofget_weights() @ sphere); a new cross-backend test pins the agreement (4.6e-12 full rank, 9.5e-11 atpcakeep=20).Behavior change (legacy backend):
AMICA_NumPynow writes files only when given anoutdir(defaultNone, like torch and MLX); an explicitoutdir(keyword, params file, or the CLI's--outdir, whose default staysoutput) writes exactly as before.Fix: the legacy
pamica.numpy_impl.vizhelpers had the same orientation slip (stored-A columns drawn as maps; activations from raw data with no transpose, sphere or mean); they now plot whatget_sensor_mixing_matrixandtransformreturn, andload_resultsreads a rank-reduced fit's padded sphere.Docs: a short Apple Silicon (MLX) route in
docs/getting-started.mdthat links to the backends guide's full workflow; per-backend harness usage and parity rows indocs/guides/validation.md;docs/guides/amica-differences.mdrecordsdo_sphere=False(reference scales channels, pamica does not; #328) and NumPy refit warm-start (related to #312); AGENTS.md, changelog, native-backend and testing pages updated.Cleanups: 35 British spellings fixed in 18 files; seven
torch_impl/core.py:<line>citations (plus a stalepamica.py:802-813) converted to symbol references; the suite no longer writes into the repository (a session-scopedconftest.pyfixture runs each session from a temporary directory, and the slow tests write undertmp_path); stale 2025 debug logs at the repository root removed.Part of epic #324; resolves #315 (closes when the epic merges to dev).
Parity rows (harness defaults: seed 42,
max_iter100,sample_params.json; Apple M4 Pro, 2026-09-22; reference: v0.3.3 nativeamica15-macos-arm64)AMICA)AMICA_NumPy)AMICA(backend="mlx"))Test plan
uv run ruff check --fix . && uv run ruff format .,uv run ty check,typos: cleanuv run pytest pamica/tests -q --no-cov -n 4 -m "not slow": 1374 passed, 17 skipped, 1 xfailed; the session working directory is empty afterwards (nothing in the suite writes to its working directory any more)validate_implementations.py --backend allagainst the v0.3.3 native binary: all three backends meet their bar (table above); default run output diffed identical to the pre-change runAMICA_RUN_FORTRAN=1per-backend parity test (test_backend_meets_its_parity_bar_against_fortran): 3 passedtest_ng_backendend-to-end x2,test_ng_pdf_familiesx5,test_sample_data_cli,test_sample_data_scikit): 7 passed, 2 xfailed as beforetest_numpy_outdir.py(default writes nothing, explicit and params-fileoutdirwrite as before; fails on the old code) and a CLI test that a run without--outdirstill writes./outputtest_numpy_viz.pycompares the plotting helpers' maps, histograms and reconstructions with the live accessors, full rank andpcakeep=20(10 passed; 8 fail on the old code)format_parity_summaryrendered from real runs, no-MLX exit overtorch,mlxandallmkdocs build --strict(scratch docs environment); new anchors checked in the built site