Increase stacksize from python?

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

Moderator: hines

Post Reply
Posts: 35
Joined: Fri Apr 25, 2014 10:54 am

Increase stacksize from python?

Post by aaronmil » Thu Feb 19, 2015 11:34 am

I have a model with over 10000 sections, specified in Python via the neuron module. When I execute:

Code: Select all

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.

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

Re: Increase stacksize from python?

Post by hines » Thu Feb 19, 2015 12:04 pm

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.

Posts: 153
Joined: Fri Nov 28, 2008 3:38 pm
Location: Yale School of Medicine

Re: Increase stacksize from python?

Post by ramcdougal » Thu Feb 19, 2015 12:28 pm

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) +
        for child in morph.children(sec):
            print_morph(child, indent + 2)
    for root in morph.roots:
This is recursive, but that's not a huge issue in Python, because there you can set the maximum recursion depth at runtime.

Post Reply