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

Memory issues introduced in spectral_connectivity_time by #138 #174

Closed
ruuskas opened this issue Mar 6, 2024 · 1 comment
Closed

Memory issues introduced in spectral_connectivity_time by #138 #174

ruuskas opened this issue Mar 6, 2024 · 1 comment

Comments

@ruuskas
Copy link
Contributor

ruuskas commented Mar 6, 2024

Describe the bug

It appears that upon the addition of multivariate connectivity methods in #138, the following was introduced on line 483 in mne_connectivity/spectral/time.py.

conn_patterns[m] = np.full((n_epochs, 2, len(source_idx), n_freqs),
                           np.nan)

and this was later changed to

conn_patterns[m] = np.full(
    (n_epochs, 2, n_cons, max_n_channels, n_freqs), np.nan)

in #142.

This leads to memory problems with real data. In my current case, the array becomes of size
(7, 2, 100128, 100128, 32), which would require 32 TiB of memory. This problem does not occur with version 0.5.

Steps to reproduce

Try running the standard example with large number of signals (448 in my case) and frequencies.

Expected results

Code should run normally.

Actual results

I receive the following error:

File "<decorator-gen-290>", line 12, in spectral_connectivity_time
  File "*/miniconda3/envs/connectivity-pipeline/lib/python3.12/site-packages/mne_connectivity/spectral/time.py", line 543, in spectral_connectivity_time
    conn_patterns[m] = np.full(
                       ^^^^^^^^
  File "*/miniconda3/envs/connectivity-pipeline/lib/python3.12/site-packages/numpy/core/numeric.py", line 329, in full
    a = empty(shape, dtype, order)
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 32.7 TiB for an array with shape (7, 2, 100128, 100128, 32) and data type float64

Additional information

I'm running MNE-Python v1.6 and MNE-Connectivity v0.6.

Pinging here already @adam2392 and @tsbinns. For a quick fix, I guess the conn_patterns array could be initialized only if a multivariate method is used?

@tsbinns
Copy link
Collaborator

tsbinns commented Mar 6, 2024

Sorry for this @ruuskas, was an oversight on my part. I just submitted PR #175 to fix this by only initialising the array when it is required.

@tsbinns tsbinns closed this as completed Mar 12, 2024
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

No branches or pull requests

2 participants