Repository navigation
Phase 17: unify the lrate default and fix raw-backend device auto-selection (#354) - #355
Merged
neuromechanist merged 11 commits intoSep 24, 2026
Conversation
AMICA.fit restated max_iter/lrate/do_mean/do_sphere/do_newton, and its lrate (0.05, runamica15.m's) differed from every backend's 0.1. It now reads them from the selected backend's signatures, so AMICA and AMICAICA fits without lrate run at 0.1. Tests for torch and MLX: resolved defaults, a default wrapper fit equals the default backend fit, and one set of constructor defaults across the backends.
AMICATorchNG(n_channels) with default arguments raised ValueError on Apple Silicon: device=None picked MPS, which has no float64. The constructor now uses the CPU for that case and logs a warning; the wrapper and AMICA.load pass device through and drop their copy. An explicit device='mps' at float64 still raises. Torch-only (MLX has no device choice). Tested on MPS: raw construction and fit, float32 auto, explicit MPS, load with device=None.
No pamica/data directory exists. Built with uv build: the wheel's file list is unchanged, it imports from a clean venv, and numpy_impl/params.json is inside.
Add a defaults table to the differences guide: pamica against the compiled amica15 binary and EEGLAB's runamica15.m, why pamica follows the binary, and how to reproduce an EEGLAB run. Update the pages that stated the wrapper's lrate or the raw backend's MPS raise. mkdocs build --strict passes.
The wrapper lrate change joins the 'Default fits differ from 0.3.3' warning; entries for the backend device fallback and the package-data cleanup.
params.json set do_newton on and max_iter 2000, the only shared settings where NumPy differed from AMICATorchNG; it now sets them off and 100, as does the constructor's max_iter fallback (reached by the CLI). Fits shorter than newt_start are byte-identical. New test_default_settings.py holds NumPy and MLX to every shared AMICATorchNG default (the MLX check moves there from test_wrapper_backends.py).
The comment said torch stops on nan_ll at iteration 3; both backends stop on nan_params with iteration 2 in all 16 measured runs, at either lrate. The test asserts only a degenerate stop.
Defaults section, validation guide's stops table, NumPy API page, and a changelog entry (NumPy joins the opening warning's defaults line).
The engine wrote the bundled input.param's values (lrate 0.05, Newton on, max_iter 2000, block_size 512, ...). It now takes every setting the binary has a keyword for from AMICATorchNG's signature through FORTRAN_TO_PAMICA_KEY; binary-only knobs are unchanged. The default block is pamica's 8192 samples split over max_threads and capped at the data, since the binary's block_size is per thread and a block longer than the data gives an all-NaN fit (#292). The native oracles now start from the bundled input.param itself (byte-identical files). Tested with the v0.3.3 binary: native, oracle and default-settings tests pass.
AMICANative joins the defaults table's pamica column; the section and the native API page cover the settings it cannot write, the per-thread block size, and running the binary as an input.param configures it. The changelog records the behavior change.
This was referenced Sep 24, 2026
9 tasks done
neuromechanist
merged commit Sep 24, 2026
bb22df6
into
feature/issue-324-epic-mlx-first-class
8 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.
Part of #324, closes #354 on the epic merge.
Summary
Every pamica entry point now shares one set of defaults, plus two related fixes from the documentation audit (#352) and a defaults table.
lratedefault across the wrapper and the backends.AMICA.fitrestated its own fallback defaults, and itslrate(0.05, EEGLAB'srunamica15.mvalue) differed from every backend's (0.1, the compiled amica15 default,amica15_header.f90:68).The wrapper now reads the defaults of
max_iter,lrate,do_mean,do_sphereanddo_newtonfrom the selected backend's signatures (pamica.amica._fit_defaults, viainspect).Only
lratemoves;AMICAICAforwards toAMICA.fitand follows. Explicit and params-file values are unaffected.Behavior change: on the bundled sample (PyTorch, seed 42, 100 iterations) a default wrapper fit ends at LL -3.42768 instead of -3.43566 (old vs new sources: mean Hungarian |corr| 0.983, min 0.931).
AMICA_NumPyjoins the shared set.numpy_impl/params.jsonsetdo_newtonon andmax_iter2000, the only shared settings where it differed; now off and 100, as is the constructor'smax_iterfallback (reached by the CLI).Behavior change for default NumPy fits longer than
newt_start(20); shorter fits are byte-identical (checked at 19 iterations).AMICANativejoins the shared set.native/engine.pywrote the bundledinput.param's values (lrate0.05, Newton on,max_iter2000,block_size512, ...).It now derives every setting the binary has a keyword for from
AMICATorchNG's signature throughpamica.fortran_params.FORTRAN_TO_PAMICA_KEY; binary-only knobs (max_threads,byte_size,writestep,load_*,update_*) are unchanged. Settings without a binary keyword (keep_best,mineig_rel, ...) andNonedefaults (pcadb,seed) are not written.block_size: the binary'sblock_sizeis one thread's share of a block, and it processesn_samples // (max_threads * block_size)blocks (amica15.f90:1215-1227). Writing 8192 with the defaultmax_threads10 gives zero blocks on any recording under 81,920 samples, an all-NaN fit (issue Fortran binary silently produces all-NaN fit when block_size exceeds frames per thread #292): every default native test failed that way on the bundled sample. The default is therefore pamica's 8192-sample block, capped at the data's length, divided bymax_threads(819 on the bundled sample). A givenblock_sizeis written as is.pamica/tests/native_oracle.py,test_schedule_native_oracle.py) relied on the old defaults; they now start from the bundledinput.paramitself, which renders byte-identical parameter files.AMICATorchNGautomatic device choice.AMICATorchNG(n_channels=4)raisedValueErroron every Apple Silicon Mac. The MPS/float64 fallback moved from the wrapper into the backend constructor (alogger.warningfrompamica.torch_impl.core); the wrapper's copy is removed. Explicitdevice="mps"at float64 still raises;device=Noneat float32 still picks MPS. Torch-only: MLX has no device choice of this kind."pamica" = ["data/*"]; the wheel's file list is unchanged, it imports from a clean venv, andparams.jsonis inside.docs/guides/amica-differences.mdgains Default settings (row 17 links it): pamica against the compiled binary andrunamica15.m(sccn/amica 509c8be) with source line numbers, why pamica follows the binary and its exceptions, and how to reproduce an EEGLAB run withAMICA.from_params_fileor withAMICANativefed the file's settings. API pages, guides, README and the changelog are updated; NumPy andAMICANativejoin the opening "Default fits differ" warning.Tests
pamica/tests/test_default_settings.py: NumPy (through a default construction and its ownparams.jsonloader), MLX (signatures) andAMICANative(itsinput.parambuilt without a binary and read back throughread_params_file) hold every setting they share withAMICATorchNGto its default; every writable native setting is written; the native block is pamica's block split over the threads, and a givenblock_sizeis kept.test_wrapper_backends.py: the wrapper resolves each backend's defaults; a default wrapper fit is the default backend fit, bit for bit on torch and MLX; an explicitlratewins.mne_tests/test_mne_backends.py: anAMICAICAfit withoutlrateruns at the backend default; the stale degenerate-fit comment (nan_llat iteration 3) now gives the measured stop (nan_params,iteration2, 16/16 runs on both backends at eitherlrate).torch_tests/test_amica_ng_wrapper.py: raw default construction and fit on MPS resolve to CPU with one warning; float32 auto keeps MPS; explicit MPS at float64 raises;AMICA.loadwithdevice=Noneuses the backend's choice. All ran and passed on the macOS 26 CI job.test_pamica.py::test_amica_initializationexpected NumPy's oldmax_iter;test_native_engine.py::test_native_engine_degenerate_fit_raises_clearlygot its NaN weights from the zero-block case at the oldblock_size512, so it pinsblock_size=512with that reason. No test relied on the wrapper's 0.05; two torch-vs-MLX docstring figures were re-measured.benchmarks/,examples/,validate_implementations.py: their wrapper and NumPy fits passsample_params.json's settings explicitly; the harness's Fortran run writes the bundledinput.param, not the engine's defaults.benchmarks/reproduce_table1.pyis left to Phase 15 (Re-measure parity and sweep docs for epic #324 #351).test_sample_data_numpy_vs_fortran, which setsdo_newton,newt_startandmax_iterexplicitly, so they do not depend on the old NumPy defaults.Gates
uv run ruff check .,uv run ruff format --check .uv run ty check .(also on an env without mlx/mne, as CI runs it)typos,uv run mkdocs build --strictAMICA_RUN_FORTRAN=1,PAMICA_NATIVE_BINARY): 356 passeduv run pytest -q(full suite, MLX and MNE installed): 1974 passed, 40 skipped (opt-in Fortran oracles and native-binary tests), 3 xfailedFollow-ups found, not fixed here
AMICANative(threads=...)setsOMP_NUM_THREADS, but the binary callsomp_set_num_threads(max_threads)frominput.param(amica15.f90:95-100), so it always runsmax_threadsthreads (10 by default);threads=2has no effect.block_sizeon both sides" for bit-for-bit comparisons compares different quantities: the binary's is per thread, pamica's per block.block_sizepassed toAMICANativecan still hit the Fortran binary silently produces all-NaN fit when block_size exceeds frames per thread #292 zero-block case; the engine's non-finite-weights check reports it as degenerate.