MNE Coreg Segmentation Fault

  • operating system: Windows 11 / WSL Ubuntu 20.04

I am having an issue with getting the mne coreg gui to load. I’ve installed mne and freesurfer in my WSL.
mne sys_info
Platform: Linux-5.10.60.1-microsoft-standard-WSL2-x86_64-with-glibc2.29
Python: 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
Executable: /home/alexdv/mne/bin/python3
CPU: x86_64: 6 cores
Memory: 19.5 GB

mne: 0.24.1
numpy: 1.22.2 {}
scipy: 1.8.0
matplotlib: 3.5.1 {backend=QtAgg}

sklearn: 1.0.2
numba: Not found
nibabel: 3.2.2
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: 1.4.1
mayavi: 4.7.4
pyvista: 0.33.3 {OpenGL 3.3 (Core Profile) Mesa 21.2.6 via D3D12 (AMD Radeon™ Graphics)}
pyvistaqt: 0.7.0
ipyvtklink: Not found
vtk: 9.1.0
PyQt5: 5.12.3
ipympl: Not found
mne_qt_browser: Not found
pooch: Not found

Every time I try to open mne coreg from terminal I get a segmentation fault.

/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/_pyvista.py:41: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  VTK9 = LooseVersion(getattr(vtk, 'VTK_VERSION', '9.0')) >= LooseVersion('9.0')e 341 in _render
/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/_pyvista.py:41: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  VTK9 = LooseVersion(getattr(vtk, 'VTK_VERSION', '9.0')) >= LooseVersion('9.0')y", line 1953 in remove_actor
Using pyvistaqt 3d backend.b/python3.8/site-packages/pyvista/plotting/plotting.py", line 1049 in remove_actor
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 609 in _update_actor
/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/_pyvista.py:192: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  if LooseVersion(pyvista.__version__) >= '0.27.0':s/mne/gui/_coreg.py", line 524 in _update_plot
Using high resolution head model in /mnt/g/My Drive/Ricerca/EEG Data/TBSCrit_01_Pilot/TBSCrit_01_MRI/bem/TBSCrit_01_MRI-head-dense.fif
    Triangle neighbors and vertex normals...packages/mne/gui/_coreg.py", line 327 in _subjects_dir_changed
Estimating fiducials from fsaverage..8/site-packages/traitlets/traitlets.py", line 1266 in _notify_observers
Overwriting existing file.ib/python3.8/site-packages/traitlets/traitlets.py", line 1229 in notify_change
Using high resolution head model in /mnt/g/My Drive/Ricerca/EEG Data/TBSCrit_01_Pilot/TBSCrit_01_MRI/bem/TBSCrit_01_MRI-head-dense.fif
    Triangle neighbors and vertex normals...packages/traitlets/traitlets.py", line 595 in set
Estimating fiducials from fsaverage..8/site-packages/traitlets/traitlets.py", line 606 in __set__
Using outer_skin.surf for head surface.site-packages/mne/gui/_coreg.py", line 216 in _set_subjects_dir
Using outer_skin.surf for head surface.site-packages/mne/gui/_coreg.py", line 176 in __init__
Fatal Python error: Segmentation fault/site-packages/mne/gui/__init__.py", line 206 in coregistration
  File "<decorator-gen-564>", line 24 in coregistration
Current thread 0x00007fca6dfbd740 (most recent call first):mmands/mne_coreg.py", line 107 in run
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/plotting.py", line 1224 in render
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvistaqt/plotting.py", line 341 in _render
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvistaqt/plotting.py", line 346 in render
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/renderer.py", line 1953 in remove_actor
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/plotting.py", line 1049 in remove_actor
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 609 in _update_actor
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 681 in _add_head_surface
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 524 in _update_plot
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 586 in _reset
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 327 in _subjects_dir_changed
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 1266 in _notify_observers
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 1229 in notify_change
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 1219 in _notify_trait
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 595 in set
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 606 in __set__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 216 in _set_subjects_dir
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 176 in __init__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/__init__.py", line 206 in coregistration
  File "<decorator-gen-564>", line 24 in coregistration
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/mne_coreg.py", line 107 in run
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/utils.py", line 107 in main
  File "/home/alexdv/mne/bin/mne", line 8 in <module>
Segmentation fault

Can you give the command line call that you’re using? Could you also try downloading the MNE-sample-data (mne.datasets.sample.data_path() should fetch it to ~/mne_data/MNE-sample-data), then do something like:

cd ~/mne_data/MNE-sample-data
mne coreg -s sample -d subjects --fif MEG/sample/sample_audvis_raw.fif

? This way we can see if it’s broken even for the sample dataset. If it is, we’ll have to figure out why things aren’t working for your GPU.

If it works for sample but not your subjects_dir, we’ll have to figure out what it is about your dataset that causes a segfault.

The command I used is:


mne coreg -s TBSCrit_01_MRI -d '/mnt/g/My Drive/Ricerca/EEG Data/TBSCrit_01_Pilot'

