Changeset 365
- Timestamp:
- 06/13/08 18:17:09 (5 months ago)
- Files:
-
- trunk/src/neuron/__init__.py (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/neuron/__init__.py
r364 r365 48 48 hit is it to replace integers with ID objects? 49 49 """ 50 51 #def __init__(self, n): 52 # common.ID.__init__(self, n) 53 # self.hocname = None 50 54 51 def __init__(self, n): 55 52 int.__init__(n) … … 66 63 67 64 def _hoc_cell(self): 65 """Returns the hoc object corresponding to the cell with this id.""" 68 66 assert self in gidlist, "Cell %d does not exist on this node" % self 69 67 if self.parent: 70 68 hoc_cell_list = getattr(h, self.parent.label) 71 69 try: 72 #cell = hoc_cell_list.object(self - self.parent.gid_start)73 70 list_index = self.parent.gidlist.index(self) 74 71 cell = hoc_cell_list.object(list_index) … … 313 310 new_ids = list( ids.difference(self.recorded) ) 314 311 self.recorded = self.recorded.union(ids) 315 if self.population is None: 316 cell_template = "cell%d" 317 id_list = new_ids 318 else: 319 cell_template = "%s.object(%s)" % (self.population.hoc_label, "%d") 320 id_list = self.population.gidlist 312 321 313 if self.variable == 'spikes': 322 template = 'tmp = %s.record(1)' % cell_template 323 elif self.variable == 'v': 324 template = 'tmp = %s.record_v(1,%g)' % (cell_template, get_time_step()) 325 hoc_commands = [] 326 for src in new_ids: 327 hoc_commands += [template % id_list.index(src)] 328 hoc_execute(hoc_commands, "---Recorder.record() ---") 314 for cell in new_ids: 315 cell._hoc_cell().record(1) 316 elif self.variable == 'v': 317 dt = get_time_step() 318 for cell in new_ids: 319 cell._hoc_cell().record_v(1, dt) 329 320 330 321 def get(self, gather=False): 331 322 """Returns the recorded data.""" 323 # not implemented yet 332 324 data = recording.readArray(filename, sepchar=None) 333 325 data = recording.convert_compatible_output(data, self.population, variable) … … 440 432 441 433 if initialised: 442 h oc_commands = ['dt = %f' % timestep,443 'min_delay = %g' % min_delay]434 h.dt = timestep 435 h.min_delay = min_delay 444 436 running = False 445 437 else: 446 hoc_commands = [ 447 'tmp = xopen("%s")' % os.path.join(pyNN_path[0],'hoc','standardCells.hoc'), 448 'tmp = xopen("%s")' % os.path.join(pyNN_path[0],'hoc','odict.hoc'), 449 'objref pc', 450 'pc = new ParallelContext()', 451 'dt = %f' % timestep, 452 'tstop = 0', 453 'min_delay = %g' % min_delay, 454 'create dummy_section', 455 'access dummy_section', 456 'objref netconlist, nil', 457 'netconlist = new List()', 458 'strdef cmd', 459 'strdef fmt', 460 'objref nc', 461 'objref rng', 462 'objref cell'] 438 tmp = h.xopen(os.path.join(pyNN_path[0],'hoc','standardCells.hoc')) 439 tmp = h.xopen(os.path.join(pyNN_path[0],'hoc','odict.hoc')) 440 h('objref pc') 441 h('pc = new ParallelContext()') 442 h.dt = timestep 443 h('tstop = 0') 444 h('min_delay = %f' % min_delay) 445 #'create dummy_section', 446 # 'access dummy_section', 447 h('objref netconlist, nil') 448 h('netconlist = new List()') 449 h('strdef cmd') 450 h('strdef fmt') 451 h('objref nc') 452 h('objref rng') 453 h('objref cell') 463 454 #---Experimental--- Optimize the simulation time ? / Reduce inter-processors exchanges ? 464 hoc_commands += [ 465 'tmp = pc.spike_compress(1,0)'] 455 tmp = h.pc.spike_compress(1,0) 466 456 if extra_params.has_key('use_cvode') and extra_params['use_cvode'] == True: 467 hoc_commands += [ 468 'objref cvode', 469 'cvode = new CVode()', 470 'cvode.active(1)'] 471 472 hoc_execute(hoc_commands,"--- setup() ---") 473 474 #nhost = HocToPy.get('pc.nhost()','int') 457 h('objref cvode') 458 h('cvode = new CVode()') 459 h.cvode.active(1) 460 475 461 nhost = int(h.pc.nhost()) 476 462 if nhost < 2: 477 463 nhost = 1; myid = 0 478 464 else: 479 #myid = HocToPy.get('pc.id()','int')480 465 myid = int(h.pc.id()) 481 #print "\nHost #%d of %d" % (myid+1, nhost)482 vfilelist = {}483 spikefilelist = {}484 466 485 467 initialised = True … … 492 474 for recorder in recorder_list: 493 475 recorder.write(gather=False, compatible_output=compatible_output) 494 hoc_commands = [] 495 hoc_commands += ['tmp = pc.runworker()', 496 'tmp = pc.done()'] 497 hoc_execute(hoc_commands,"--- end() ---") 476 h.pc.runworker() 477 h.pc.done() 498 478 if quit_on_end: 499 h oc.execute('tmp = quit()') # sometimes needed, sometimes not wanted. Maybe a 'quit_on_end' kwarg for setup?479 h.quit() 500 480 logging.info("Finishing up with NEURON.") 501 481 sys.exit(0) … … 504 484 """Run the simulation for simtime ms.""" 505 485 global running 506 hoc_commands = [] 486 507 487 if not running: 508 488 running = True 509 hoc_commands += ['local_minimum_delay = pc.set_maxstep(10)', 510 'tmp = finitialize()', 511 'tstop = 0'] 512 hoc_execute(hoc_commands,"--- run() ---") 489 h('local_minimum_delay = pc.set_maxstep(10)') 490 h.finitialize() 491 h.tstop = 0 513 492 logging.debug("local_minimum_delay on host #%d = %g" % (myid, h.local_minimum_delay)) 514 493 if nhost > 1: 515 494 assert h.local_minimum_delay >= get_min_delay(),\ 516 495 "There are connections with delays (%g) shorter than the minimum delay (%g)" % (h.local_minimum_delay, get_min_delay()) 517 hoc_commands += ['tstop += %f' % simtime, 518 'tmp = pc.psolve(tstop)'] 519 hoc_execute(hoc_commands,"--- run() ---") 496 h.tstop = simtime 497 h.pc.psolve(h.tstop) 520 498 return get_current_time() 521 499 … … 572 550 #'nc = new NetCon(cell%d.source, nil)' % cell_id, 573 551 'tmp = pc.cell(%d, nc)' % cell_id] 552 #h('tmp = pc.set_gid2node(%d,%d)' % (cell_id, myid)) 553 #h('objref cell%d' % cell_id) 554 #h('cell%d = new %s(%s)' % (cell_id, hoc_name, argstr)) 555 #h('tmp = cell%d.connect2target(nil, nc)' % cell_id) 556 #h('tmp = pc.cell(%d, nc)' % cell_id) 574 557 hoc_execute(hoc_commands, "--- create() ---") 575 558 … … 971 954 # Each node will record N/nhost cells... 972 955 nrec = int(record_from/nhost) 973 if rng: 974 record_from = rng.permutation(self.gidlist) 975 else: 976 record_from = numpy.random.permutation(self.gidlist) 977 # Taken as random in self.gidlist 978 record_from = record_from[0:nrec] 979 record_from = numpy.array(record_from) # is this line necessary? 956 if not rng: 957 rng = numpy.random 958 record_from = rng.permutation(self.gidlist)[0:nrec] # need ID objects, permutation returns integers 959 # need ID objects, permutation returns integers 960 record_from = [self.gidlist.index(i) for i in record_from] 980 961 else: 981 962 raise Exception("record_from must be either a list of cells or the number of cells to record from")

