def runSound(self, parallelize=False): self.civ = {} self.iiv = [] if not parallelize: pass if parallelize: nworker = 16 varsg = np.linspace( 0.25, 2.0, int((2.0 - 0.25) / 0.25) + 1 ) #[0.5, 0.75, 1.0, 1.5, 2.0] # covary Ih and gklt in constant ratio self.npost = len(varsg) nrep = 25 tasks = range(self.npost) results = [None] * len(tasks) ivc = [None] * len(tasks) gklts = np.zeros(len(varsg)) ghs = np.zeros(len(varsg)) start = time.time() seed = 0 cf = 16000. f0 = 16000. rundur = 0.25 # seconds pipdur = 0.1 # seconds dbspl = 50. fmod = 40. dmod = 0. stimulus = 'tone' # with mp.Parallelize(enumerate(tasks), results=results, workers=nworker, progressDialog='processing in parallel..') as tasker: with mp.Parallelize(enumerate(tasks), results=results, workers=nworker) as tasker: for i, x in tasker: post_cell = cells.Bushy.create(species=species) h.celsius = 34 self.temp = h.celsius refgbar_klt = post_cell.soma().klt.gbar refgbar_ih = post_cell.soma().ihvcn.gbar gklts[i] = refgbar_klt * varsg[i] ghs[i] = refgbar_ih * varsg[i] post_cell.soma().klt.gbar = gklts[i] post_cell.soma().ihvcn.gbar = ghs[i] post_cell.initial_mechanisms = None # forget the mechanisms we set up initially post_cell.save_all_mechs( ) # and save new ones because we are explicitely varying them self.make_stimulus(stimulus=stimulus, cf=cf, f0=f0, rundur=rundur, pipdur=pipdur, dbspl=50., simulator=None, fmod=fmod, dmod=dmod) pre_cells = [] synapses = [] for n in range(self.npre): pre_cells.append(cells.DummySGC(cf=cf, sr=2)) synapses.append(pre_cells[n].connect(post_cell, type=synapseType)) v_reps = [] i_reps = [] p_reps = [] # pre spike on 0'th sgc for j in range(nrep): for prec in range(len(pre_cells)): pre_cells[prec].set_sound_stim(self.stim, seed=seed) seed += 1 # for i in range(synapses[-1].terminal.n_rzones): # xmtr['xmtr%04d'%j] = h.Vector() # xmtr['xmtr%04d'%j].record(synapses[-1].terminal.relsite._ref_XMTR[i]) # j = j + 1 #synapses[-1].terminal.relsite.Dep_Flag = False # no depression in these simulations # # Run simulation # post_cell.vm0 = None post_cell.cell_initialize() # set starting voltage... post_cell.soma(0.5).v = post_cell.vm0 h.dt = 0.02 h.t = 0 # run a bit to find true stable rmp h.tstop = 20. h.batch_save() h.batch_run(h.tstop, h.dt, 'v.dat') self['t'] = h._ref_t # set up recordings self['v_post%02d' % j] = post_cell.soma(0.5)._ref_v h.finitialize() # init and instantiate recordings print 'running %d' % i h.t = 0. h.tstop = rundur * 1000. # rundur is in seconds. post_cell.check_all_mechs( ) # make sure no further changes were introduced before run. h.batch_run(h.tstop, h.dt, 'v.dat') v_reps.append(self['v_post%02d' % j]) i_reps.append(0. * self['v_post%02d' % j]) p_reps.append(pre_cells[0]._stvec.to_python()) tasker.results[i] = { 'v': v_reps, 'i': i_reps, 't': self['t'], 'pre': pre_cells[0]._stvec.to_python() } print("\nParallel time: %d workers, %0.2f sec" % (nworker, time.time() - start)) cell_info = {'gklt': gklts, 'gh': ghs} stim_info = { 'nreps': nrep, 'cf': cf, 'f0': f0, 'rundur': rundur, 'pipdur': pipdur, 'dbspl': dbspl, 'fmod': fmod, 'dmod': dmod } res = {'cells': cell_info, 'stim': stim_info, 'results': results} if runname is not None: f = open(runname, 'w') pickle.dump(res, f) f.close()
def run(self, mode='IV', cf=16e3, temp=34.0, dt=0.025, stimamp=0, iinj=[1.0]): self.dt = dt self.temp = temp self.make_cells(cf, temp, dt) print dir(self.pre_cells[0]) seed = 0 j = 0 if mode == 'sound': self.make_stimulus(stimulus='tone') for np in range(len(self.pre_cells)): self.pre_cells[np].set_sound_stim(self.stim, seed=seed) seed += 1 synapses.append(pre_cells[-1].connect(post_cell, post_opts={ 'AMPAScale': 2.0, 'NMDAScale': 2.0 }, type=synapseType)) for i in range(synapses[-1].terminal.n_rzones): xmtr['xmtr%04d' % j] = h.Vector() xmtr['xmtr%04d' % j].record( synapses[-1].terminal.relsite._ref_XMTR[i]) j = j + 1 synapses[ -1].terminal.relsite.Dep_Flag = False # no depression in these simulations print 'setup to run' self.stim_params = [] self.istim = [] self.istims = [] if mode == 'pulses': for i, pre_cell in enumerate(self.pre_cells): stim = {} stim['NP'] = 10 stim['Sfreq'] = 100.0 # stimulus frequency stim['delay'] = 10.0 stim['dur'] = 0.5 stim['amp'] = stimamp stim['PT'] = 0.0 stim['dt'] = dt (secmd, maxt, tstims) = make_pulse(stim) self.stim_params.append(stim) stim['amp'] = 0. (secmd2, maxt2, tstims2) = make_pulse(stim) # istim current pulse train istim = h.iStim(0.5, sec=pre_cell.soma) i_stim_vec = h.Vector(secmd) self.istim.append((istim, i_stim_vec)) self['istim%02d' % i] = istim._ref_i self.postpars = [] self.poststims = [] if mode == 'IV': for i, post_cell in enumerate(self.post_cells): pstim = {} pstim['NP'] = 1 pstim['Sfreq'] = 100.0 # stimulus frequency pstim['delay'] = 10.0 pstim['dur'] = 100 pstim['amp'] = iinj[0] pstim['PT'] = 0.0 pstim['dt'] = dt (secmd, maxt, tstims) = make_pulse(pstim) self.postpars.append(pstim) # istim current pulse train pistim = h.iStim(0.5, sec=post_cell.soma) pi_stim_vec = h.Vector(secmd) self.poststims.append((pistim, pi_stim_vec)) self['poststim%02d' % i] = pistim._ref_i # # Run simulation # h.celsius = temp self.temp = temp # first find rmp for each cell for m in range(self.npost): self.post_cells[m].vm0 = None self.post_cells[m].cell_initialize() # set starting voltage... self.post_cells[m].soma(0.5).v = self.post_cells[m].vm0 h.dt = 0.02 h.t = 0 # run a bit to find true stable rmp h.tstop = 20. h.batch_save() h.batch_run(h.tstop, h.dt, 'v.dat') # order matters: don't set these up until we need to self['t'] = h._ref_t # set up recordings if mode == 'pulses': for i in range(self.npre): self.istim[i][1].play(self.istim[i][0]._ref_i, dt, 0) self['v_pre%02d' % i] = self.pre_cells[i].soma(0.5)._ref_v for m in range(self.npost): if mode == 'IV': self.poststims[m][1].play(self.poststims[m][0]._ref_i, dt, 0) self['v_post%02d' % m] = self.post_cells[m].soma(0.5)._ref_v h.finitialize() # init and instantiate recordings print 'running' h.t = 0. h.tstop = 200. h.batch_run(h.tstop, h.dt, 'v.dat')