Skip to content

Various testing speedups and tweaks#14072

Merged
larsoner merged 3 commits into
mne-tools:mainfrom
larsoner:speedup
Jul 19, 2026
Merged

Various testing speedups and tweaks#14072
larsoner merged 3 commits into
mne-tools:mainfrom
larsoner:speedup

Conversation

@larsoner

Copy link
Copy Markdown
Member

Speed up tests:

  1. Mark a few more tests ultraslow to speed up main test runs
  2. Use fixtures and caching to avoid re-reading some files over and over (read once and copy instead, similar to how we already do for some evoked/epochs IIRC)
  3. Cache 3D sensor geometry so that it doesn't need to be recomputed (we have finite coil geoms)

Part of #14063. Investigated speedups and drafted changes using Claude Fable 5 and Opus 4.8, then I revised (and understand + vouch for all changes).

@drammock drammock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Couple comments, I only had time for a quick skim. This might be a good one for @nordme , @CarinaFo , @scott-huberty , and @tsbinns to look at, since it deals with a topic of interest (speeding up tests)

onset += raw.first_time
assert_array_equal(annot_nan.onset, onset)
assert_array_equal(annot_nan.duration, np.array([2]))
assert_allclose(annot_nan.onset, onset, rtol=1e-3)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why the change from equal to all close here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sample dataset uses non integer sampling rate. Original test resampled to 100 Hz but that makes it take much longer, and the test shows the same thing conceptually without it

Comment thread mne/utils/numerics.py
if c.nnz > 0:
out += pre + (f" sparse matrix a and b differ on {c.nnz} elements")
elif pd and isinstance(a, pd.DataFrame):
elif (pd := sys.modules.get("pandas")) is not None and isinstance(a, pd.DataFrame):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it make more sense to do this within check_pandad_installed and leave this line the way it was?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The check will actually attempt an import, which is what we're trying to avoid (takes time if you haven't imported it yet). Don't need to check to see if the data are a data frame here if you couldn't possibly have one yet (i.e. if you haven't imported pandas yourself yet)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

... And I don't think a sys.modules check inside check_pandas_installed makes sense, it would need to be a new check_pandas_imported or add a new kwarg like imported_only or something to the existing function to make it kind of a misnomer

Comment thread mne/viz/_3d.py Outdated
@larsoner
larsoner merged commit 3e35909 into mne-tools:main Jul 19, 2026
29 checks passed
@larsoner
larsoner deleted the speedup branch July 19, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants