Exemple #1
0
def prun(tstop, restore=False):
    pc.set_maxstep(10 * ms)
    h.finitialize(-65 * mV)

    if restore == "SaveState":
        ns = h.SaveState()
        sf = h.File("state%d.bin" % pc.id())
        ns.fread(sf)
        ns.restore(0)  # event queue restored
        sf.close()
    elif restore == "BBSaveState":
        cp_out_to_in()  # prepare for restore.
        bbss = h.BBSaveState()
        bbss.restore_test()
    else:
        pc.psolve(tstop / 2)

        # SaveState save
        ss = h.SaveState()
        ss.save()
        sf = h.File("state%d.bin" % pc.id())
        ss.fwrite(sf)
        sf.close()

        # BBSaveState Save
        cnt = h.List("PythonObject").count()
        for i in range(1):
            bbss = h.BBSaveState()
            bbss.save_test()
            bbss = None
        assert h.List("PythonObject").count() == cnt

    pc.psolve(tstop)
Exemple #2
0
    def restore_state(self, state_file='state.bin', keep_events=False):
        from neuron import h
        ns = h.SaveState()
        sf = h.File(os.path.join(self.get_permanent_model_directory(), state_file))
        ns.fread(sf)

        h.stdinit()

        if keep_events:
            ns.restore(1)

            # Workaround - without the fixed step cycle, NEURON crashes with same error as in:
            # https://www.neuron.yale.edu/phpBB/viewtopic.php?f=2&t=3845&p=16542#p16542
            # Only happens when there is a vector.play added after a state restore
            # Running one cycle using the fixed integration method addresses the problem
            h.cvode_active(0)
            prev_dt = h.dt
            h.dt = 0.000001
            h.steprun()
            h.dt = prev_dt
            # END Workaround

        else:
            ns.restore()

        h.cvode_active(self.config.cvode_active)
Exemple #3
0
def savehocstate(filestr):
    '''saves the current hoc states (not rxd) of the simulation into file with name filestr.dat
  filestr: a string of file path (without file extension)'''
    myss = h.SaveState()
    #h.initnrn() # to set h.t to zero
    myss.save()
    myfile = h.File('./data/' + filestr + '_hoc_.dat')
    myss.fwrite(myfile)
    myfile.close()
Exemple #4
0
def read_state(conf):
    state_dir = conf["output"]["state_dir"]

    state = h.SaveState()
    f = h.File('{}/state_rank-{}'.format(state_dir, int(pc.id())))
    # f = h.File(state_dir+'/state_rank-%d' % (int(pc.id())))
    state.fread(f, 0)
    state.restore()
    rlist = h.List('Random')
    for r_tmp in rlist:
        r_tmp.seq(f.scanvar())
    f.close()
Exemple #5
0
def save_state(conf):
    state = h.SaveState()
    state.save()

    state_dir = conf["output"]["state_dir"]
    f = h.File('{}/state_rank-{}'.format(state_dir, int(pc.id())))
    # f = h.File(state_dir + '/state_rank-%d' % (int(pc.id())))
    state.fwrite(f, 0)
    rlist = h.List('Random')
    for r_tmp in rlist:
        f.printf('%g\n', r_tmp.seq())
    f.close()
Exemple #6
0
    def run_to_steady_state(self, tstop):
        self._update_current_sources(tstop)
        self._pre_run()
        self.parallel_context.set_maxstep(self.default_maxstep)
        self.tstop = tstop

        #logger.info("Running the simulation until steady state: %g ms" % tstop)
        if self.tstop > self.t:
            self.parallel_context.psolve(self.tstop)
        # Make object to save the model state
        svstate = h.SaveState()

        # Save the model state and write it to file
        svstate.save()
        f = h.File("steady_state.bin")
        svstate.fwrite(f)
Exemple #7
0
    def run_from_steady_state(self, tstop):
        self._update_current_sources(tstop)
        self._pre_run()
        self.parallel_context.set_maxstep(self.default_maxstep)
        self.tstop = tstop

        h.stdinit()

        ns = h.SaveState()
        sf = h.File('steady_state.bin')
        ns.fread(sf)
        #print("Time before restore = %g ms" % h.t)
        ns.restore(0)

        h.cvode_active(0)
        #print("Time after restore = %g ms" % h.t)
        #logger.info("Running the simulation until %g ms" % tstop)
        if self.tstop > self.t:
            self.parallel_context.psolve(self.tstop)
Exemple #8
0
def loadhocstate(filestr):
    '''loads hoc states (not rxd states) of simulation from file filestr.dat
  filestr: a string of file path (without file extension).
  For loading to happen appropriately, this statement has to be called after any initialization (eg h.finitalize)'''
    global tstart, tstop
    myfile = h.File()
    myfile.ropen('./data/' + filestr + '_hoc_.dat')
    myss = h.SaveState()
    if myfile.isopen():
        myss.fread(myfile)
        myfile.close()
        myss.restore(1)
        print 'loaded hoc states from:', myfile.getname()
        tstart = h.t
        tstop = tstart + simdur  # stopping time of simulation
        h.tstop = tstop
        #for ns in netStimlist: ns.start = nstimStart + tstart
    else:
        print "file cannot be open to read"
