Truncation of floats upon loading .hoc file from ipython

When Python is the interpreter, what is a good
design for the interface to the basic NEURON
concepts.

Moderator: hines

mbesserve
Posts: 7
Joined: Sat Mar 17, 2018 2:36 pm

Truncation of floats upon loading .hoc file from ipython

Post by mbesserve »

Dear Neuron community,
I am reporting here an issue that I have specifically with ipython, while *the same code in python seems to work fine*.

I have converted an .swc cell morphology file to a .hoc file using the Neuron GUI (Import 3D _ cell builder).
With an ipython console I then load this file into neuron using
import neuron
neuron.h.load_file(<FileName>)

This runs without errors, but all dimensions of the loaded sections have been truncated to the lowest integer. For example, I get zero for
neuron.h.dend[0].diam3d(k)
for any k within the acceptable range of this section.

A zero diameter obviously leads to further errors.

I tested on 2 unix machines with
ubuntu 16.4 LTS/ubuntu 17.10
python 2.7 and python 3
ipython 6.0 and ipython 5.0

I could not figure out what in ipython causes this issue. I would assume it has to do with division, but imposing
from __future__ import division
does not seem to fix it.

Do you have any idea what can cause this behavior. Not being able to use ipython poses challenges, besides it takes a lot of time to figure out ipython is the issue, has for example spyder only has ipython console support (no python console anymore).

I am pasting below the parts of my .hoc file

Many thanks,
Michel

Code: Select all

%%%%% .hoc file %%%%
proc celldef() {
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()
}

create soma, dend[57], apic[101]

