Exemplo n.º 1
0
def simulate(pool, tstop=50000, vinit=-55):
    ''' simulation control
    Parameters
    ----------
    cell: NEURON cell
        cell for simulation
    tstop: int (ms)
        simulation time
    vinit: int (mV)
        initialized voltage
    '''
    h.finitialize(vinit)
    for i in pool:
        cell = pc.gid2cell(i)
        balance(cell)
    if h.cvode.active():
        h.cvode.active()
    else:
        h.fcurrent()
    h.frecord_init()
    h.tstop = tstop
    h.v_init = vinit
    pc.set_maxstep(0.5)
    h.stdinit()
    pc.psolve(tstop)
Exemplo n.º 2
0
    def run_cclamp(self):

        print "- running model", self.name

        rec_t = h.Vector()
        rec_t.record(h._ref_t)

        rec_v = h.Vector()
        rec_v.record(h.soma(0.5)._ref_v)

        h.stdinit()

        dt = 0.025
        h.dt = dt
        h.steps_per_ms = 1 / dt
        h.v_init = -65

        h.celsius = 34
        h.init()
        h.tstop = 1600
        h.run()

        t = numpy.array(rec_t)
        v = numpy.array(rec_v)

        return t, v
Exemplo n.º 3
0
def test_direct_memory_transfer():
    h('''create soma''')
    h.soma.L = 5.6419
    h.soma.diam = 5.6419
    h.soma.insert("hh")
    ic = h.IClamp(h.soma(.5))
    ic.delay = .5
    ic.dur = 0.1
    ic.amp = 0.3

    h.cvode.use_fast_imem(1)
    h.cvode.cache_efficient(1)

    v = h.Vector()
    v.record(h.soma(.5)._ref_v, sec=h.soma)
    i_mem = h.Vector()
    i_mem.record(h.soma(.5)._ref_i_membrane_, sec=h.soma)
    tv = h.Vector()
    tv.record(h._ref_t, sec=h.soma)
    h.run()
    vstd = v.cl()
    tvstd = tv.cl()
    i_memstd = i_mem.cl()

    pc = h.ParallelContext()
    h.stdinit()
    pc.nrncore_run("-e %g" % h.tstop, 0)

    assert (tv.eq(tvstd))
    assert (v.cl().sub(vstd).abs().max() < 1e-10)
    assert (i_mem.cl().sub(i_memstd).abs().max() < 1e-10)
Exemplo n.º 4
0
    def run_cclamp_somatic_feature(self, section_rec, loc_rec):

        exec("self.sect_loc=h." + str(section_rec) + "(" + str(loc_rec) + ")")

        print "- running model", self.name

        rec_t = h.Vector()
        rec_t.record(h._ref_t)

        rec_v = h.Vector()
        rec_v.record(self.sect_loc._ref_v)

        h.stdinit()

        dt = 0.025
        h.dt = dt
        h.steps_per_ms = 1 / dt
        h.v_init = -65

        h.celsius = 34
        h.init()
        h.tstop = 1600
        h.run()

        t = numpy.array(rec_t)
        v = numpy.array(rec_v)

        return t, v
    def getRMP(self, parameters, debug=False):
        if not self.stop:
            # Simulation parameters
            h.load_file('stdrun.hoc')
            h.load_file('negative_init.hoc')
            tstop = 100
            dt = 0.025
            h.stdinit()
            h.celsius = 37.0
            h.tstop = tstop
            h.v_init = -65

            # Instantiate and parameterize cells
            testCell = cell.Cell(0, (0, 0), self.synvars, 'granulecell',
                                 'output0_updated.swc')
            self.parameterizeCell(testCell, parameters)

            # Instrument cells
            self.RMPv = h.Vector()
            self.RMPv.record(testCell.c.soma[0](0.5)._ref_v)

            # Run simulation
            h.run()

            # Get RMP
            self.RMP = self.RMPv[-1]
            if debug:
                return [np.array([self.RMP]), np.array([self.RMPv])]
            else:
                return np.array([self.RMP])
        else:
            return 1e9
Exemplo n.º 6
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)
def simulate(pool, tstop=1000, vinit=-55):
    ''' simulation control 
    Parameters
    ----------
    cell: NEURON cell
        cell for simulation
    tstop: int (ms)
        simulation time
    vinit: int (mV)
        initialized voltage
    '''
    h.finitialize(vinit)
    for i in pool:
        cell = pc.gid2cell(i)
        balance(cell)
    if h.cvode.active():
        h.cvode.active()
    else:
        h.fcurrent()
    h.frecord_init()
    h.tstop = tstop
    h.v_init = vinit
    pc.set_maxstep(0.5)
    h.stdinit()
    pc.psolve(tstop)
Exemplo n.º 8
0
    def run_syn(self):

        # initiate recording
        rec_t = h.Vector()
        rec_t.record(h._ref_t)

        rec_v = h.Vector()
        rec_v.record(h.somaA(0.5)._ref_v)

        rec_v_dend = h.Vector()
        rec_v_dend.record(self.dendrite(self.xloc)._ref_v)

        print "- running model", self.name
        # initialze and run
        #h.load_file("stdrun.hoc")
        h.stdinit()

        dt = 0.025
        h.dt = dt
        h.steps_per_ms = 1 / dt
        h.v_init = -65

        h.celsius = 34
        h.init()
        h.tstop = 300
        h.run()

        # get recordings
        t = numpy.array(rec_t)
        v = numpy.array(rec_v)
        v_dend = numpy.array(rec_v_dend)

        return t, v, v_dend
Exemplo n.º 9
0
    def run(mode):
        h.stdinit()
        if mode == 0:
            pc.psolve(h.tstop)
        elif mode == 1:
            while h.t < h.tstop:
                pc.psolve(h.t + 1.0)
        else:
            while h.t < h.tstop:
                h.continuerun(h.t + 0.5)
                pc.psolve(h.t + 0.5)

        corenrn_all_spike_t_py = corenrn_all_spike_t.to_python()
        corenrn_all_spike_gids_py = corenrn_all_spike_gids.to_python()

        # check spikes match
        assert len(nrn_spike_t)  # check we've actually got spikes
        assert len(nrn_spike_t) == len(nrn_spike_gids)  # matching no. of gids
        if nrn_spike_t != corenrn_all_spike_t_py:
            print(mode)
            print(nrn_spike_t)
            print(nrn_spike_gids)
            print(corenrn_all_spike_t_py)
            print(corenrn_all_spike_gids_py)
            print([
                corenrn_all_spike_t[i] - nrn_spike_t[i]
                for i in range(len(nrn_spike_t))
            ])
        assert nrn_spike_t == corenrn_all_spike_t_py
        assert nrn_spike_gids == corenrn_all_spike_gids_py
Exemplo n.º 10
0
def prun():
    pc.barrier()  # wait for all hosts to get to this point
    pc.set_maxstep(1);
    h.stdinit()
    if (pc.id()==0 and printflag>1):
        print("Parallel run is going to run till",h.tstop)
    pc.psolve(h.tstop);
    pc.barrier()  # wait for all hosts to get to this point
Exemplo n.º 11
0
def simulate(tstop=25):
    """Initialize and run a simulation.

    :param tstop: Duration of the simulation.
    """
    h.tstop = tstop
    h.stdinit()
    h.run()
    def getMembraneTimeConstant(self, parameters, debug=False):
        if not self.stop:
            ######################################
            # Membrane Time Constant Experiments #
            ######################################
            # Simulation parameters
            h.load_file('stdrun.hoc')
            h.load_file('negative_init.hoc')
            tstop = self.subthresh_dur + 300
            dt = 0.025
            h.stdinit()
            h.celsius = 37.0
            h.tstop = tstop
            h.v_init = -65

            # Instantiate and parameterize cells
            testCell = cell.Cell(0, (0, 0), self.synvars, 'granulecell',
                                 'output0_updated.swc')
            self.parameterizeCell(testCell, parameters)

            # Make sure the cell doesn't spike
            # Create inputs for experiments
            stim = h.IClamp(0.5, sec=testCell.c.soma[0])
            stim.amp = self.threshAmp  # amp at which neuron no longer spikes
            stim.dur = self.subthresh_dur  # subthresh is duration where neuron no longer spikes
            stim.delay = 0

            # Instrument cells
            self.tauV = h.Vector()
            self.tauV.record(testCell.c.soma[0](0.5)._ref_v)
            t = h.Vector()
            t.record(h._ref_t)
            tvec = h.Vector()
            nc = testCell.connect_pre(None, 0, 0)
            nc.record(tvec)

            # Run simulation
            h.run()

            # Calculate membrane time constant
            self.tauV = np.array(self.tauV)
            t = np.array(t)
            t_idx = t >= self.subthresh_dur
            t = t[t_idx] - self.subthresh_dur
            v = self.tauV[t_idx]
            try:
                popt, pcov = curve_fit(self.expFunc, t, v, p0=(1, -0.1, -60))
                self.tau = -1 / popt[1]
            except RuntimeError:
                self.tau = 1000

            if debug:
                return [np.array([self.tau]), v, t, popt]
            else:
                return np.array([self.tau])

        else:
            return 1e9
