Segmentation Fault when calling BBSaveState.save_test()

Anything that doesn't fit elsewhere.
Post Reply
peterbratby
Posts: 6
Joined: Fri Jul 20, 2018 1:00 am

Segmentation Fault when calling BBSaveState.save_test()

Post by peterbratby »

I would like to use BBSaveState to take a snapshot of the state of my parallel simulation, for use as starting conditions for further model runs. However, when I call BBSaveState.save_test(), a segmentation fault occurs:
Segmentation fault: 11
My simulation is quite complicated. However, even the following (completely trivial) code results in the segmentation fault on the call to save_test.

Code: Select all

from neuron import h

h.load_file("stdrun.hoc")
pc = h.ParallelContext()
pc.gid_clear()
pc.set_maxstep(10)
section = h.Section()
pc.set_gid2node(0, pc.id())
nc = h.NetCon(section(0.5)._ref_v, None, sec=section)
nc.threshold = 0
nc.delay = 1
nc.weight[0] = 1
pc.cell(0, nc)
pc.setup_transfer()
h.stdinit()
bbss = h.BBSaveState()
pc.psolve(100)
bbss.save_test()
I wonder if I am using BBSaveState correctly? I hope someone can help me with this. I am using Neuron 7.5 (6b4c19f) on MacOS.
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Segmentation Fault when calling BBSaveState.save_test()

Post by ted »

There have been many bug fixes and improvements since 7.5. Suggest you remove 7.5 and update to the latest version of NEURON (7.6.5), just in case that takes care of the problem.

With regard to your test program, why call pc.set_maxstep before even a single NetCon delay has been specified? Why invoke pc.setup_transfer for a model that has no gap junctions?
peterbratby
Posts: 6
Joined: Fri Jul 20, 2018 1:00 am

Re: Segmentation Fault when calling BBSaveState.save_test()

Post by peterbratby »

Thanks very much for your help. As you suggested, I installed the latest version of NEURON (7.7.0). I also corrected the two issues you identified in the code:

Code: Select all

from neuron import h

h.load_file("stdrun.hoc")
pc = h.ParallelContext()
pc.gid_clear()
section = h.Section()
pc.set_gid2node(0, pc.id())
nc = h.NetCon(section(0.5)._ref_v, None, sec=section)
nc.threshold = 0
nc.delay = 1
nc.weight[0] = 1
pc.cell(0, nc)
pc.set_maxstep(10)
h.stdinit()
bbss = h.BBSaveState()
pc.psolve(100)
bbss.save_test()


I still get the segmentation fault error on the call to bbss.save_test().
ted
Site Admin
Posts: 6289
Joined: Wed May 18, 2005 4:50 pm
Location: Yale University School of Medicine
Contact:

Re: Segmentation Fault when calling BBSaveState.save_test()

Post by ted »

Sorry this response took such a long time.

I decided to start with a parallelized network model that is known to work--specifically, ringpar.hoc, which implements the parallelized model of the ring network in
Hines ML, Carnevale NT (2008) Translating network models to parallel hardware in NEURON J. Neurosci. Meth. 169:425-455
https://www.ncbi.nlm.nih.gov/pubmed/17997162
which is available from ModelDB https://senselab.med.yale.edu/ModelDB/s ... odel=96444
Yes, it's in hoc, and the very short example in the Programmer's Reference documentation for BBSaveState is in Python, but the hoc implementation works.

Only minimal changes are needed to turn this into a program that would use BBSaveState. The changes I made are:

1. At the very start of the program insert

Code: Select all

// embed this assignment
// but consider moving it to the command line in the future
RESTORE = 0 // 0 to do a warmup run then save states
            // 1 to use previously saved states

if (RESTORE == 0) {
  TSTOP =  50 // do a 50 ms warmup simulation, then save states
} else {
  TSTOP = 100 // for a run after saved states have been restored
}
2. Change the simulation flow code from

Code: Select all

tstop = 100
{pc.set_maxstep(10)}
stdinit()
{pc.psolve(tstop)}
to

Code: Select all

/*
tstop = 100
{pc.set_maxstep(10)}
stdinit()
{pc.psolve(tstop)}
*/

tstop = TSTOP

proc prun() { localobj bbss
  pc.set_maxstep(10)
  stdinit()
  bbss = new BBSaveState()

  if (RESTORE == 1) {
    bbss.restore_test()
    if (pc.id==0) printf("after restore t = %g\n", t)
    pc.psolve(tstop)
  } else {
    pc.psolve(tstop)
    bbss.save_test()
  }
}

prun()
3. Comment out everything from the definition of proc spikeout() to the end of the file. Clearly a bit of additonal development is required to handle the "restore states and run a simulation from that point" case. For now, all I wanted was something that ran and saved states.

Program execution went well until the "save states" step, at which point the program exited with this message:

Code: Select all

nrniv: bbsavestate.cpp:410: BBSS_TxtFileOut::BBSS_TxtFileOut(const 
char*): Assertion `f' failed.
It turns out that BBSaveState.save_test() expects the "out" subdirectory to already exist. If "out" does not exist, the program just quits. Of course, that's not explicitly stated in the documentation of save_test--but it should be.

Anyway, after I created an "out" subdirectory, the code ran without problems and wrote a bunch of files to that directory.
Post Reply