Cannot load compiled mod files from python

Anything that doesn't fit elsewhere.
Post Reply
igor
Posts: 5
Joined: Tue Mar 03, 2020 11:33 am
Contact:

Cannot load compiled mod files from python

Post by igor » Sat Mar 07, 2020 9:03 am

Hi,

I started working with NEURON recently, mainly using Python. A friend of mine has written a library which, at one moment, compiles some mod files using

Code: Select all

os.popen('nrnivmodl')
which runs great building an x86_64/.libs/ directory with compiled library libnrnmech.so. The compile procedure returns for each mod file compiled
"/Applications/NEURON-7.7/nrn/share/nrn/libtool" --tag=CC --mode=compile gcc -DHAVE_CONFIG_H -I. -I.. -I"/Applications/NEURON-7.7/nrn/include/nrn" -I"/Applications/NEURON-7.7/nrn/x86_64/lib" -g -O2 -c -o vecevent.lo vecevent.c
libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -I/Applications/NEURON-7.7/nrn/include/nrn -I/Applications/NEURON-7.7/nrn/x86_64/lib -g -O2 -c vecevent.c -fno-common -DPIC -o .libs/vecevent.o
with
"/Applications/NEURON-7.7/nrn/share/nrn/libtool" --tag=CC --mode=link gcc -module -g -O2 -headerpad_max_install_names -o libnrnmech.la -rpath "/Applications/NEURON-7.7/nrn/x86_64/lib" CaDynamics_E2.lo Ca_HVA.lo Ca_LVAst.lo Ih.lo Im.lo K_Pst.lo K_Tst.lo NaTa_t.lo NaTs2_t.lo Nap_Et2.lo SK_E2.lo SKv3_1.lo syn_4p.lo vecevent.lo mod_func.lo -L"/Applications/NEURON-7.7/nrn/x86_64/lib" -lnrnoc -loc -lmemacs -lscopmath -lsparse13 -lreadline -lncurses -L"/Applications/NEURON-7.7/nrn/x86_64/lib" -lnrniv -livoc -lneuron_gnu -lmeschach -lsundials
libtool: link: gcc -Wl,-undefined -Wl,dynamic_lookup -o .libs/libnrnmech.0.so -bundle .libs/CaDynamics_E2.o .libs/Ca_HVA.o .libs/Ca_LVAst.o .libs/Ih.o .libs/Im.o .libs/K_Pst.o .libs/K_Tst.o .libs/NaTa_t.o .libs/NaTs2_t.o .libs/Nap_Et2.o .libs/SK_E2.o .libs/SKv3_1.o .libs/syn_4p.o .libs/vecevent.o .libs/mod_func.o -L/Applications/NEURON-7.7/nrn/x86_64/lib /Applications/NEURON-7.7/nrn/x86_64/lib/libnrnoc.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/liboc.dylib -L/usr/X11/lib -lX11 /Applications/NEURON-7.7/nrn/x86_64/lib/libmemacs.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/libscopmath.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/libsparse13.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/libreadline.dylib -lncurses /Applications/NEURON-7.7/nrn/x86_64/lib/libnrniv.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/libivoc.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/libneuron_gnu.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/libmeschach.dylib /Applications/NEURON-7.7/nrn/x86_64/lib/libsundials.dylib -g -O2
libtool: link: (cd ".libs" && rm -f "libnrnmech.so" && ln -s "libnrnmech.0.so" "libnrnmech.so")
libtool: link: ( cd ".libs" && rm -f "libnrnmech.la" && ln -s "../libnrnmech.la" "libnrnmech.la" )
Successfully created x86_64/special
At the end.

It is correct, since running nrniv from terminal runs successfully:

Code: Select all

(pytorch) MacBook-Pro-4:mods0 igor$ nrniv
NEURON -- VERSION 7.7.2 7.7 (2b7985ba) 2019-06-20
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2018
See http://neuron.yale.edu/neuron/credits

loading membrane mechanisms from x86_64/.libs/libnrnmech.so
Additional mechanisms from files
 CaDynamics_E2.mod Ca_HVA.mod Ca_LVAst.mod Ih.mod Im.mod K_Pst.mod K_Tst.mod NaTa_t.mod NaTs2_t.mod Nap_Et2.mod SK_E2.mod SKv3_1.mod syn_4p.mod vecevent.mod
oc>
with all mechanisms being added.

On the other hand when trying to load it from Python

Code: Select all

import neuron
# ... neuron is initiated together with HocInterpreter object and then
h.nrn_load_dll(lib_path)
(where h is the HocObject initialised object) fails with error output
dlopen failed -
dlopen(/Users/igor/git/neuronpp/neuronpp/examples/compiled/mods0/x86_64/.libs/libnrnmech.so, 2): Symbol not found: __ZN11ivMonoGlyph4bodyEP7ivGlyph
Referenced from: /Applications/NEURON-7.7/nrn/x86_64/lib/libnrniv.0.dylib
Expected in: flat namespace
in /Applications/NEURON-7.7/nrn/x86_64/lib/libnrniv.0.dylib
I tried whatever I could find in other answers on this forum.

I am using NEURON 7.7.2.7.7, on Mac OSX 10.15 Catalina and a Conda python 3.7.

What may be wrong?

hines
Site Admin
Posts: 1595
Joined: Wed May 18, 2005 3:32 pm

Re: Cannot load compiled mod files from python

Post by hines » Wed Mar 11, 2020 9:19 am

The symbol that is not found would be in the interviews library and it is not clear to me why that is needed to successfully load the libnrnmech.so
file. Can you try the following test which loads the mod files for the neurondemo

Code: Select all

python3
from neuron import h
h.nrn_load_dll("/Applications/NEURON-7.7/nrn/share/nrn/demo/release/x86_64/.libs/libnrnmech.so")
But first verify that the path to the above libnnmech.so is correct on your machine. From this we will know if the issue is general on your machine
or has something specific to do with your mod files. On my mac I am not experiencing the problem with the libnrnmech.so for the neurondemo, but I am also using a cmake build of the latest repository code. The relevant difference with the cmake build is that all the interviews names are actually inside the main libnrniv.dylib
Also, did you build from sources or use the pkg installer for NEURON?

Post Reply