I’ve tried now with the sample data, and I get the same Segmentation Fault

Using high resolution head model in /home/alexdv/mne_data/MNE-sample-data/subjects/sample/surf/lh.seghead
    Triangle neighbors and vertex normals...
Estimating fiducials from fsaverage.
Overwriting existing file.
    Triangle neighbors and vertex normals...
Using high resolution head model in /home/alexdv/mne_data/MNE-sample-data/subjects/sample/surf/lh.seghead
    Triangle neighbors and vertex normals...
Estimating fiducials from fsaverage.
Using outer_skin.surf for head surface.
Using outer_skin.surf for head surface.
Fatal Python error: Segmentation fault

Current thread 0x00007f0bb37e1740 (most recent call first):
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/plotting.py", line 1224 in render
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvistaqt/plotting.py", line 341 in _render
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvistaqt/plotting.py", line 346 in render
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/renderer.py", line 1953 in remove_actor
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/plotting.py", line 1049 in remove_actor
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 609 in _update_actor
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 681 in _add_head_surface
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 524 in _update_plot
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 586 in _reset
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 327 in _subjects_dir_changed
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 1266 in _notify_observers
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 1229 in notify_change
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 1219 in _notify_trait
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 595 in set
  File "/home/alexdv/mne/lib/python3.8/site-packages/traitlets/traitlets.py", line 606 in __set__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 216 in _set_subjects_dir
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 176 in __init__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/__init__.py", line 206 in coregistration
  File "<decorator-gen-564>", line 24 in coregistration
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/mne_coreg.py", line 107 in run
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/utils.py", line 107 in main
  File "/home/alexdv/mne/bin/mne", line 8 in <module>
Segmentation fault

Can you update to the latest MNE-Python (1.0.1) and PyVista and PyVistaQt? We have fixed some bugs in coreg since 0.24.1

are you running the code on a remote machine?

Alex

This is WSL, i.e., the Windows Subsystem for Linux. I don’t think this is supposed to render 3D graphics, or is it? I’d assume one would have to install an X server on the Windows host and connect to it from the Linux system. But I’m not entirely sure.

Yes, I have an X server on Windows that I know works to render other graphics, so I don’t think that is the issue here.

I updated MNE, pyvista, pyvistaQT, and now I see the MNE logo flash as if it’s about to load, but then it crashes and I see the same Segmentation Fault.

Using pyvistaqt 3d backend.

Fatal Python error: Segmentation fault

Current thread 0x00007f154bdf6740 (most recent call first):
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/utilities/helpers.py", line 1193 in check_depth_peeling
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/renderer.py", line 425 in enable_depth_peeling
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/_pyvista.py", line 657 in _enable_depth_peeling
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/_pyvista.py", line 197 in __init__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/_qt.py", line 807 in __init__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/renderer.py", line 40 in _get_renderer
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 227 in __init__
  File "<decorator-gen-570>", line 12 in __init__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/__init__.py", line 193 in coregistration
  File "<decorator-gen-558>", line 12 in coregistration
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/mne_coreg.py", line 85 in run
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/utils.py", line 107 in main
  File "/home/alexdv/mne/bin/mne", line 8 in <module>
Segmentation fault

Can you prepend the command with:

MNE_3D_OPTION_DEPTH_PEELING=false

to disable depth peeling, which seems to be causing the above crash?

I’ve seen this behavior on remote systems using X2go. We may need to disable additional 3D features too, like anti-aliasing.

Also, could you please share mne sys_info again, now that you’ve updated some packages?

Ok, by prepending with the

MNE_3D_OPTION_DEPTH_PEELING=false

Now, the MNE logo stays up for longer, but I get the following error:

Using pyvistaqt 3d backend.

    Triangle neighbors and vertex normals...
Using high resolution head model in /home/alexdv/mne_data/MNE-sample-data/subjects/sample/surf/lh.seghead
    Triangle neighbors and vertex normals...
Estimating fiducials from fsaverage.
    Triangle neighbors and vertex normals...
Using high resolution head model in /home/alexdv/mne_data/MNE-sample-data/subjects/sample/surf/lh.seghead
    Triangle neighbors and vertex normals...
Estimating fiducials from fsaverage.
Estimating fiducials from fsaverage.
Placing MRI fiducials - LPA
Using lh.seghead for head surface.
Channel types:: eeg: 59
Placing MRI fiducials - LPA
Fatal Python error: Segmentation fault

Thread 0x00007f158e67b700 (most recent call first):
  File "/usr/lib/python3.8/threading.py", line 302 in wait
  File "/usr/lib/python3.8/queue.py", line 170 in get
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 671 in _run_worker
  File "/usr/lib/python3.8/threading.py", line 870 in run
  File "/usr/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/usr/lib/python3.8/threading.py", line 890 in _bootstrap

