Page 1 of 1

Increase stacksize from python?

Posted: Thu Feb 19, 2015 11:34 am
by aaronmil
I have a model with over 10000 sections, specified in Python via the neuron module. When I execute:

Code: Select all

h.topology()
I am warned:

Code: Select all

NEURON: Stack too deep. Increase with -NSTACK stacksize option
If I then execute:

Code: Select all

from neuron import gui
and use the ModelViewer to visualize the topology, it's clear that it didn't load more compartments than the limited stacksize.

Is it possible to increase this parameter in Python? Normally it is changed via the command line, or modifying /nrn/share/nrn/lib/nrn.defaults, but it would be nice for model sharing if my script could update the interpreter without requiring the user to climb into the source.

Re: Increase stacksize from python?

Posted: Thu Feb 19, 2015 12:04 pm
by hines
I'm afraid that is not supported.
It's too bad that h.topology() even uses the hoc stack. It just needs to visit each of the child sections of a section in reverse order.

Re: Increase stacksize from python?

Posted: Thu Feb 19, 2015 12:28 pm
by ramcdougal
If you're using NEURON 7.3 or higher, the reaction-diffusion's morphology submodule will allow you to easily write a version of topology in pure Python.

I haven't tested edge cases (i.e. connecting to positions other than the 1 end), but here's a version that does at least the basics:

Code: Select all

def topology():
    from neuron.rxd import morphology
    morph = morphology.MorphologyDB()

    def print_morph(sec, indent=0):
        print (' ' * indent) + sec.name()
        for child in morph.children(sec):
            print_morph(child, indent + 2)
            
    for root in morph.roots:
        print_morph(root)
This is recursive, but that's not a huge issue in Python, because there you can set the maximum recursion depth at runtime.