Exemplo n.º 13
0
def prun():
    pc.timeout(1)
    pc.multisplit()
    pc.set_maxstep(1)
    pc.setup_transfer()
    h.stdinit()
    if rank == 0:
        h.cvode.event(2.001, callback)  # works when 2.0
    pc.psolve(5)
Exemplo n.º 14
0
def foo(s):
    print(s)
    h.stdinit()
    print("ri ", [seg.ri() for seg in cab.allseg()])
    for freq in [1., 10., 100.]:
        imp.compute(freq, 1, 5000)
        x = [seg.x for seg in cab.allseg()]
        trans = [imp.transfer(i, sec=cab) for i in x]
        print('freq=%g transimped=' % (freq), trans)
Exemplo n.º 15
0
def prun(runState):
    h.stdinit()
    if runState == 1:
        pnm.psolve(h.tstop / 2.)
        savestate()
    else:
        restorestate()
    h.frecord_init()
    pnm.psolve(h.tstop)
    pspike()
Exemplo n.º 16
0
def simulate(cell, tstop=400, vinit=-55):
    ''' simulation control
    Parameters
    ----------
    cell: NEURON cell
        cell for simulation
    tstop: int (ms)
        simulation time
    vinit: int (mV)
        initialized voltage
    '''
    h.finitialize(vinit)
    balance(cell)
    if h.cvode.active():
        h.cvode.active()
    else:
        h.fcurrent()
    h.frecord_init()
    h.tstop = tstop
    h.v_init = vinit
    h.run()
    if cell.numofmodel == 9 or cell.numofmodel == 10 or cell.numofmodel == 12:
        running_ = 1
        if cell.numofmodel == 9:
            dl = 0
            d_t = 60000
        elif cell.numofmodel == 10:
            dl = 1000
            d_t = 40
        else:
            dl = 800
            d_t = 10
        h.stdinit()
        for n in range(3):
            cell.x_application = cell.x_application + dl
            if n == 0:
                cell.dl = 5000
                cell.x_application = 0
                print(cell.x_application)
            else:
                cell.dl = 30050
                cell.x_application = -400
            cell.distance()
            for item in cell.diffs:
                item.tx1 = h.t + 5
                # item.initial = 0#item.atp
                # if n == 0:
                #     item.c0cleft = 0.01#item.c0cleft
                # else:
                item.c0cleft = item.c0cleft
                item.h = cell.distances.get(cell.diffusions.get(item))
            h.continuerun(h.t + d_t)
        h.continuerun(h.t + 500)
Exemplo n.º 17
0
def runring(ncell=5, delay=1, tstop=100):
  ring = Ring(ncell, delay)
  pc.set_maxstep(10)
  h.stdinit()
  pc.psolve(tstop)
  spkcnt = pc.allreduce(len(ring.tvec), 1)
  tmax = pc.allreduce(ring.tvec.x[-1], 2)
  tt = h.Vector()
  idv = h.Vector()
  pc.allgather(ring.tvec.x[-1], tt)
  pc.allgather(ring.idvec.x[-1], idv)
  idmax = int(idv.x[int(tt.max_ind())])
  return (int(spkcnt), tmax, idmax, (ncell, delay, tstop, (pc.id_world(), pc.nhost_world())))
