Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use less memory when loading EDF file #10638

Merged
merged 4 commits into from
May 17, 2022
Merged

Conversation

cbrnr
Copy link
Contributor

@cbrnr cbrnr commented May 17, 2022

Fixes #10634. We need to read through the whole file when annotations are present. However, we accidentally prevented garbage collection in a loop, which led to extremely high memory usage. Because we read annotations when preload=False, this is a problem even when the user does not actually want to load the data. I've fixed this by creating an explicit copy of the subarray in the loop.

@cbrnr
Copy link
Contributor Author

cbrnr commented May 17, 2022

@arnaumanasanch could you please test this PR with your file and report your memory usage?

@arnaumanasanch
Copy link

Thanks @cbrnr The problem seems to be solved with this PR. The current memory usage is the one in the image below.

image

From a Spike of around 11Gb now it went down to 0.8Gb. This is a size that won't be problematic with the available RAM we have.

@cbrnr
Copy link
Contributor Author

cbrnr commented May 17, 2022

Alright, so this is ready for review then!

@cbrnr cbrnr requested review from agramfort and larsoner May 17, 2022 08:09
Copy link
Member

@agramfort agramfort left a comment

Choose a reason for hiding this comment

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

@cbrnr can I ask you add a what's new entry in bug fixes and send a PR to backport this?

@cbrnr cbrnr added the backport-candidate on-merge: backport to maint/1.7 label May 17, 2022
@cbrnr
Copy link
Contributor Author

cbrnr commented May 17, 2022

Done, I'll do the backport after this is merged.

doc/changes/latest.inc Outdated Show resolved Hide resolved
Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
Copy link
Member

@agramfort agramfort left a comment

Choose a reason for hiding this comment

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

maybe push an empty commit or merge the main branch to see if it fixes the CIs?

@larsoner larsoner merged commit 9d972e4 into mne-tools:main May 17, 2022
@larsoner
Copy link
Member

Thanks @cbrnr !

@cbrnr cbrnr deleted the fix-edf-memory branch May 17, 2022 16:07
larsoner added a commit to HanBnrd/mne-python that referenced this pull request May 17, 2022
* upstream/main: (24 commits)
  Use less memory when loading EDF file (mne-tools#10638)
  BUG: fix ipython console accessibility after MNEQtBrowser in Spyder (mne-tools#10637)
  WIP: Fix mne.time_frequency.multitaper Nyquist adjustment slightly incorrect (mne-tools#10541)
  BUG: Fix bug with fNIRS reordering (mne-tools#10630)
  MNT: PyQt6 for pip pre 3.10 (mne-tools#10636)
  CI: Fix conda (mne-tools#10628)
  MRG: Update installer links to point to 1.0.3_0 (mne-tools#10622)
  [BUG, MRG] fix info write access (mne-tools#10626)
  [MRG] Fixed group_by titles in evoked_plot. (mne-tools#10618)
  [BUG, MRG] Replace image_interp with interpolation in topomap plot arguments (mne-tools#10617)
  MAINT: Fix timeout (mne-tools#10624)
  Simplify mne-tools#10619 (mne-tools#10620)
  Drop EEG rejection thresholds when replacing EEG with CSD channels (mne-tools#10619)
  Add get_montage support for fNIRS (mne-tools#10611)
  ENH: Improve make_head_surface options (mne-tools#10592)
  [ENH, MRG] Add citation for intracranial JOSS paper (mne-tools#10616)
  [ENH] Add sys info for mne-icalabel (mne-tools#10615)
  MRG: Add "highlight" parameter to Evoked.plot() to conveniently highlight time periods (mne-tools#10614)
  MRG: Allow to pass array of "average" values to plot_evoked_topomap() (mne-tools#10610)
  fix: snirf length units (mne-tools#10613)
  ...
@cbrnr
Copy link
Contributor Author

cbrnr commented May 17, 2022

Is this backporting how-to still accurate? I'm not sure where the manually copied changelog line should go in /doc/changes/1.0.inc – do I need to create a new section for the 1.0.4 release?

@larsoner
Copy link
Member

Is this backporting how-to still accurate?

Yes in principle, but in practice if you are not familiar/comfortable with the process it's better to open a PR to maint/1.0 than it is to push directly in the last step

do I need to create a new section for the 1.0.4 release?

Yes

@cbrnr
Copy link
Contributor Author

cbrnr commented May 17, 2022

Thanks @larsoner, I'll try to make a PR then.

cbrnr added a commit to cbrnr/mne-python that referenced this pull request May 17, 2022
* Use less memory when loading EDF file

* Add changelog entry

* Formatting

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>

* Restart CI

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
agramfort added a commit that referenced this pull request May 17, 2022
* Use less memory when loading EDF file (#10638)

* Use less memory when loading EDF file

* Add changelog entry

* Formatting

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>

* Restart CI

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>

* Add changelog entry

* Fix version

* Change version to "unreleased"

Co-authored-by: Alexandre Gramfort <alexandre.gramfort@m4x.org>
@cbrnr cbrnr added backported and removed backport-candidate on-merge: backport to maint/1.7 labels May 17, 2022
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.

Reading large EDF files with preload = False raises memory error
4 participants