proc topol() { local i
  connect dend(0), soma(0.5)
  for i = 1, 4 connect dend[i](0), dend[i-1](1)
  connect dend[5](0), dend[3](1)
  connect dend[6](0), dend[2](1)
  for i = 7, 8 connect dend[i](0), dend[6](1)
  connect dend[9](0), dend[1](1)
  for i = 10, 11 connect dend[i](0), dend[9](1)
  connect dend[12](0), dend(1)
%%%%%%%%% skipping many lines here %%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%
  for i = 96, 97 connect apic[i](0), apic[95](1)
  connect apic[98](0), apic[6](1)
  for i = 99, 100 connect apic[i](0), apic[98](1)
  basic_shape()
}
proc shape3d_1() {
  soma {pt3dclear()
	pt3dadd(0, 0, 30, 20)
	pt3dadd(10, 0, 30, 20)
	pt3dadd(20, 0, 30, 20)
  }
  dend {pt3dclear()
	pt3dstyle(1, 10, 0, 30)
	pt3dadd(-0.09, 1.2, 30, 0.7)
	pt3dadd(-0.8, 2, 30.2, 0.7)
	pt3dadd(-2.1, 2.6, 30.7, 0.7)
	pt3dadd(-3.1, 3, 31.1, 0.7)
	pt3dadd(-4.09, 3.3, 31.6, 0.7)
	pt3dadd(-4.9, 3.5, 32.1, 0.7)
	pt3dadd(-6.7, 3.8, 33.29, 0.7)
	pt3dadd(-7.3, 4.09, 33.79, 0.7)
	pt3dadd(-7.8, 4.59, 34.29, 0.7)
	pt3dadd(-8.5, 5.2, 35, 0.7)
	pt3dadd(-8.9, 5.7, 35.5, 0.7)
	pt3dadd(-9.5, 6.5, 36.29, 0.7)
	pt3dadd(-10.4, 7.1, 37.2, 0.7)
	pt3dadd(-11.1, 7.3, 37.79, 0.7)
	pt3dadd(-11.9, 7.7, 38.6, 0.7)
	pt3dadd(-12.5, 8.1, 39.2, 0.7)
	pt3dadd(-13.3, 8.4, 39.9, 0.7)
	pt3dadd(-14.9, 9.1, 41.4, 0.7)
	pt3dadd(-16.7, 10.1, 43.1, 0.7)
	pt3dadd(-17.6, 10.6, 43.9, 0.7)
	pt3dadd(-19.1, 11.3, 45, 0.7)
	pt3dadd(-19.89, 11.9, 45.7, 0.7)
	pt3dadd(-20.39, 12.2, 46, 0.7)
	pt3dadd(-21.2, 12.2, 46.4, 0.7)
	pt3dadd(-24.8, 12.2, 47.8, 0.7)
	pt3dadd(-26, 12.2, 48, 0.7)
	pt3dadd(-26.8, 12.6, 48, 0.7)
  }
%%%%%%%% skipping many lines here %%%%%%%%%

%%%%%%%%%%%%%%%%%%%
proc basic_shape() {
  shape3d_1()
  shape3d_2()
  shape3d_3()
  shape3d_4()
  shape3d_5()
  shape3d_6()
  shape3d_7()
  shape3d_8()
  shape3d_9()
  shape3d_10()
  shape3d_11()
  shape3d_12()
  shape3d_13()
  shape3d_14()
  shape3d_15()
  shape3d_16()
  shape3d_17()
  shape3d_18()
  shape3d_19()
  shape3d_20()
  shape3d_21()
  shape3d_22()
  shape3d_23()
  shape3d_24()
  shape3d_25()
  shape3d_26()
  shape3d_27()
  shape3d_28()
  shape3d_29()
  shape3d_30()
  shape3d_31()
  shape3d_32()
  shape3d_33()
  shape3d_34()
  shape3d_35()
  shape3d_36()
  shape3d_37()
  shape3d_38()
}

objref all, somatic, basal, apical
proc subsets() { local i
  objref all, somatic, basal, apical
  all = new SectionList()
    soma all.append()
    for i=0, 56 dend[i] all.append()
    for i=0, 100 apic[i] all.append()

  somatic = new SectionList()
    soma somatic.append()

  basal = new SectionList()
    for i=0, 56 dend[i] basal.append()

  apical = new SectionList()
    for i=0, 100 apic[i] apical.append()

}
proc geom() {
}
proc geom_nseg() {
}
proc biophys() {
}
access soma

celldef()
ted
Site Admin
Posts: 6286
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Truncation of floats upon loading .hoc file from ipython

Post by ted »

I can't help with Ipython, but here's a suggestion that may help you avoid a lot of typing: instead of
import neuron
do
from neuron import h
Then you can access NEURON's features by typing
h...
instead of
neuron.h...
Example:
from neuron import h
h.load_file(<FileName>)
ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Truncation of floats upon loading .hoc file from ipython

Post by ramcdougal »

This is puzzling because when you use h.load_file, the Python interpreter plays literally no role in loading the morphology (it's all done by the HOC interpreter instead).

I was, unfortunately, not able to quickly reproduce your issue (details below), but I did have to modify the code slightly to get it to run, so can you please try the version below and letting us know if you get the same results? Also: what version of NEURON are you using?

As shared, the code that you sent does not run, so I made a version that does and called it cellmorph.hoc:

Code: Select all

proc celldef() {
  topol()
  subsets()
  geom()
  biophys()
  geom_nseg()
}

create soma, dend[57], apic[101]

proc topol() { local i
  connect dend(0), soma(0.5)
  for i = 1, 4 connect dend[i](0), dend[i-1](1)
  connect dend[5](0), dend[3](1)
  connect dend[6](0), dend[2](1)
  for i = 7, 8 connect dend[i](0), dend[6](1)
  connect dend[9](0), dend[1](1)
  for i = 10, 11 connect dend[i](0), dend[9](1)
  connect dend[12](0), dend(1)

  for i = 96, 97 connect apic[i](0), apic[95](1)
  connect apic[98](0), apic[6](1)
  for i = 99, 100 connect apic[i](0), apic[98](1)
  basic_shape()
}
proc shape3d_1() {
  soma {pt3dclear()
    pt3dadd(0, 0, 30, 20)
    pt3dadd(10, 0, 30, 20)
    pt3dadd(20, 0, 30, 20)
  }
  dend {pt3dclear()
    pt3dstyle(1, 10, 0, 30)
    pt3dadd(-0.09, 1.2, 30, 0.7)
    pt3dadd(-0.8, 2, 30.2, 0.7)
    pt3dadd(-2.1, 2.6, 30.7, 0.7)
    pt3dadd(-3.1, 3, 31.1, 0.7)
    pt3dadd(-4.09, 3.3, 31.6, 0.7)
    pt3dadd(-4.9, 3.5, 32.1, 0.7)
    pt3dadd(-6.7, 3.8, 33.29, 0.7)
    pt3dadd(-7.3, 4.09, 33.79, 0.7)
    pt3dadd(-7.8, 4.59, 34.29, 0.7)
    pt3dadd(-8.5, 5.2, 35, 0.7)
    pt3dadd(-8.9, 5.7, 35.5, 0.7)
    pt3dadd(-9.5, 6.5, 36.29, 0.7)
    pt3dadd(-10.4, 7.1, 37.2, 0.7)
    pt3dadd(-11.1, 7.3, 37.79, 0.7)
    pt3dadd(-11.9, 7.7, 38.6, 0.7)
    pt3dadd(-12.5, 8.1, 39.2, 0.7)
    pt3dadd(-13.3, 8.4, 39.9, 0.7)
    pt3dadd(-14.9, 9.1, 41.4, 0.7)
    pt3dadd(-16.7, 10.1, 43.1, 0.7)
    pt3dadd(-17.6, 10.6, 43.9, 0.7)
    pt3dadd(-19.1, 11.3, 45, 0.7)
    pt3dadd(-19.89, 11.9, 45.7, 0.7)
    pt3dadd(-20.39, 12.2, 46, 0.7)
    pt3dadd(-21.2, 12.2, 46.4, 0.7)
    pt3dadd(-24.8, 12.2, 47.8, 0.7)
    pt3dadd(-26, 12.2, 48, 0.7)
    pt3dadd(-26.8, 12.6, 48, 0.7)
  }
}

proc basic_shape() {
  shape3d_1()
}

objref all, somatic, basal, apical
proc subsets() { local i
  objref all, somatic, basal, apical
  all = new SectionList()
    soma all.append()
    for i=0, 56 dend[i] all.append()
    for i=0, 100 apic[i] all.append()

  somatic = new SectionList()
    soma somatic.append()

  basal = new SectionList()
    for i=0, 56 dend[i] basal.append()

  apical = new SectionList()
    for i=0, 100 apic[i] apical.append()

}
proc geom() {
}
proc geom_nseg() {
}
proc biophys() {
}
access soma

celldef()
When I tried this with IPython 5.5.0 and NEURON 7.5 on the Windows Subsystem for Linux, and it correctly reported the diameter:

Code: Select all

$ ipython
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
Type "copyright", "credits" or "license" for more information.

IPython 5.5.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from neuron import h
NEURON -- VERSION 7.5 master (fb8538e+) 2017-09-18
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits


In [2]: h.load_file('cellmorph.hoc')
Out[2]: 1.0

In [3]: h.dend[0].diam3d(0)
Out[3]: 0.699999988079071
Can you please copy-paste an IPython session where you're doing the same so we can compare? Thanks.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by hines »

I have not yet been able to reproduce the problem

Code: Select all

hines@hines-T7500:~/tmp$ ipython2
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
Type "copyright", "credits" or "license" for more information.

IPython 5.2.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: from neuron import h
NEURON -- VERSION 7.5 master (9fef270) 2018-03-16
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits


In [2]: h.load_file("temp.hoc")
Out[2]: 1.0

In [3]: h.dend[0].diam3d(2)
Out[3]: 0.699999988079071

I had to slightly modify the fragment you copied as three was a missing }, extra procedure names that did not exist, and non-syntacticly valid annotations. Can you send me your hoc
file. Also the banner of the version of NEURON you are using (or else try again with the latest github version).
mbesserve
Posts: 7
Joined: Sat Mar 17, 2018 2:36 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by mbesserve »

My apologies for the lack of precision in the original post. Here is what I do in detail in spyder (ipython console):

Code: Select all

Python 2.7.14 |Anaconda, Inc.| (default, Dec  7 2017, 17:05:42)
Type "copyright", "credits" or "license" for more information.

IPython 4.0.3 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

Restarting kernel... 


 

1/2
Out[1]: 0

from __future__ import division

import neuron

morphFile='morphologies/pc1abis.hoc'

neuron.h.load_file(morphFile)
Out[5]: 1.0

neuron.h.dend[0].diam3d(1)
Out[6]: 0.0

neuron.h.dend[0].diam3d(2)
Out[7]: 0.0

neuron.h.dend[0].x3d(1)
Out[8]: -0.0

neuron.h.dend[0].y3d(1)
Out[9]: 2.0

neuron.h.dend[0].y3d(1)
As you can see all quantities are truncated.
However, I just realized that this does actually work right now on my machine using ipython 4.0.3 only (although I did have the issue with ipython only before).
My guess is something must be wrong with the neuron import, but have to figure out what affects this (if you have any idea where to look at please let me know). Let me come back to you.

Here is my Neuron version info:
NEURON -- VERSION 7.5 master (6b4c19f) 2017-09-25
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits

I can't paste here my full .hoc file (too many characters...), so here is a link to it (not sure this is good practice but I do not know what else to do).
https://owncloud.tuebingen.mpg.de/index ... DXKFFMzRXH

Many thanks for your help,
Michel
mbesserve
Posts: 7
Joined: Sat Mar 17, 2018 2:36 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by mbesserve »

A short update. I am yet unable to reproduce the truncation issue with ipython in command line (although i am 100% sure it happened before), but the error still occurs when using spyder (which is using an ipython console too).
I checked the library files are the same in both situations: /usr/local/nrn/lib/python/neuron/__init__.py
I noticed one difference in behavior:
in the working case (ipython only), neuron commands print outputs (such as the Neuron version upon import). In the spyder ipython console, it prints nothing.
I tried "import hoc" which loads the content of "hoc.so" in both cases, and again there is a printing issue:

hoc.execute(1/2)
prints ".5" in the working case, before returning 1 in the console.
In spyder, it returns 1 without printing anything before.

Do you have any idea where this difference in behavior could come from, or what I could check further?
I am not sure anymore it comes from ipython, but I never got the error when directly using python console.
Many thanks,
Michel
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by hines »

hoc.execute(1/2)
prints ".5" in the working case, before returning 1 in the console.
In spyder, it returns 1 without printing anything before.
I'm guessing you mean
hoc.execute('1/2')
as otherwise it raises "NEURON: Expecting string argument" RuntimeError: hoc error
I use
from neuron import h
and I do notice

Code: Select all

>>> h.execute("1/2")
0.0
>>> h('1/2')
	0.5 
1
The latter is correct and expected since a hoc statement at the top level prints the value of an expression and h("expr") returns 1 if hoc succeeded
and 0 if not.
The former surprised me until i dug deeper and realised that the hoc statement "execute" always returns 0.0 .
i.e launching NEURON with the hoc interpreter...

Code: Select all

oc>execute("1/2")
	0 
oc>execute("print 1/2")
0.5 
	0
I suddenly realize you used the hoc module via
from neuron import hoc
and in that circumstance, the hoc verson of execute is not being called from python but the python wrapper that causes hoc to execute
at the top level (and so print the result of an expression).

Code: Select all

>>> hoc.execute("1/2")
	0.5 
1
>>> hoc.execute(1/2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: argument 1 must be string, not int
There was a change to the printing mechanism

Code: Select all

commit ef4da5dbf293580ee1bf86b3a94d3d2f80226f62
Author: Michael Hines <michael.hines@yale.edu>
Date:   Tue May 16 07:24:29 2017 -0400

    If python is launched use nrnpy_pr instead of printf to print to stdout.
    
    This allows h.printf, h.topology, and h.psection to print to
    the Jupyter notebook.
But that predates the version you are using. I suppose there could be some printing situations in hoc that were left out of the steering to nrnpy_pr.
It would be helpful to provide an example that demonstrates a print difference. So far I'm gathering that one needs to compare a difference
between python/ipython and spyder. And I presume we are discussing a problem with the linux version.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by hines »

just to be clear about the difference between h and hoc in the neuron module...

Code: Select all

hines@hines-T7500:~$ python
Python 2.7.12 (default, Dec  4 2017, 14:50:18) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from neuron import h, hoc
NEURON -- VERSION 7.5 master (f4ee1de) 2018-03-16
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits

>>> type(h)
<type 'hoc.HocObject'>
>>> type(hoc)
<type 'module'>
>>> 

ramcdougal
Posts: 267
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Public Health

Re: Truncation of floats upon loading .hoc file from ipython

Post by ramcdougal »

In Spyder, if you store the value of the diam3d call and print it later, does that work? I'm wondering if you're seeing a return status and not the diameter itself.
mbesserve
Posts: 7
Joined: Sat Mar 17, 2018 2:36 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by mbesserve »

@ramcdougal and hines: Thanks for your time and comments! Actually it does also print directly in spyder, when I run

Code: Select all

from neuron import hoc
hoc. execute("1/2")
This "normal" procedure imports hoc by finding the neuron library in my python path, and (I guess) running the __init__.py inside.


What I did to get the print issue was different, in order to check any difference in the way neuron/hoc libraries are imported in the __init__.py file of the library. So I went to the folder
/usr/local/nrn/lib/python/neuron/
and imported hoc.so directly using

Code: Select all

import hoc
hoc. execute("1/2")
This last procedure (which would not work outside of this folder) gives robust differences in printing between spyder and ipython (spyder does not print)

Regarding ramcdougal's question.
In this particular import context, if I do

Code: Select all

hoc.execute("a = 1/2")
hoc.execute("print a")
It does not print anything either...


I am not sure I should focus on this print difference, but this is the only thing I could spot that robustly differs between the working and non working case. Why and how is the hoc library loading differently? (again: spyder is using the same ipython, i.e. the ipython of my conda environment...)

I think I am stuck here: I am pretty sure it is not a spyder issue per se but something about the interfacing with the Neuron interpreter. I am mostly using Neuron through the LFPy library, and even when using a python console (through Pycharm), although it mostly works, I get sometimes an error due to a zero diameter. This happened when I ran several calls to the LFPy.Cell() constructor, which imports the morphology, calls neuron.h.lambda_f, and this function triggers a hoc RuntimeError due to the zero diameter.
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by hines »

I believe the problem will resolve if you always import neuron prior to import hoc (import neuron also imports hoc so you can replace any
import hoc with from neuron import hoc.
The reason for this is the code in the neuron/__init__.py file that reads:

Code: Select all

if not embedded:
  try:
    # callback in place of hoc printf
    # ensures consistent with python stdout even with jupyter notebook.  
but earlier in the file

Code: Select all

import sys
embedded = True if 'hoc' in sys.modules else False
So, because you import hoc prior to import neuron, embedded is True and the code that registers the callback for printing is skipped.
Note that when embedded is True, that generally means nrniv was launched instead of python and so python is embedded into neuron instead of
neuron being an extension to python.
mbesserve
Posts: 7
Joined: Sat Mar 17, 2018 2:36 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by mbesserve »

Hi Michael,

I do not usually "import hoc", but just tried this do figure out any potential issue. In the end I guess the errors are due to some library file used by the hoc file interpreter (not working properly, absent or conflicting with others libraries in some situations?) when running neuron.h.load_file(), and I assume there is no way to learn more about this by just trying to run the neuron python library because the actual error happens in when running some hoc code (but can we actually debug what is going on inside neuron.h.load_file() within python? or with some other debugger?).

So I decided to reinstall neuron from the tar.gz (instead of the .deb as I did before). All this is done within a conda environement with python 2.7 (because unfortunately some LFPy related libraries do not work with python 3...).

I followed the install instructions here
https://neuron.yale.edu/neuron/download ... heroptions

with python as alternative interpreter (the interpreter being the one of my conda environment)
I suggested in this page, I ran the extra
python setup.py install inside src/nrnpython

to generate the neuron python library in my local site-packages folder.

This reinstallation did not solve the previous issue, but at least I can report some issues I encountered that might be part of the problem:

upon make install of nrn there is a syntax error:

Code: Select all

byte-compiling /is/ei/besserve/neuron/nrn/lib/python/neuron/hclass3.py to hclass3.pyc
  File "/is/ei/besserve/neuron/nrn/lib/python/neuron/hclass3.py", line 29
    class hc(hoc.HocObject, metaclass=MetaHocObject):
                                     ^
SyntaxError: invalid syntax
besides this I could not spot anything significant in the long output.

and the neuron demo seems to run ok (although i do not know how to test it extensively.

Once the whole installation was done, running import neuron (in a python console) was missing
libreadline.so.0

I encountered such issue in a past installation (but then was asking for libreadline.so.6, although I realized I had the issue upon installation of LFPy)
I solved this by creating a simlink for libreadline.so.6 to libreadline.so.0 in my local library (the lib folder of my conda environment)

After neuron can be imported within python without error.

After that I get the same error as usual in spyder (cylinder diameter truncated to zero). In pycharm (i.e. with a python console), I do not get the truncation error direcly (same as before), but I get stuck with a different error upon importing hybridLFPy (https://github.com/INM-6/hybridLFPy, note this module does not need to be installed with pip, just to be put in the path)

Code: Select all

NEURON -- VERSION 7.5 master (6b4c19f) 2017-09-25
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits

dlopen failed - 
x86_64/.libs/libnrnmech.so: undefined symbol: nrnmpi_myid
As I saw similar neuron related errors on the web, I assume it might have something to do with my neuron installation.

Would you have any idea where to look at? Or any library that may be involved in these errors? (I cannot exclude some issues related to LFPy and hybridLFPy libraries, but it would be funny that they affect the way neuron.h.load_file works...)

For example, which libraries may affect the reading of a .hoc file? libreadline? Can it be that some version of libreadline has a bug and at some point neuron.h.load_file uses this version because of the current library path, which may depend on whether I use spyder or python, and whether some other library (hybridLFPy?) is imported first?


Thanks for you help,
Michel
hines
Site Admin
Posts: 1682
Joined: Wed May 18, 2005 3:32 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by hines »

It would be interesting to see if the problem goes away by demanding that embedded = False in neuron/__init__.py . Ie. just add a
embedded = False
line after the check about whether the hoc module is already loaded.
mbesserve
Posts: 7
Joined: Sat Mar 17, 2018 2:36 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by mbesserve »

Hi Michael,
The problem remains after changing the init file as you suggested.

Regarding the minimalistic example:

neuron.h.load_file('/is/ei/besserve/MBsource/scripts/neural_models/hybridlfpy/morphologies/pc1abis.hoc')

neuron.h.dend[0].diam3d(0)

now does not work anymore in an ipython console (without spyder, after reinstallation of neuron).

I am trying to play with different versions of libreadline.so, but without success until now. I am pretty sure this has something to do with some libraries/library paths, but do not know enough to figure out which are relevant here.
mbesserve
Posts: 7
Joined: Sat Mar 17, 2018 2:36 pm

Re: Truncation of floats upon loading .hoc file from ipython

Post by mbesserve »

I did a reinstall with a brand new conda environment:
Here is the full procedure:

Code: Select all

# create conda environment and activate
conda create -n lfpy2 python=2.7 pip ipython
source activate lfpy2

# just add this package, as I have see in one post it may be required, other required packages are already installed afaik.
sudo apt-get install mpich

# install potentially required packages (with conda when available, otherwise with pip)
conda install spyder
conda install scipy
conda install cython
conda install mpi4py
pip install neo
pip install lazyarray
conda install matplotlib
conda install h5py

# I am already in the nrn folder, I reinstall after a make clean/make uninstall
./configure --prefix=/is/ei/besserve/neuron/nrn --with-iv=/is/ei/besserve/neuron/iv --with-nrnpython=/is/ei/besserve/.conda/envs/lfpPy/bin/python2.7 -with-readline=/lib/x86_64-linux-gnu/

make
make install

# neurondemo runs fine after that

# now going to generate the python package
cd src/nrnpython/
python setup.py install

After that I get the usual truncation discrepancy between python and ipython.

Code: Select all

[rench 29] ~/neuron/nrn/src/nrnpython > ipython
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) 
Type "copyright", "credits" or "license" for more information.

IPython 5.3.0 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: import neuron
NEURON -- VERSION 7.5 master (6b4c19f) 2017-09-25
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits


In [2]: neuron.h.load_file('/is/ei/besserve/MBsource/scripts/neural_models/hybridlfpy/morphologies/pc1abis.hoc')
Out[2]: 1.0

In [3]: neuron.h.dend[1].diam3d(1)
Out[3]: 0.0

In [4]: quit()
(lfpy2) [19:30 - 0]
[rench 30] ~/neuron/nrn/src/nrnpython > python
Python 2.7.13 |Continuum Analytics, Inc.| (default, Dec 20 2016, 23:09:15) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import neuron
NEURON -- VERSION 7.5 master (6b4c19f) 2017-09-25
Duke, Yale, and the BlueBrain Project -- Copyright 1984-2016
See http://neuron.yale.edu/neuron/credits

>>> neuron.h.load_file('/is/ei/besserve/MBsource/scripts/neural_models/hybridlfpy/morphologies/pc1abis.hoc')
1.0
>>> neuron.h.dend[1].diam3d(1)
0.699999988079071
>>> 
Would you have any way to try to reproduce this? I am really completely stuck here ;)
Post Reply