Changeset 371

Show
Ignore:
Timestamp:
06/18/08 14:02:10 (5 months ago)
Author:
apdavison
Message:

Initia lization of membrane potentials now works in neuron2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/neuron2/__init__.py

    r367 r371  
    3737    simulator but not by others. 
    3838    """ 
    39     global initialised, quit_on_end, running, parallel_context 
     39    global initialised, quit_on_end, running, parallel_context, initializer 
    4040    if not initialised: 
    4141        h('min_delay = 0') 
     
    4444        parallel_context.spike_compress(1,0) 
    4545        cvode = neuron.CVode() 
     46        initializer = Initializer() 
    4647        utility.init_logging("neuron2.log.%d" % rank(), debug) 
    4748        logging.info("Initialization of NEURON (use setup(.., debug=True) to see a full logfile)") 
     
    6970    """Run the simulation for simtime ms.""" 
    7071    global running 
    71     logging.info("Running the simulation for %d ms" % simtime) 
    7272    if not running: 
    7373        running = True 
     
    8080                   "There are connections with delays (%g) shorter than the minimum delay (%g)" % (local_minimum_delay, get_min_delay()) 
    8181    h.tstop = simtime 
     82    logging.info("Running the simulation for %d ms" % simtime) 
    8283    parallel_context.psolve(h.tstop) 
    8384    return get_current_time() 
     
    165166    for id in all_ids[mask_local]: 
    166167        id.cellclass = cellclass 
     168    initializer.register(*all_ids[mask_local]) 
    167169    if len(all_ids) == 1: 
    168170        all_ids = all_ids[0] 
     
    281283        label is an optional name for the population. 
    282284        """ 
    283         ##global gid_counter 
    284285        common.Population.__init__(self, dims, cellclass, cellparams, label) 
    285286        self.recorders = {'spikes': Recorder('spikes', population=self), 
    286287                          'v': Recorder('v', population=self)} 
    287         ##self.first_id = gid_counter 
    288         ##self.last_id = gid_counter + self.size 
    289288        self.label = self.label or 'population%d' % Population.nPop 
    290289        self.celltype = cellclass(cellparams) 
     
    294293        # All are stored in a single numpy array for easy lookup by address 
    295294        # The local cells are also stored in a list, for easy iteration 
    296          
    297295        self._all_ids, self._mask_local, self.first_id, self.last_id = _create(self.celltype, self.size, parent=self) 
    298         ##self._all_ids = numpy.array([id for id in range(self.first_id, self.last_id)], ID) #.reshape(self.dim) 
    299         ### _mask_local is used to extract those elements from arrays that apply to the cells on the current node, e.g. for tset() 
    300         ##self._mask_local = self._all_ids%num_processes()==0 # round-robin distribution of cells between nodes 
    301         ##for i,(id,is_local) in enumerate(zip(self._all_ids, self._mask_local)): 
    302         ##    if is_local: 
    303         ##        self._all_ids[i] = ID(id) 
    304         # _local_ids is a list containing only those cells that exist on the current node 
    305296        self._local_ids = self._all_ids[self._mask_local] 
    306297        self._all_ids = self._all_ids.reshape(self.dim) 
    307298        self._mask_local = self._mask_local.reshape(self.dim) 
    308299         
    309          
    310         ##for id in self._local_ids: 
    311         ##    id._build_cell(self.celltype, parent=self) 
    312         #gid_counter += self.size 
     300        initializer.register(self) 
    313301        Population.nPop += 1 
    314302        logging.info(self.describe('Creating Population "%(label)s" of shape %(dim)s, '+ 
  • trunk/src/neuron2/cells.py

    r367 r371  
    8181        if self.v_init is None: 
    8282            self.v_init = self.v_rest 
    83              
    84         # need to deal with FinitializeHandler for v_init? 
    85         self.fih = neuron.h.FInitializeHandler("memb_init()", self) 
    86         self.fih2 = neuron.h.FInitializeHandler('print "kjyuyv"') 
    8783        self.spiketimes = neuron.Vector(0) 
    88         self.fih.allprint() 
    8984 
    9085    def __set_tau_m(self, value): 
     
    124119     
    125120    def memb_init(self, v_init=None): 
    126         print "memb_init() called" 
    127121        if v_init: 
    128122            self.v_init = v_init 
    129         self.v = v_init 
    130      
     123        self.seg.v = self.v_init 
    131124 
    132125 
  • trunk/src/neuron2/utility.py

    r367 r371  
    11from pyNN import __path__ as pyNN_path 
     2from pyNN import common 
    23import platform 
    34import logging 
     
    8788        self.population_list = [] 
    8889        neuron.h('objref initializer') 
    89         neuron.h('initializer = PythonObject(self)') 
     90        neuron.h.initializer = self 
     91        self.fih = h.FInitializeHandler("initializer.initialize()") 
     92     
     93    def register(self, *items): 
     94        for item in items: 
     95            if isinstance(item, common.Population): 
     96                if "Source" not in item.__class__.__name__: 
     97                    self.population_list.append(item) 
     98            else: 
     99                if hasattr(item._cell, "memb_init"): 
     100                    self.cell_list.append(item) 
    90101     
    91102    def initialize(self): 
     103        logging.info("Initializing membrane potential of %d cells and %d Populations." % \ 
     104                     (len(self.cell_list), len(self.population_list))) 
    92105        for cell in self.cell_list: 
    93             cell.memb_init() 
    94  
     106            cell._cell.memb_init() 
     107        for population in self.population_list: 
     108            for cell in population: 
     109                cell._cell.memb_init() 
    95110 
    96111load_mechanisms()