Thread 0x00007f158ee7c700 (most recent call first):
  File "/usr/lib/python3.8/threading.py", line 302 in wait
  File "/usr/lib/python3.8/queue.py", line 170 in get
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 671 in _run_worker
  File "/usr/lib/python3.8/threading.py", line 870 in run
  File "/usr/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/usr/lib/python3.8/threading.py", line 890 in _bootstrap

Current thread 0x00007f15e9b38740 (most recent call first):
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvista/plotting/plotting.py", line 1285 in render
  File "/home/alexdv/mne/lib/python3.8/site-packages/pyvistaqt/plotting.py", line 309 in _render
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/viz/backends/_qt.py", line 818 in show
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/_coreg.py", line 300 in __init__
  File "<decorator-gen-570>", line 12 in __init__
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/gui/__init__.py", line 193 in coregistration
  File "<decorator-gen-558>", line 12 in coregistration
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/mne_coreg.py", line 85 in run
  File "/home/alexdv/mne/lib/python3.8/site-packages/mne/commands/utils.py", line 107 in main
  File "/home/alexdv/mne/bin/mne", line 8 in <module>
Segmentation fault

Here is the sys_info again:

Platform: Linux-5.10.60.1-microsoft-standard-WSL2-x86_64-with-glibc2.29
Python: 3.8.10 (default, Nov 26 2021, 20:14:08) [GCC 9.3.0]
Executable: /home/alexdv/mne/bin/python3
CPU: x86_64: 6 cores
Memory: 19.5 GB

mne: 1.0.1
numpy: 1.22.2 {}
scipy: 1.8.0
matplotlib: 3.5.1 {backend=QtAgg}

sklearn: 1.0.2
numba: Not found
nibabel: 3.2.2
nilearn: Not found
dipy: Not found
cupy: Not found
pandas: 1.4.1
pyvista: 0.34.0 {OpenGL 3.3 (Core Profile) Mesa 21.2.6 via D3D12 (AMD Radeon™ Graphics)}
pyvistaqt: 0.9.0
ipyvtklink: Not found
vtk: 9.1.0
PyQt5: 5.12.3
ipympl: Not found
pooch: v1.6.0

mne_bids: Not found
mne_nirs: Not found
mne_features: Not found
mne_qt_browser: Not found
mne_connectivity: Not found

Ok, so now let’s try to disable even more 3D stuff.

I’d suggest to start the coreg UI from a script as otherwise things become a bit messy:

import mne

mne.viz.set_3d_options(antialias=False, depth_peeling=False, smooth_shading=False)
mne.gui.coregistration(..., advanced_rendering=False)

What kind of X server are you using, by the way?

Alright, so that seems to have fixed part of it. The GUI now appears, and I can move the fiducials around fine, but when I go to load in the montage it crashes with a segmentation fault again. This happens for the sample data and my data.

mne.viz.set_3d_options(antialias=False, depth_peeling=False, smooth_shading=False)
mne.gui.coregistration(subject=subject,subjects_dir=subjects_dir,advanced_rendering=False)
<stdin>:1: RuntimeWarning: The parameter advanced_rendering is not supported with the pyvistaqt 3d backend. It will be ignored.
Using pyvistaqt 3d backend.

    Triangle neighbors and vertex normals...
Using high resolution head model in /home/alexdv/mne_data/MNE-sample-data/subjects/sample/surf/lh.seghead
    Triangle neighbors and vertex normals...
Estimating fiducials from fsaverage.
    Triangle neighbors and vertex normals...
Using high resolution head model in /home/alexdv/mne_data/MNE-sample-data/subjects/sample/surf/lh.seghead
    Triangle neighbors and vertex normals...
Estimating fiducials from fsaverage.
Estimating fiducials from fsaverage.
Placing MRI fiducials - LPA
Using lh.seghead for head surface.
Placing MRI fiducials - LPA
Using lh.seghead for head surface.
Channel types:: eeg: 59
Segmentation fault

I use Xming!

Can you try passing the path to the file containing the info with the digpoints directly to the function, i.e., do something like:

raw_path = '/my/data-raw.fif'
mne.viz.set_3d_options(antialias=False, depth_peeling=False, smooth_shading=False)
mne.gui.coregistration(
    subject=subject,
    subjects_dir=subjects_dir,
    inst=raw_path
)

No unfortunately get the same segmentation fault as soon as I press lock fiducials.

Is there a specific reason you’re using WSL2 anyway? Can you not run things natively on Windows?

Aside from that, I’d suggest to start with an entirely fresh install of MNE, ideally with one of our new installers, to ensure the Python environment you’re using is consistent.

I had tried with an older version of MNE, but there’s some issues when trying to build wheels for mayavi. I remember trying it before a few years and again a few months ago, but something happened that made me switch. Can’t for the life of me remember now. I’ve always used the mne_environment conda file to install, but I’ll try the Windows installer now and see.

There’s also an installer for Linux if you insist in using WSL2.