maartenmennes/ICA-AROMA

Segmentation fault (core dumped)

oesteban opened this issue · 5 comments

This is probably a duplicate of #19, but I can't reopen.

Context - nipreps/fmriprep#1064 (comment)

Getting this:

Step 1) MELODIC
  - The existing/specified MELODIC directory will be used.
  - The MELODIC directory does not contain the required 'stats' folder. Mixture modeling on the Z-statistical maps will be run.
Step 2) Automatic classification of the components
  - registering the spatial maps to MNI
  - extracting the CSF & Edge fraction features
     - The spatial map of component 1 is empty. Please check!
     - The spatial map of component 2 is empty. Please check!
     - The spatial map of component 3 is empty. Please check!
     - The spatial map of component 4 is empty. Please check!
     - The spatial map of component 5 is empty. Please check!
     - The spatial map of component 6 is empty. Please check!
     - The spatial map of component 7 is empty. Please check!
     - The spatial map of component 8 is empty. Please check!
     - The spatial map of component 9 is empty. Please check!
     - The spatial map of component 10 is empty. Please check!
     - The spatial map of component 11 is empty. Please check!
     - The spatial map of component 12 is empty. Please check!
     - The spatial map of component 13 is empty. Please check!
     - The spatial map of component 14 is empty. Please check!
     - The spatial map of component 15 is empty. Please check!
     - The spatial map of component 16 is empty. Please check!
     - The spatial map of component 17 is empty. Please check!
     - The spatial map of component 18 is empty. Please check!
     - The spatial map of component 19 is empty. Please check!
     - The spatial map of component 20 is empty. Please check!
     - The spatial map of component 21 is empty. Please check!
     - The spatial map of component 22 is empty. Please check!
     - The spatial map of component 23 is empty. Please check!
     - The spatial map of component 24 is empty. Please check!
     - The spatial map of component 25 is empty. Please check!
     - The spatial map of component 26 is empty. Please check!
     - The spatial map of component 27 is empty. Please check!
     - The spatial map of component 28 is empty. Please check!
     - The spatial map of component 29 is empty. Please check!
     - The spatial map of component 30 is empty. Please check!
     - The spatial map of component 31 is empty. Please check!
  - extracting the Maximum RP correlation feature
  - extracting the High-frequency content feature
  - classification
Segmentation fault (core dumped)

Some items I checked:

  • Made sure all files are executable in the original melodic folder, and even run ICA_AROMA.py after setting umask 000.
  • Ran everything with absolute paths.
  • thresh_zstat files exist in melodic.ica/stats

Any ideas?

I've narrowed it down to the following backtrace:

#0  PyType_IsSubtype (a=0x626f6174656d5f74, b=0x7fffdc413660) at Objects/typeobject.c:1357
#1  0x00007fffdc2090cf in ?? () from /usr/local/miniconda/lib/python3.6/site-packages/sip.so
#2  0x00007fffdc209935 in ?? () from /usr/local/miniconda/lib/python3.6/site-packages/sip.so
#3  0x00007fffdbed2cdd in qpycore_init() () from /usr/local/miniconda/lib/python3.6/site-packages/PyQt5/QtCore.so
#4  0x00007fffdbea9bfc in PyInit_QtCore () from /usr/local/miniconda/lib/python3.6/site-packages/PyQt5/QtCore.so
#5  0x00007ffff7a3e55b in _PyImport_LoadDynamicModuleWithSpec (spec=0x7fffdc427390, fp=0x7fffdbea9b20 <PyInit_QtCore>) at ./Python/importdl.c:154
#6  0x00007ffff7a3b33f in _imp_create_dynamic_impl (file=<optimized out>, spec=0x7fffdc427390, module=<optimized out>) at Python/import.c:2004
...

I suspect that importing matplotlib is the origin of this Segmentation Fault (see matplotlib/matplotlib#9294)

Okay,

python -c "import matplotlib.pyplot as plt"

forces the segmentation fault. I'm closing this issue since it is not an ICA-AROMA problem per se.

However, @maartenmennes, please consider setting the 'Agg' backend right after loading matplotlib in the beginning (probably protected by a try...except for the case when users have already set the backend themselves).

For your Dockerfile, definitely consider something along these lines: https://github.com/poldracklab/mriqc/blob/cfedd5e008510a5d02f508ee1b9ca82976d5340d/Dockerfile#L116

Hi Oscar,
thanks for solving your own issue 😀 - but I'm kind of lost as to what the issue is and what I might need to implement to get this sorted at the AROMA end. This is beyond my level of dealing with python 😅

Hi Maarten,

Nine days ago you added this line:

https://github.com/maartenmennes/ICA-AROMA/blame/7b000665b45ea49b749bfe89be065f50f4921523/classification_plots.py#L9

For rendering, matplotlib uses a "backend". By default (and I don't know why), it seems like it selects QT5 (I guess that depends on pyqt being installed). These backends usually link to C libraries. In my settings (the docker image of fmriprep) QT was not fully installed and importing matplotlib caused the segfault.

In this function you don't want to pop up an interactive plot, so you are safe using the 'Agg' backend. That is the simplest one.

To make your code robuster, you should add:

import matplotlib as mpl
mpl.use('Agg')

It used to raise exception if the backend was already set, but now checking with matplotlib 2.2.0 it doesn't seem so.

For your Dockerfile, I recommended adding a line like https://github.com/poldracklab/mriqc/blob/cfedd5e008510a5d02f508ee1b9ca82976d5340d/Dockerfile#L116 to ensure that the default backend is set to 'Agg' within the container.

I hope this clarified a bit...

Thanks for the clarification @oesteban. I have fixed this in the classification_plots function. I have not fixed this in the Dockerfile as I currently have 0 experience with Docker. The file included in AROMA was provided by somebody else.