Exemplo n.º 18
0
def runring(ncell=5, delay=1, tstop=100):
  ring = Ring(ncell, delay)
  pc.set_maxstep(10)
  h.stdinit()
  pc.psolve(tstop)
  spkcnt = pc.allreduce(len(ring.tvec), 1)
  tmax = pc.allreduce(ring.tvec.x[-1], 2)
  tt = h.Vector()
  idv = h.Vector()
  pc.allgather(ring.tvec.x[-1], tt)
  pc.allgather(ring.idvec.x[-1], idv)
  idmax = int(idv.x[int(tt.max_ind())])
  return (int(spkcnt), tmax, idmax, (ncell, delay, tstop, (rank, nhost)))
Exemplo n.º 19
0
    def _set_init_conditions(self):
        """Set up the initial conditions: either read from the h.SaveState or from config["condidtions"]"""
        pc.set_maxstep(10)
        h.stdinit()
        self.tstep = int(round(h.t/h.dt))
        self.tstep_start_block = self.tstep

        if self._start_from_state:
            # io.read_state()
            io.log_info('Read the initial state saved at t_sim: {} ms'.format(h.t))
        else:
            h.v_init = self.v_init

        h.celsius = self.celsius
Exemplo n.º 20
0
def runring(ncell=5, delay=1, tstop=100):
  ring = Ring(ncell, delay) # ring is local, therefore destroyed upon exit
  pc.set_maxstep(10) # minimum NetCon delay
  h.stdinit()
  pc.psolve(tstop)
  spkcnt = pc.allreduce(len(ring.tvec), 1) # total number of spikes in ring
  tmax = pc.allreduce(ring.tvec.x[-1], 2) # last spike time
  # min time would be 3 aka first spike
  tt = h.Vector()
  idv = h.Vector()
  pc.allgather(ring.tvec.x[-1], tt) # all last times in tt
  pc.allgather(ring.idvec.x[-1], idv) # biggest ids
  idmax = int(idv.x[int(tt.max_ind())]) # identifier of cell that fired last
  return (int(spkcnt), tmax, idmax, (ncell, delay, tstop, (pc.id_world(), pc.nhost_world())))
Exemplo n.º 21
0
    def prun(self,tstop):
        #from neuron import h    
        pc=h.ParallelContext()
        NCELL=self.NCELL
        SIZE=self.SIZE
        COMM = self.COMM
        RANK=self.RANK
        checkpoint_interval = 50000.

        #The following definition body is from the open source code at:
        #http://senselab.med.yale.edu/ModelDB/ShowModel.asp?model=151681
        #with some minor modifications
        cvode = h.CVode()
        cvode.cache_efficient(1)
        # pc.spike_compress(0,0,1)
    
        pc.setup_transfer()
        mindelay = pc.set_maxstep(10)
        if RANK == 0:
            print 'mindelay = %g' % mindelay
        runtime = h.startsw()
        exchtime = pc.wait_time()
    
        inittime = h.startsw()
        h.stdinit()
        inittime = h.startsw() - inittime
        if RANK == 0:
            print 'init time = %g' % inittime
    
        while h.t < tstop:
            told = h.t
            tnext = h.t + checkpoint_interval
            if tnext > tstop:
                tnext = tstop
            pc.psolve(tnext)
            if h.t == told:
                if RANK == 0:
                    print 'psolve did not advance time from t=%.20g to tnext=%.20g\n' \
                        % (h.t, tnext)
                break    
            print 'working', h.t
        runtime = h.startsw() - runtime
        comptime = pc.step_time()
        splittime = pc.vtransfer_time(1)
        gaptime = pc.vtransfer_time()
        exchtime = pc.wait_time() - exchtime
        if RANK == 0:
            print 'runtime = %g' % runtime
        print comptime, exchtime, splittime, gaptime
