Skip to content

[AMICA] Write min_dll and min_grad_norm as real numbers - #637

Merged
suraj-ranganath merged 2 commits into
developfrom
cursor/amica-real-stop-thresholds-b7ae
Nov 18, 2026
Merged

suraj-ranganath merged 2 commits into
developfrom
cursor/amica-real-stop-thresholds-b7ae

Conversation

@suraj-ranganath

@suraj-ranganath suraj-ranganath commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

MATLAB fprintf with %d falls back to %e when the value is not an integer, so runamica15.m writes min_dll and min_grad_norm as 1.000000e-09 and 1.000000e-07. eegprep formatted those defaults as integers and wrote 0. Scientific notation restores that output, and a regression test reads the written fields back as 1e-9 and 1e-7.

Fixes #619
Supersedes #620

Open in Web Open in Cursor 

The parameter writer sent both stop thresholds through the integer
formatter, so the amica15 binary read 0 instead of 1e-9 and 1e-7.

Co-authored-by: Suraj Ranganath <[email protected]>

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Code review skipped — your organization has no extra usage available to pay for this review.

If your organization's extra usage balance is empty, an organization admin can add extra usage credits at claude.ai/admin-settings/usage. If its monthly spend limit was reached, an admin can raise it on the same page. If neither applies, contact Anthropic support.

Once extra usage is available, someone with write access to this repository can comment @claude review on this pull request to trigger a review.

The written min_dll and min_grad_norm fields must parse as 1e-9 and 1e-7.

Co-authored-by: Suraj Ranganath <[email protected]>
@suraj-ranganath
suraj-ranganath marked this pull request as draft November 18, 2026 09:44
@suraj-ranganath
suraj-ranganath marked this pull request as ready for review November 18, 2026 09:44
@claude

claude Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @suraj-ranganath's task in 37s —— View job


Code review

  • Overall assessment: Looks good. The fix is correct and stays small. Moving min_dll and min_grad_norm from _INT_PARAMS to _SCI_PARAMS makes _write_param_file write 1.000000e-09 and 1.000000e-07. That matches what runamica15.m writes, since MATLAB's %d switches to %e for values that are not integers. Before this PR, int(val) truncated both values to 0. That only mattered when a user set use_min_dll=1 or use_grad_norm=1, because both default to 0.
  • Highest-risk area: _write_param_file formatting in src/eegprep/functions/sigprocfunc/runamica.py:309-311.
  • Merge recommendation: Safe to merge.

Blocking

None.

Important

None.

Nits

  • tests/test_runamica.py:52-62: the second test repeats the first. test_default_stop_thresholds_read_back_under_f15_12 writes the same file and checks the same values as test_write_param_file_keeps_stop_thresholds. Its only addition is a Python imitation of a fixed-width read (f'{field:<15}'[:15]). That imitation is not AMICA's Fortran parser, so it adds no regression protection beyond the first test. Its != 0 checks are also implied by the == 1e-9 and == 1e-7 checks above them. AGENTS.md §Testing says to "only add a test that would catch a real bug". Suggest keeping the first test and dropping the second.
  • tests/test_runamica.py:47,55: the file handle is never closed. open(path).read() leaves the handle open, which raises a ResourceWarning under -W error. Path(path).read_text() avoids this.

Test gaps

None. The first test fails on develop, where both values are written as 0, and passes with this change.

EEGLAB parity notes

  • runamica15.m is not vendored under src/eegprep/eeglab/, so the parity claim rests on MATLAB's documented fprintf('%d', 1e-9) behavior. That gives 1.000000e-09, which is the same string Python's f"{1e-9:e}" produces.
  • This touches the code path that drives the AMICA binary, but it does not change any numerical algorithm. The EEGLAB reference suite does not test AMICA, so I don't think the MATLAB reference run in AGENTS.md is needed here. A maintainer should confirm that.

I checked correctness, EEGLAB parity, the changed-behavior tests and AGENTS.md compliance. I did not run the tests.

Copy link
Copy Markdown
Member Author

The two nits do not need a change before merge.

The first test is the regression #619 asked for: it reads the written fields back and checks they are 1e-9 and 1e-7. The second test adds a 15-character width check on those same strings. Issue #619 left the Fortran field width unverified, and the current {:e} forms (1.000000e-09 and 1.000000e-07) are 12 characters, so both tests agree. The != 0 asserts are already implied by the equality checks. I am leaving the extra test in place.

open(path).read() is a short read of a temp file the test just wrote. pytest in this repo does not run with -W error (addopts is -ra --strict-config --strict-markers), so this does not fail CI.

@suraj-ranganath
suraj-ranganath merged commit d0dea04 into develop Nov 18, 2026
13 checks passed
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.

AMICA parameter file writes min_dll and min_grad_norm as integers (the binary gets 0)

2 participants