neuronsimulator / nrn

NEURON Simulator
http://nrn.readthedocs.io
Other
404 stars 118 forks source link

NEURON Model View for ModelDB 239421 crashes #1378

Closed ramcdougal closed 1 month ago

ramcdougal commented 3 years ago

Context

Overview of the issue

Attempting to use Model View for modeldb.yale.edu/239421 crashes. I wonder if this is related to the fact that the model uses threads.

Expected result/behavior

Not crashing. :)

NEURON setup

Minimal working example - MWE

Step 0: Download the model from https://modeldb.yale.edu/239421

step 1: compile mod files

nrnivmodl mod_files

step 2: start the simulation

nrniv -python protocols/01_PFAA.py

step 3: stop the simulation

hit the stop button on the RunControl panel

step 4: display the main menu

from neuron import gui

step 5: attempt to open ModelView

Tools - ModelView

Logs

The exact error message varies, but here's one:

[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
Assertion failed: (!xcb_xlib_threads_sequence_lost), function poll_for_event, file xcb_io.c, line 272.
zsh: abort      nrniv -python protocols/01_PFAA.py

and another:

/Users/ramcdougal/opt/anaconda3/bin/nrniv: copy : object prefix is NULL
 near line 1
 {forall SectionList[79].append()}
                                  ^
        doNotify()
      ModelViewDistinctValues[0].ndistinct(...)
    ModelViewSeclistAnalysis[6].mk_parm_subsets()
  ModelViewSeclistAnalysis[6].analyse()
and others
Exception in gui thread
Segmentation violation
Exception in thread Thread-1:
Backtrace:
Traceback (most recent call last):
  File "/Users/ramcdougal/opt/anaconda3/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/Users/ramcdougal/opt/anaconda3/lib/python3.8/site-packages/neuron/gui.py", line 79, in run
Bus error
Backtrace:
zsh: illegal hardware instruction  nrniv -python protocols/01_PFAA.py

and another:

NEURON -- VERSION 8.0a-524-gc9c4b7a8 HEAD (c9c4b7a8) 2021-04-21
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2021
See http://neuron.yale.edu/neuron/credits

loading membrane mechanisms from x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 "mod_files/Cav2_1.mod" "mod_files/Cav3_1.mod" "mod_files/Cav3_2.mod" "mod_files/Cav3_3.mod" "mod_files/HCN1_Angeloetal2007.mod" "mod_files/Kca11.mod" "mod_files/Kca22.mod" "mod_files/Kca31.mod" "mod_files/Kir23.mod" "mod_files/Kv11.mod" "mod_files/Kv15.mod" "mod_files/Kv33.mod" "mod_files/Kv34.mod" "mod_files/Kv43.mod" "mod_files/Leak.mod" "mod_files/Nav16.mod" "mod_files/PC_Gaba_det_vi_alfa1.mod" "mod_files/PURKINJE_Ampa_det_vi.mod" "mod_files/UBC_TRP.mod" "mod_files/cdp5.mod"
cores 8
    1 
len pf 100
len aa 0
len stl 25
>>> from neuron import gui
>>> Bus error
Backtrace:
    2   libsystem_platform.dylib            0x00007fff2057ed7d : _sigtramp()+29
    3   ???                                 0x00007fd4926a3a00 0x0 + 140550966229504
    4   libnrniv.dylib                      0x00000001039adf84 : _Z11hoc_executeP4Inst()+100
    5   libnrniv.dylib                      0x00000001039c1f5a : hoc_call_ob_proc()+234
    6   libnrniv.dylib                      0x00000001039c2c1a : _Z20hoc_object_componentv()+634
    7   libnrniv.dylib                      0x00000001039b0fa5 : _Z10hoc_ifcodev()+117
    8   libnrniv.dylib                      0x00000001039afefe : _Z12hoc_shortforv()+1086
    9   libnrniv.dylib                      0x00000001039afefe : _Z12hoc_shortforv()+1086
    10  libnrniv.dylib                      0x00000001039afefe : _Z12hoc_shortforv()+1086
    11  libnrniv.dylib                      0x00000001039afefe : _Z12hoc_shortforv()+1086
/Users/ramcdougal/opt/anaconda3/bin/nrniv: Aborting.  See $NEURONHOME/lib/help/oc.help
 near line 1
 {forall SectionList[79].append()}
                                  ^
        doNotify()
      ModelViewDistinctValues[0].ndistinct(...)
    ModelViewSeclistAnalysis[9].mk_parm_subsets()
  ModelViewSeclistAnalysis[9].analyse()
and others
Segmentation violation
Backtrace:
/Users/ramcdougal/opt/anaconda3/bin/nrniv: Aborting.
 near line 1
 ^
        doNotify()
      ModelViewDistinctValues[0].ndistinct(...)
    ModelViewSeclistAnalysis[9].mk_parm_subsets()
  ModelViewSeclistAnalysis[9].analyse()
and others
Exception in gui thread
Segmentation violation
Backtrace:
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/Users/ramcdougal/opt/anaconda3/lib/python3.8/threading.py", line 932, in _bootstrap_inner
Bus error
Backtrace:
Segmentation violation
Backtrace:
/Users/ramcdougal/opt/anaconda3/bin/nrniv: Aborting.
 near line 1
 ^
        ModelViewDistinctValues[0].ndistinct(...)
      ModelViewSeclistAnalysis[9].mk_parm_subsets()
    ModelViewSeclistAnalysis[9].analyse()
  ModelViewRealCell[9].analyse()
and others
Bus error
Backtrace:
    2   libsystem_platform.dylib            0x00007fff2057ed7d : _sigtramp()+29
    3   ???                                 0x0000000000020008 0x0 + 131080
    4   libsystem_c.dylib                   0x00007fff204472e6 : funlockfile()+36
    5   libsystem_c.dylib                   0x00007fff20450065 : vfprintf()+88
    6   libnrniv.dylib                      0x00000001039ddd89 : Fprintf()+137
    7   libnrniv.dylib                      0x00000001039b14d7 : frame_debug()+663
    8   libnrniv.dylib                      0x00000001039e197b : hoc_execerror_mes()+251
/Users/ramcdougal/opt/anaconda3/bin/nrniv: Aborting.  See $NEURONHOME/lib/help/oc.help
 near line 11
 ^
ramcdougal commented 3 years ago

I wonder if this is because this is a model that uses threads? If that is a problem, we should detect it and give a graceful, meaningful error message.

nrnhines commented 3 years ago

Quite by accident I didn't have a problem with

nrnivmodl mod_files
nrngui -python protocols/*.py
# stop the sim
# select NEURON/MainMenu/Tools/ModelView

But, yes, most things with 'from neuron import gui' gives me a problem.

$ git diff
diff --git a/protocols/01_PFAA.py b/protocols/01_PFAA.py
index 94e2fdc..c8f3042 100755
--- a/protocols/01_PFAA.py
+++ b/protocols/01_PFAA.py
@@ -1,9 +1,9 @@
+from neuron import h, gui
 # 01 - Excitatory and inhibitory activity on Purkinje cell model
 # Protocols to reproduce all the images based on the excitation/inhibition burst/pause behaviors
 import matplotlib as mpl
 mpl.use('tkagg')  
 from Purkinje_py3 import Purkinje_py3
-from neuron import h
 import numpy as np
 import multiprocessing
 import matplotlib.pyplot as plt
hines@hines-T7500:~/Downloads/Purkinjecell_2017$ nrniv -python protocols/*.py
NEURON -- VERSION 8.0a-603-g078a7b12a master (078a7b12a) 2021-07-21
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2021
See http://neuron.yale.edu/neuron/credits

loading membrane mechanisms from x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 "mod_files/Cav2_1.mod" "mod_files/Cav3_1.mod" "mod_files/Cav3_2.mod" "mod_files/Cav3_3.mod" "mod_files/cdp5.mod" "mod_files/HCN1_Angeloetal2007.mod" "mod_files/Kca11.mod" "mod_files/Kca22.mod" "mod_files/Kca31.mod" "mod_files/Kir23.mod" "mod_files/Kv11.mod" "mod_files/Kv15.mod" "mod_files/Kv33.mod" "mod_files/Kv34.mod" "mod_files/Kv43.mod" "mod_files/Leak.mod" "mod_files/Nav16.mod" "mod_files/PC_Gaba_det_vi_alfa1.mod" "mod_files/PURKINJE_Ampa_det_vi.mod" "mod_files/UBC_TRP.mod"
cores 8
    1 
len pf 100
len aa 0
len stl 25
>>> nrniv: Arg out of range in user function
 near line 1
 {forall SectionList[79].append()}
                                  ^
        ModelViewSeclistAnalysis[1].Matrix(4.68326e-310, 4.68326e-310)
      ModelViewSeclistAnalysis[1].MechanismStandard("Kv1_5", Matrix[603])
    ModelViewSeclistAnalysis[1].mk_parm_subsets()
  ModelViewSeclistAnalysis[1].analyse()
and others
*** longjmp causes uninitialized stack frame ***: nrniv terminated
Aborted (core dumped)

and

hines@hines-T7500:~/Downloads/Purkinjecell_2017$ python -i protocols/*.py
Traceback (most recent call last):
  File "/home/hines/Downloads/Purkinjecell_2017/protocols/01_PFAA.py", line 6, in <module>
    from Purkinje_py3 import Purkinje_py3
ModuleNotFoundError: No module named 'Purkinje_py3'

but the following also worked for me (with the import gui change above)

cp protocols/*.py temp.py
python -i temp.py

But seems brittle (but not always) in the sense of #1349 . I'm using

$ pyenv which python
/home/hines/.pyenv/versions/3.9.0/bin/python

I'm thinking there is indeed a thread problem but in the python from neuron import gui aspect.

nrnhines commented 1 month ago

I'm approaching this again with the latest master 9.0a-335-g1d812c87a and a clone of git@github.com:ModelDBRepository/239421.git on ubuntu 24.04

nrnivmodl mod_files requires a minor tweak:

~/models/modeldb/239421$ git diff
diff --git a/mod_files/cdp5.mod b/mod_files/cdp5.mod
index 31d8e70..17c5905 100644
--- a/mod_files/cdp5.mod
+++ b/mod_files/cdp5.mod
@@ -99,10 +99,9 @@ ASSIGNED {
        cai       (mM)
        mgi     (mM)
        vrat    (1)     
+       cao (mM)
 }

-CONSTANT { cao = 2     (mM) }
-
 STATE {

and nrngui -python protocols/01_PFAA.py requires export PYTHONPATH=`pwd`:$PYTHONPATH since apparently the working directory gets set to protocols so that otherwise

Traceback (most recent call last):
  File "protocols/01_PFAA.py", line 5, in <module>
    from Purkinje_py3 import Purkinje_py3
ModuleNotFoundError: No module named 'Purkinje_py3'

Anyway, after all this, modelview seems to work fine except for several ions with multiple styles not handled messages. It appears that the cell is broken into about 49 pieces and I notice there is a

$ grep -r multisplit
readme.html:The model uses NEURON multisplit to distribute automatically the
protocols/01_PFAA.py:#this code discover the number of cores available in a CPU and activate the multisplit to use them all.
protocols/01_PFAA.py:p.multisplit(1)

The bottom line so far is that I'm not seeing an issue with modelview for version 9.0. I get same behavior on my Apple M1 Sonoma 14.6.1

nrnhines commented 1 month ago

@ramcdougal I'm closing this as it seems to be fixed for 9.0. Reopen if you think it needs to be looked into for 8.2.