Exemplo n.º 22
0
def runring(ncell=5, delay=1, tstop=100):
    ring = Ring(ncell, delay)  # ring is local, therefore destroyed upon exit
    pc.set_maxstep(10)  # minimum NetCon delay
    h.stdinit()
    pc.psolve(tstop)
    spkcnt = pc.allreduce(len(ring.tvec), 1)  # total number of spikes in ring
    tmax = pc.allreduce(ring.tvec.x[-1], 2)  # last spike time
    # min time would be 3 aka first spike
    tt = h.Vector()
    idv = h.Vector()
    pc.allgather(ring.tvec.x[-1], tt)  # all last times in tt
    pc.allgather(ring.idvec.x[-1], idv)  # biggest ids
    idmax = int(idv.x[int(tt.max_ind())])  # identifier of cell that fired last
    return (int(spkcnt), tmax, idmax, (ncell, delay, tstop,
                                       (pc.id_world(), pc.nhost_world())))
Exemplo n.º 23
0
def main():
    h.load_file("multisplit.hoc")
    h('{nrn_load_dll("../specials/x86_64/.libs/libnrnmech.so")}')

    tstop = 1000
    pc = h.ParallelContext()
    start = h.startsw()

    ######################################################
    # load model
    cell = load_model("./1056.swc")

    ######################################################
    # generate mcomplex.dat
    lb = h.MyLoadBalance()
    lb.ExperimentalMechComplex()
    #save_mcomplex(lb)
    pc.barrier()

    ######################################################
    # set up multi split
    cplx = h.multisplit(lb)
    pc.multisplit()
    pc.set_maxstep(10)

    ######################################################
    # set stim and record of v
    stim = set_iclamp("CellSwc[0].Dend[2000]", pc)
    vec_t = h.Vector()
    vec_t.record(h._ref_t)
    vec_v = set_vec_v("CellSwc[0].Dend[100]", pc)
    setup_time = h.startsw() - start

    ######################################################
    # run simulation
    start = h.startsw()
    h.stdinit()
    pc.psolve(tstop)
    pc.barrier()
    calc_time = h.startsw() - start

    ######################################################
    # disp info
    show_result(pc, setup_time, calc_time, cplx)
    #show_section()
    #if(vec_v != 0):
    #    show_plot(vec_t, vec_v)
    pc.done()
Exemplo n.º 24
0
def bpattrun():
    netfcns.erasecue(pop_by_name,pc)
    for i in range(0, NPATT):
        if (pc.id()==0 and printflag>1):
            print("Cue pattern ", i) # print header once
        cuefstem = "{}_{}".format(fstem, i)
        #h.sprint(fstem, "Results/HAM_P5R%", i)
        netfcns.mkcue(FPATT, i, CFRAC, NPATT, pc);	# cue from stored pattern
        pc.barrier()  # wait for all hosts to get to this point
        #{pc.set_maxstep(10)}
        pc.set_maxstep(1);
        h.stdinit()
        pc.psolve(h.tstop);
        netfcns.spikeout(cells,fstem,pc)
        netfcns.vout(cells,results,fstem,pc)
        netfcns.erasecue(pop_by_name,pc)
Exemplo n.º 25
0
def test_direct_memory_transfer():
    h('''create soma''')
    h.soma.L = 5.6419
    h.soma.diam = 5.6419
    h.soma.insert("hh")
    ic = h.IClamp(h.soma(.5))
    ic.delay = .5
    ic.dur = 0.1
    ic.amp = 0.3

    #for testing external mod file
    h.soma.insert("Sample")

    h.cvode.use_fast_imem(1)
    h.cvode.cache_efficient(1)

    v = h.Vector()
    v.record(h.soma(.5)._ref_v, sec=h.soma)
    i_mem = h.Vector()
    i_mem.record(h.soma(.5)._ref_i_membrane_, sec=h.soma)
    tv = h.Vector()
    tv.record(h._ref_t, sec=h.soma)
    h.run()
    vstd = v.cl()
    tvstd = tv.cl()
    i_memstd = i_mem.cl()
    # Save current (after run) value to compare with transfer back from coreneuron
    tran_std = [h.t, h.soma(.5).v, h.soma(.5).hh.m]

    from neuron import coreneuron
    coreneuron.enable = True
    coreneuron.gpu = bool(os.environ.get('CORENRN_ENABLE_GPU', ''))

    pc = h.ParallelContext()
    h.stdinit()
    pc.psolve(h.tstop)
    tran = [h.t, h.soma(.5).v, h.soma(.5).hh.m]

    assert (tv.eq(tvstd))
    assert (
        v.cl().sub(vstd).abs().max() < 1e-10
    )  # usually v == vstd, some compilers might give slightly different results
    # This check is disabled on GPU because fast imem is not implemented on
    # GPU: https://github.com/BlueBrain/CoreNeuron/issues/197
    assert (coreneuron.gpu or i_mem.cl().sub(i_memstd).abs().max() < 1e-10)
    assert (h.Vector(tran_std).sub(h.Vector(tran)).abs().max() < 1e-10)