def restoreSS():
    svst = h.SaveState()
    f = h.File(os.path.join(restoredir, 'save_test_'+str(pcid) + '.dat'))
    svst.fread(f)
    svst.restore()
def runSS():
    svst = h.SaveState()
    svst.save()
    f = h.File(os.path.join(outdir,'save_test_' + str(pcid) + '.dat'))
    svst.fwrite(f)
Exemple #11
0
def restorestate():
    s = 'svst.{pcid}'.format(pcid=int(pc.id()))
    f = h.File(s)
    ss = h.SaveState()
    ss.fread(f)
    ss.restore()
Exemple #12
0
def savestate():
    s = 'svst.{pcid}'.format(pcid=int(pc.id()))
    f = h.File(s)
    ss = h.SaveState()
    ss.save()
    ss.fwrite(f)
Exemple #13
0
    pnm.nc_append(i, (i + 1) % ncell, -1, 1.1, 2)

# stimulate
if pnm.gid_exists(4):
    stim = h.NetStim(.5)
    ncstim = h.NetCon(stim, pnm.pc.gid2obj(4))
    ncstim.weight[0] = 1.1
    ncstim.delay = 1
    stim.number = 1
    stim.start = 1

pnm.set_maxstep(100)  # will end up being 2

pnm.want_all_spikes()

ss = h.SaveState()


def savestate():
    s = 'svst.{pcid}'.format(pcid=int(pc.id()))
    f = h.File(s)
    ss = h.SaveState()
    ss.save()
    ss.fwrite(f)


def restorestate():
    s = 'svst.{pcid}'.format(pcid=int(pc.id()))
    f = h.File(s)
    ss = h.SaveState()
    ss.fread(f)
Exemple #14
0
def flowJac(noiseTimes):

    cvodewrap.states(x)
    t0 = h.t
    print 't0'
    print t0
    ss = [None] * (len(noiseTimes) + 1)
    k = 0
    ss[0] = h.SaveState()
    ss[0].save()
    cvodewrap.re_init()
    while k < len(noiseTimes):
        print noiseTimes[k]
        h.continuerun(noiseTimes[k])
        ss[k + 1] = h.SaveState()
        ss[k + 1].save()
        cvodewrap.re_init()
        k += 1
    cvodewrap.states(value)

    # Derivative with respect to state
    DFx = pylab.zeros((len(value), len(x)))
    k = 0
    while k < len(x):
        ss[0].restore(1)
        cvodewrap.re_init()
        cvodewrap.states(x)
        temp = x[k]
        if abs(temp) > 1:
            dx = sqrtEps * abs(temp)
        else:
            dx = sqrtEps
        x.x[k] = temp + dx
        cvodewrap.yscatter(x)
        cvodewrap.re_init()
        dx = x[k] - temp  # trick to reduce finite precision error
        h.continuerun(noiseTimes[len(noiseTimes) - 1])
        cvodewrap.states(df)
        df.sub(value)
        df.div(dx)
        DFx[:, k] = numpy.array(df)
        k += 1

    # Derivative with respect to noise
    DFn = pylab.zeros((len(value), len(noiseTimes)))
    noiseTimes.insert(0, t0)
    k = 0
    while k < len(noiseTimes) - 1:
        ss[k + 1].restore(1)
        cvodewrap.re_init()
        if k < len(noiseTimes) - 2:
            dx = sqrtEps
            cvodewrap.states(x)
            x.x[0] += sigp * math.sqrt(noiseTimes[k + 1] - noiseTimes[k]) * dx
            cvodewrap.yscatter(x)
            cvodewrap.re_init()
            h.continuerun(noiseTimes[len(noiseTimes) - 1])
            cvodewrap.states(df)
            df.sub(value)
            df.div(dx)
            DFn[:, k] = numpy.array(df)
        else:
            DFn[:, k] = numpy.array(
                [sigp * math.sqrt(noiseTimes[k + 1] - noiseTimes[k]), 0, 0, 0])
        k += 1

    return [numpy.matrix(value).T, numpy.matrix(DFx), numpy.matrix(DFn)]
Exemple #15
0
 def save_state(self, state_file='state.bin'):
     from neuron import h
     ns = h.SaveState()
     sf = h.File(os.path.join(self.get_permanent_model_directory(), state_file))
     ns.save()
     ns.fwrite(sf)
Exemple #16
0
 def __init__(self):
     self.ss = h.SaveState()
     self.ss.save()
     self.t0 = h.t