Changeset 408

Show
Ignore:
Timestamp:
07/10/08 12:45:18 (1 month ago)
Author:
pierre
Message:

Start to play with nest2.py in a distributed simulation framework. Add a method to have an estimate of the firing rate in a distributed context (frame/thread). More generally, after having done some code profiling, I noticed that setting the values of the parameters was very slow in nest2, due to the fact that in the common.py file, each time we want to set a parameter, we get all the native_parameters, translate them, and then only modify a single value. I've changed therefore the common.py file and the results speed up greatly the building of networks. Moreover, checking the delays in the connector should be an option. Because it also slows down notably the loops. What about a tag check_connectionc, added to the Connector object, that will be used to check either weights/delays but that can also skip it if the user know what he's doing ?

Files:

Legend:

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

    r407 r408  
    125125    def set_parameters(self, **parameters): 
    126126        """Set cell parameters, given as a sequence of parameter=value arguments.""" 
    127         all_parameters = self.get_parameters() 
    128         all_parameters.update(parameters) 
     127        #all_parameters = self.get_parameters() 
     128        #all_parameters.update(parameters) 
    129129        if self.is_standard_cell(): 
    130             parameters = self.cellclass.translate(all_parameters) 
     130            parameters = self.cellclass.translate(parameters) 
    131131        self.set_native_parameters(parameters) 
    132132     
     
    315315        parameters = cls.checkParameters(parameters, with_defaults=False) 
    316316        native_parameters = {} 
    317         for name,D  in cls.translations.items(): 
     317        for name,value in parameters.items(): 
     318            D = cls.translations[name] 
     319        #for name,D  in cls.translations.items(): 
    318320            pname = D['translated_name'] 
    319321            try: 
     
    12281230    """Base class for Connector classes.""" 
    12291231     
    1230     def __init__(self, weights=0.0, delays=None): 
     1232    def __init__(self, weights=0.0, delays=None, check_connections=False): 
    12311233        self.w_index = 0 # should probably use a generator 
    12321234        self.d_index = 0 # rather than storing these values 
    12331235        self.weights = weights 
    12341236        self.delays = delays 
     1237        self.check_connections = check_connections 
    12351238        if delays is None: 
    12361239            self.delays = get_min_delay() 
     
    12521255        else: 
    12531256            raise Exception("weights is of type %s" % type(self.weights)) 
    1254         #assert numpy.all(weights>=0), "Weight values must be positive" 
    12551257        self.w_index += N 
    12561258        return weights 
     
    12681270        else: 
    12691271            raise Exception("delays is of type %s" % type(self.delays)) 
    1270         assert numpy.all(delays >= get_min_delay()), \ 
    1271                "Delay values must be greater than or equal to the minimum delay %g. The smallest delay is %g." % (get_min_delay(), delays.min()) 
    1272         assert numpy.all(delays <= get_max_delay()), \ 
    1273                "Delay values must be less than or equal to the maximum delay %s. The largest delay is %s" % (get_max_delay(), delays.max())                                                                                               
     1272        if self.check_connections: 
     1273            assert numpy.all(delays >= get_min_delay()), \ 
     1274            "Delay values must be greater than or equal to the minimum delay %g. The smallest delay is %g." % (get_min_delay(), delays.min()) 
     1275            assert numpy.all(delays <= get_max_delay()), \ 
     1276            "Delay values must be less than or equal to the maximum delay %s. The largest delay is %s" % (get_max_delay(), delays.max())                                                                                               
    12741277        self.d_index += N 
    12751278        return delays 
     
    14061409            d = 1e12; assert 0 <= eval(d_expression), eval(d_expression) 
    14071410        except ZeroDivisionError: 
    1408             print d_expression 
    1409             raise 
     1411            raise Exception("Error in the distance expression %s" %d_expression) 
    14101412        self.d_expression = d_expression 
    14111413        # We will use the numpy functions, so we need to parse the function 
  • trunk/src/nest1/__init__.py

    r399 r408  
    12631263        print "\n------- Projection description -------" 
    12641264        print "Projection %s from %s [%d cells] to %s [%d cells]" %(self.label, self.pre.label, len(self.pre.cell),self.post.label, len(self.post.cell)) 
    1265         print "Connector used is %s : " %self._method 
     1265        print "\t| Connector : " %self._method 
    12661266        if isinstance(self._method.weights,RandomDistribution): 
    1267           print "\t| Weights are drawn from %s distribution with parameters %s "%(self._method.weights.name, self._method.weights.parameters) 
    1268         else: 
    1269           print "\t| Weights: ", self._method.weights 
     1267          print "\t| Weights : drawn from %s distribution with params %s "%(self._method.weights.name, self._method.weights.parameters) 
     1268        else: 
     1269          print "\t| Weights : ", self._method.weights 
    12701270        if isinstance(self._method.delays,RandomDistribution): 
    1271           print "\t| Delays are drawn from %s distribution with parameters %s " %(self._method.delays.name, self._method.delays.parameters) 
    1272         else: 
    1273           print "\t| Delays: ", self._method.delays 
    1274         print "\t| Plasticity: ", self._plasticity_model 
     1271          print "\t| Delays : drawn from %s distribution with params %s " %(self._method.delays.name, self._method.delays.parameters) 
     1272        else: 
     1273          print "\t| Delays : ", self._method.delays 
     1274        print "\t| Plasticity : ", self._plasticity_model 
    12751275        print "\t --> %d connections have been created for this projection" %len(self) 
    1276         print "To check, here are the parameters of one connection from this projection" 
    1277         print "\tsource\ttarget" 
    1278         print "\t%d\t%d" %(self._sources[0], self._targets[0]) 
    1279         print "\t| Weight: ", pynest.getWeight([self._sources[0]],self._targetPorts[0]) 
    1280         print "\t| Delay: ", pynest.getDelay([self._sources[0]], self._targetPorts[0]) 
     1276        print "\tParameters of connection from %d to %d" %(self._sources[0], self._targets[0]) 
     1277        print "\t| weights : ", pynest.getWeight([self._sources[0]],self._targetPorts[0]) 
     1278        print "\t| delays : ", pynest.getDelay([self._sources[0]], self._targetPorts[0]) 
    12811279         
    12821280        print "---- End of Projection description -----" 
  • trunk/src/nest2/__init__.py

    r407 r408  
    1010from pyNN.random import * 
    1111from pyNN import recording 
    12 import numpy, types, sys, shutil, os, logging, copy, tempfile 
     12import numpy, types, sys, shutil, os, logging, copy, tempfile, re 
    1313from math import * 
    1414from pyNN.nest2.cells import * 
     
    515515            os.remove(nest_filename) 
    516516    if gather and len(node_list) > 1: 
     517        #if rank() == 0: 
    517518        raise Exception("gather not yet implemented") 
    518519    return merged_filename 
     
    571572            self.cell_local = self.cell[numpy.array(nest.GetStatus(self.cell.tolist(),'local'))] 
    572573            self.first_id = self.cell.reshape(self.size,)[0] 
    573  
    574574            for id in self.cell: 
    575575                id.parent = self 
     
    864864        Returns the mean number of spikes per neuron. 
    865865        """ 
    866         n_spikes = nest.GetStatus(self.recorders['spikes']._device,'n_events')[0] 
     866         
     867        ## Routine to give an average firing rate over all the threads/nodes 
     868        ## This is a rough approximation, because in fact each nodes is only multiplying  
     869        ## the frequency of the recorders by the number of processes. To do better, we need a MPI 
     870        ## package to send informations to node 0. 
     871        node_list = range(nest.GetStatus([0], "total_num_virtual_procs")[0]) 
     872        n_spikes  = 0 
     873        for node in node_list: 
     874            nest.sps(self.recorders['spikes']._device[0]) 
     875            nest.sr("%d GetAddress %d append" %(self.recorders['spikes']._device[0], node)) 
     876            nest.sr("GetStatus /n_events get") 
     877            n_spikes += nest.spp() 
    867878        n_rec = len(self.recorders['spikes'].recorded) 
    868879        return float(n_spikes)/n_rec 
     
    13611372        print "\n------- Projection description -------" 
    13621373        print "Projection %s from %s [%d cells] to %s [%d cells]" %(self.label, self.pre.label, len(self.pre.cell),self.post.label, len(self.post.cell)) 
    1363         print "Connector used is %s : " %self._method 
     1374        print "\t| Connector : %s" %self._method 
    13641375        if isinstance(self._method.weights,RandomDistribution): 
    1365           print "\t| Weights are drawn from %s distribution with parameters %s "%(self._method.weights.name, self._method.weights.parameters) 
    1366         else: 
    1367           print "\t| Weights: ", self._method.weights 
     1376          print "\t| Weights : drawn from %s distribution with params %s "%(self._method.weights.name, self._method.weights.parameters) 
     1377        else: 
     1378          print "\t| Weights : ", self._method.weights 
    13681379        if isinstance(self._method.delays,RandomDistribution): 
    1369           print "\t| Delays are drawn from %s distribution with parameters %s " %(self._method.delays.name, self._method.delays.parameters) 
     1380          print "\t| Delays : drawn from %s distribution with params %s " %(self._method.delays.name, self._method.delays.parameters) 
    13701381        else: 
    13711382          print "\t| Delays: ", self._method.delays 
    1372         print "\t| Plasticity: ", self._plasticity_model 
    1373         print "\t --> %d connections have been created for this projection" %len(self) 
    1374         print "To check, here are the parameters of one connection from this projection" 
    1375         print "\tsource\ttarget\tport" 
    1376         print "\t%d\t%d\t%d" %(self._sources[0], self._targets[0], self._target_ports[0]) 
     1383        print "\t| Plasticity : ", self._plasticity_model 
     1384        print "\t ----> %d connections have been created for this projection" %len(self) 
     1385        print "\tParameters of connection from %d to %d [port %d]" %(self._sources[0], self._targets[0], self._target_ports[0]) 
    13771386        dict = nest.GetConnections([self.pre.cell.flat[0]], self._plasticity_model)[0] 
    13781387        for i in xrange(len(self._targets)): 
  • trunk/src/nest2/connectors.py

    r406 r408  
    8787     
    8888    def connect(self, projection): 
    89         postsynaptic_neurons = projection.post.cell_local.flatten() 
    90         npost = projection.post.size 
     89       postsynaptic_neurons = projection.post.cell.flatten() 
     90        npost = len(postsynaptic_neurons) 
    9191        for pre in projection.pre.cell.flat: 
    9292            if projection.rng: 
     
    120120            print "Periodic boundaries activated and set to size ", periodic_boundaries 
    121121        postsynaptic_neurons = projection.post.cell.flatten() # array 
    122         presynaptic_neurons  = projection.pre.cell.flat # iterator  
     122        #postsynaptic_neurons = projection.post.cell_local 
    123123        # what about NativeRNG? 
    124124        if projection.rng: 
     
    130130        else: 
    131131            rng = numpy.random 
    132         for pre in presynaptic_neurons
     132        for pre in projection.pre.cell.flat
    133133            # We compute the distances from the post cell to all the others 
    134134            distances = common.distances(pre, projection.post, self.mask,