Exemplo n.º 26
0
def run(argv=None):
    """Run a ring network simulation. Additional arguments on command line can
    be any Python statement to execute, but strings in the form 
    ``"sim_var['<var>']=x"`` will run the simulation with a modification of 
    those parameters."""
    sim_var = process_args(argv)
    pc = h.ParallelContext()
    ring = Ring(sim_var['N'], sim_var['stim_w'], sim_var['stim_spike_num'],
                sim_var['syn_w'], sim_var['syn_delay'])
    pc.set_maxstep(10)
    h.stdinit()
    h.dt = 0.025  # Fixed dt
    pc.psolve(100)
    ring.write_spikes(sim_var['spike_out_file'])

    # After we are done, re-sort the file by spike times.
    exec_cmd = ('sort -k 1n,1n -k 2n,2n ' + sim_var['spike_out_file'] + ' > ' +
                'sorted_' + sim_var['spike_out_file'])
    os.system(exec_cmd)
Exemplo n.º 27
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)
Exemplo n.º 28
0
def test_direct_memory_transfer():
    h('''create soma''')
    h.soma.L = 5.6419
    h.soma.diam = 5.6419
    h.soma.insert("hh")
    ic = h.IClamp(h.soma(.5))
    ic.delay = .5
    ic.dur = 0.1
    ic.amp = 0.3

    #for testing external mod file
    h.soma.insert("Sample")

    h.cvode.use_fast_imem(1)
    h.cvode.cache_efficient(1)

    v = h.Vector()
    v.record(h.soma(.5)._ref_v, sec=h.soma)
    i_mem = h.Vector()
    i_mem.record(h.soma(.5)._ref_i_membrane_, sec=h.soma)
    tv = h.Vector()
    tv.record(h._ref_t, sec=h.soma)
    h.run()
    vstd = v.cl()
    tvstd = tv.cl()
    i_memstd = i_mem.cl()
    # Save current (after run) value to compare with transfer back from coreneuron
    tran_std = [h.t, h.soma(.5).v, h.soma(.5).hh.m]

    from neuron import coreneuron
    coreneuron.enable = True

    pc = h.ParallelContext()
    h.stdinit()
    pc.psolve(h.tstop)
    tran = [h.t, h.soma(.5).v, h.soma(.5).hh.m]

    assert (v.eq(vstd))
    assert (tv.eq(tvstd))
    assert (v.cl().sub(vstd).abs().max() < 1e-10)
    assert (i_mem.cl().sub(i_memstd).abs().max() < 1e-10)
    assert (h.Vector(tran_std).sub(h.Vector(tran)).abs().max() < 1e-10)
Exemplo n.º 29
0
    def set_init_conditions(self):
        '''
        Set up the initial conditions: either read from the h.SaveState or from config["condidtions"]
        '''

        pc.set_maxstep(10)
        h.stdinit()

        self.tstep = int(round(h.t / h.dt))
        self.tstep_start_block = self.tstep

        if self._start_from_state == True:
            io.read_state()
            io.print2log0('Read the initial state saved at t_sim: %.2f ms' %
                          (h.t))

        else:
            h.v_init = self.conf["conditions"]["v_init"]

        h.celsius = self.conf["conditions"]["celsius"]
Exemplo n.º 30
0
    def run(mode):
        pc.set_maxstep(10)
        h.stdinit()
        if mode == 0:
            pc.psolve(h.tstop)
        elif mode == 1:
            while h.t < h.tstop:
                pc.psolve(h.t + 1.0)
        else:
            while h.t < h.tstop:
                h.continuerun(h.t + 0.5)
                pc.psolve(h.t + 0.5)
        tran = [h.t, h.soma(0.5).v, h.soma(0.5).hh.m]

        assert tv.eq(tvstd)
        assert (
            v.cl().sub(vstd).abs().max() < 1e-10
        )  # usually v == vstd, some compilers might give slightly different results
        assert i_mem.cl().sub(i_memstd).abs().max() < 1e-10
        assert h.Vector(tran_std).sub(h.Vector(tran)).abs().max() < 1e-10
Exemplo n.º 31
0
def runring(ring, pc, comm, tstop=100):
    pc.set_maxstep(10)
    h.stdinit()
    pc.psolve(tstop)
    ring.vecdict_to_pydict(ring.voltage_tvec, 't')
    ring.vecdict_to_pydict(ring.voltage_recvec, 'rec')
    nhost = int(pc.nhost())
    #Use MPI Gather instead:
    #all_dicts = pc.py_alltoall([ring.pydicts for i in range(nhost)])
    all_dicts = comm.gather(ring.pydicts, root=0)
    if int(pc.id()) == 0:
        t = {
            key: value
            for dict in all_dicts for key, value in dict['t'].iteritems()
        }
        rec = {
            key: value
            for dict in all_dicts for key, value in dict['rec'].iteritems()
        }
        return {'t': t, 'rec': rec}
    return None
Exemplo n.º 32
0
def myrun():
    global fit  # pointer to FinitializeHandler needs to be global so doesn't disappear
    dastart = datetime.now()
    print 'started at:', dastart
    if dconf['useWM']: setupWMInputs()
    h.stdinit()
    ca[er].concentration = dconf['caerinit']  # 100e-6
    ca[cyt].concentration = dconf['cacytinit']  # 100e-6
    if dconf['cvodeactive']: h.cvode.re_init()
    h.continuerun(h.t + tstop)  # run for tstop
    daend = datetime.now()
    print 'finished ', tstop, ' ms sim at:', daend
    dadiff = daend - dastart
    print 'runtime:', dadiff, '(', tstop / 1e3, ' s)'
    # concatenate the results so can view/save all at once
    global lspks, lids
    lspks, lids = array([]), array([])
    for i in xrange(len(ltimevec)):
        lspks = concatenate((lspks, ltimevec[i]))
        lids = concatenate((lids, lidvec[i]))
    ion()
    plotnew(xl=(9.9, 11))
    def checkSpontaneous(self, parameters):
        h.load_file('stdrun.hoc')
        h.load_file('negative_init.hoc')
        tstop = 500
        dt = 0.025
        h.stdinit()
        h.celsius = 37.0
        h.tstop = tstop
        h.v_init = -65

        # Instantiate and parameterize cells
        testCell = cell.Cell(0, (0, 0), self.synvars, 'granulecell',
                             'output0_updated.swc')
        self.parameterizeCell(testCell, parameters)

        # Instrument cells
        tvec = h.Vector()
        nc = testCell.connect_pre(None, 0, 0)
        nc.record(tvec)

        # Run simulation
        h.run()
        if len(tvec) > 0:
            self.spontaneous_flag = 1
Exemplo n.º 34
0
 def sim(self):
     tMax = self.gettMax()
     tData = 0
     tNoise = 0
     h.stdinit()
     x = h.Vector()
     Data = []
     while tData < tMax:
         noiseTimes = [] 
         tData += self.Mdt
         if tData > tMax:
             tData = tMax
         while tNoise < min(tMax,tData):
             tNoise += self.Ndt
             noiseTimes.append(tNoise)
             if tNoise > tMax:
                 tNoise = tMax
             h.continuerun(tNoise)
             cvodewrap.states(x)
             x.x[0] += self.sp*(self.evalW(tNoise) - self.evalW(tNoise-self.Ndt))
             cvodewrap.yscatter(x)
             cvodewrap.re_init()
         Data.append([noiseTimes, x.x[0] + self.sm*self.evalM(tData)])
     return Data 
Exemplo n.º 35
0
def gap_junction_test (tree, v_init):
    
    h('objref gjlist, cells, Vlog1, Vlog2')

    h.pc = h.ParallelContext()
    h.cells  = h.List()
    h.gjlist = h.List()
    
    cell1 = cells.make_neurotree_cell ("MOPPCell", neurotree_dict=tree)
    cell2 = cells.make_neurotree_cell ("MOPPCell", neurotree_dict=tree)

    h.cells.append(cell1)
    h.cells.append(cell2)

    ggid        = 20000000
    source      = 10422930
    destination = 10422670
    srcbranch   = 1
    dstbranch   = 2
    weight      = 5.4e-4

    stimdur     = 500
    tstop       = 2000
    
    h.pc.set_gid2node(source, int(h.pc.id()))
    nc = cell1.connect2target(h.nil)
    h.pc.cell(source, nc, 1)

    h.pc.set_gid2node(destination, int(h.pc.id()))
    nc = cell2.connect2target(h.nil)
    h.pc.cell(destination, nc, 1)

    stim1 = h.IClamp(cell1.sections[0](0.5))
    stim1.delay = 250
    stim1.dur = stimdur
    stim1.amp = -0.1

    stim2 = h.IClamp(cell2.sections[0](0.5))
    stim2.delay = 500+stimdur
    stim2.dur = stimdur
    stim2.amp = -0.1

    log_size = old_div(tstop,h.dt) + 1
    
    h.tlog = h.Vector(log_size,0)
    h.tlog.record (h._ref_t)

    h.Vlog1 = h.Vector(log_size)
    h.Vlog1.record (cell1.sections[0](0.5)._ref_v)

    h.Vlog2 = h.Vector(log_size)
    h.Vlog2.record (cell2.sections[0](0.5)._ref_v)
    
    h.mkgap(h.pc, h.gjlist, source, srcbranch, ggid, ggid+1, weight)
    h.mkgap(h.pc, h.gjlist, destination, dstbranch, ggid+1, ggid, weight)

    h.pc.setup_transfer()
    h.pc.set_maxstep(10.0)

    h.stdinit()
    h.finitialize(v_init)
    h.pc.barrier()

    h.tstop = tstop
    h.pc.psolve(h.tstop)

    f=open("MOPPCellGJ.dat",'w')
    for (t,v1,v2) in zip(h.tlog,h.Vlog1,h.Vlog2):
        f.write("%f %f %f\n" % (t,v1,v2))
    f.close()
Exemplo n.º 36
0
 def run_simulation(self):
     start = h.startsw()
     h.stdinit()
     self.pc.psolve(self.tstop)
     self.pc.barrier()
     self.calc_time = h.startsw() - start
Exemplo n.º 37
0
                        'noise': inputProps['poissonNoise']},
                       connectionProps)
    n.addSomaticVoltageRecorder()
    stim = h.IClamp(n.soma(0.5))
    stim.dur = np.random.uniform(high=inputProps['initialPulseDur'])
    stim.amp = np.random.uniform(low=-inputProps['initialPulseAmp'],high=inputProps['initialPulseAmp'])
    stim.delay = np.random.uniform(high=inputProps['initialPulseDelay'])
    initialPulses.append(stim)

logger('Started the simulation...', myId)
# run the simulation    
h.load_file('stdrun.hoc')
h.tstop = simulationProps['tend']
h.dt = simulationProps['dt']
pc.set_maxstep(1)
h.stdinit()
pc.psolve(simulationProps['tend'])
pc.barrier()
# the simulation is finished.

logger('Saving data...', myId)
# save everything.
if myId == 0:
    fid = h5.H5File(outfile, 'w', 'Common input simulation')
    fid.createGroup('/','Properties')
    fid.writeTable('/Properties', 'Simulation', SimulationProps, 'Simulation properties', simulationProps)
    fid.createGroup('/','Input')
    fid.writeTable('/Input', 'Properties', InputProps, 'Input properties', inputProps)
    fid.writeArray('/Input', 'PresynapticSpikes', tbl.Float64Atom(), fixedSpikeTimes)
    fid.close()
pc.barrier()
Exemplo n.º 38
0
def prun(tstop):
  ''' simulation control '''
  pc.set_maxstep(10)
  h.stdinit()
  pc.psolve(tstop)