Changeset 322

Show
Ignore:
Timestamp:
06/04/08 16:38:40 (5 years ago)
Author:
apdavison
Message:

Assorted minor bug-fixes related to parallel simulations

Location:
trunk/src
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/common.py

    r310 r322  
    100100 
    101101    def __getattr__(self, name): 
    102         try: 
    103             val = self.get_parameters()[name] 
    104         except KeyError: 
    105             raise NonExistentParameterError(name, self.cellclass) 
     102        if name in IDMixin.non_parameter_attributes: 
     103            val = self.__getattribute__(name) 
     104        else: 
     105            try: 
     106                val = self.get_parameters()[name] 
     107            except KeyError: 
     108                raise NonExistentParameterError(name, self.cellclass) 
    106109        return val 
    107110     
     
    368371        'tau_m'      :  20.0,   # Membrane time constant in ms. 
    369372        'tau_refrac' :   0.0,   # Duration of refractory period in ms.  
    370         'tau_syn_E'  :   0.3,   # Rise time of the excitatory synaptic alpha function in ms. 
     373        'tau_syn_E'  :   0.5,   # Rise time of the excitatory synaptic alpha function in ms. 
    371374        'tau_syn_I'  :   0.5,   # Rise time of the inhibitory synaptic alpha function in ms. 
    372375        'i_offset'   :   0.0,   # Offset current in nA 
     
    624627 
    625628def get_min_delay(): 
    626     pass 
     629    return 1e12 
     630 
     631def get_max_delay(): 
     632    return -1e12 
    627633 
    628634def num_processes(): 
     
    11641170    # --- Methods for writing/reading information to/from file. ---------------- 
    11651171     
     1172    def getWeights(self, format='list', gather=True): 
     1173        """ 
     1174        Possible formats are: a list of length equal to the number of connections 
     1175        in the projection, a 2D weight array (with zero or None for non-existent 
     1176        connections). 
     1177        """ 
     1178        return _abstract_method(self) 
     1179     
     1180    def getDelays(self, format='list', gather=True): 
     1181        """ 
     1182        Possible formats are: a list of length equal to the number of connections 
     1183        in the projection, a 2D delay array (with None or 1e12 for non-existent 
     1184        connections). 
     1185        """ 
     1186        return _abstract_method(self) 
     1187     
    11661188    def saveConnections(self, filename, gather=False): 
    11671189        """Save connections to file in a format suitable for reading in with the 
     
    12351257        else: 
    12361258            raise Exception("delays is of type %s" % type(self.delays)) 
    1237         assert numpy.all(delays >= get_min_delay()), "Delay values must be greater than the minimum delay %g" %get_min_delay() 
     1259        assert numpy.all(delays >= get_min_delay()), \ 
     1260               "Delay values must be greater than or equal to the minimum delay %g. The smallest delay is %g." % (get_min_delay(), delays.min()) 
     1261        assert numpy.all(delays <= get_max_delay()), \ 
     1262               "Delay values must be less than or equal to the maximum delay %s. The largest delay is %s" % (get_max_delay(), delays.max())                                                                                               
    12381263        self.d_index += N 
    12391264        return delays 
     
    13601385            'xy': [0,1], 'yz': [1,2], 'xz': [0,2], 'xyz': None, None: None} 
    13611386     
    1362     def __init__(self, d_expression, axes=None, scale_factor=1.0, offset=0., 
     1387    def __init__(self, d_expression, axes=None, scale_factor=1.0, offset=0.0, 
    13631388                 periodic_boundaries=False, allow_self_connections=True, 
    13641389                 weights=0.0, delays=None): 
  • trunk/src/nest2/__init__.py

    r318 r322  
    285285def get_max_delay(): 
    286286    return nest.GetSynapseDefaults('static_synapse')['max_delay'] 
     287common.get_max_delay = get_max_delay 
    287288 
    288289def num_processes(): 
     
    479480 
    480481    if compatible_output: 
    481         if gather == False or nest.Rank() == 0: # if we gather, only do this on the master node 
     482        if gather == False: 
     483            user_filename += '.%d' % rank() 
     484        if gather == False or rank() == 0: # if we gather, only do this on the master node 
    482485            recording.write_compatible_output(nest_filename, user_filename, 
    483486                                              population, get_time_step()) 
     
    711714            raise Exception('rset() not yet implemented for NativeRNG') 
    712715        else: 
    713             rarr = rand_distr.next(n=len(self.cell_local)) 
    714             assert len(rarr) == len(self.cell_local) 
     716            #rarr = rand_distr.next(n=len(self.cell_local)) 
     717            rarr = rand_distr.next(n=self.size) 
     718            print rank(), self.cell_local[:5], self.cell_local[-5:], len(rarr), len(self.cell_local) 
     719            assert len(rarr) >= len(self.cell_local), "The length of rarr (%d) must be greater than that of cell_local (%d)" % (len(rarr), len(self.cell_local)) 
     720            rarr = rarr[:len(self.cell_local)] 
    715721            for cell,val in zip(self.cell_local, rarr): 
    716722                setattr(cell, parametername, val) 
     
    12691275        """Save connections to file in a format suitable for reading in with the 
    12701276        'fromFile' method.""" 
     1277        if gather == True: 
     1278            raise Exception("saveConnections(gather=True) not yet supported") 
     1279        else: 
     1280            filename += '.%d' % rank() 
    12711281        f = open(filename, 'w', DEFAULT_BUFFER_SIZE) 
    12721282        weights = []; delays = [] 
  • trunk/src/nest2/connectors.py

    r304 r322  
    55 
    66from pyNN import common 
    7 from pyNN.nest2.__init__ import nest, is_number 
     7from pyNN.nest2.__init__ import nest, is_number, get_max_delay, get_min_delay 
    88import numpy 
    99# note that WDManager is defined in __init__.py imported here, then imported 
     
    7979            return projection.pre.size 
    8080        else: 
    81             raise Exception("Connection method not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes.") 
     81            raise Exception("OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes.") 
    8282     
    8383class FixedProbabilityConnector(common.FixedProbabilityConnector): 
    8484     
    8585    def connect(self, projection): 
    86         postsynaptic_neurons  = projection.post.cell.flatten() 
     86        postsynaptic_neurons = projection.post.cell_local.flatten() 
    8787        npost = projection.post.size 
    88         for pre in projection.pre.cell.flat: 
     88        for pre in projection.pre.cell: 
    8989            if projection.rng: 
    9090                rarr = projection.rng.uniform(0, 1, (npost,)) # what about NativeRNG? 
    9191            else: 
    9292                rarr = numpy.random.uniform(0, 1, (npost,)) 
     93            if len(rarr) > len(postsynaptic_neurons): 
     94                rarr = rarr[:len(postsynaptic_neurons)] 
    9395            target_list = numpy.compress(numpy.less(rarr, self.p_connect), postsynaptic_neurons).tolist() 
    9496            # if self connections are not allowed, check whether pre and post are the same 
  • trunk/src/neuron/__init__.py

    r310 r322  
    328328            'pc = new ParallelContext()', 
    329329            'dt = %f' % timestep, 
     330            'tstop = 0', 
    330331            'min_delay = %g' % min_delay, 
    331332            'create dummy_section', 
     
    407408    if not running: 
    408409        running = True 
    409         hoc_commands += ['tstop = 0', 
    410                          'local_minimum_delay = pc.set_maxstep(10)', 
     410        hoc_commands += ['local_minimum_delay = pc.set_maxstep(10)', 
    411411                         'tmp = finitialize()',] 
    412412        hoc_execute(hoc_commands,"--- run() ---") 
     
    752752            raise common.InvalidDimensionsError 
    753753        return coords 
     754 
     755    def index(self, n): 
     756        """Return the nth cell in the population (Indexing starts at 0).""" 
     757        if hasattr(n, '__len__'): 
     758            n = numpy.array(n) 
     759        return self.fullgidlist[n] 
    754760 
    755761    def get(self, parameter_name, as_array=False): 
     
    11661172        self.hoc_label = self.label.replace(" ","_") 
    11671173        if not rng: 
    1168             self.rng = numpy.random.RandomState() 
     1174            self.rng = NumpyRNG() 
    11691175        hoc_commands = ['objref %s' % self.hoc_label, 
    11701176                        '%s = new List()' % self.hoc_label] 
  • trunk/src/neuron/connectors.py

    r310 r322  
    9393                hoc_commands += self.singleConnect(projection, src, tgt, w, d) 
    9494        else: 
    95             raise Exception("Method '%s' not yet implemented for the case where presynaptic and postsynaptic Populations have different sizes." % sys._getframe().f_code.co_name) 
     95            raise Exception("OneToOneConnector does not support presynaptic and postsynaptic Populations of different sizes.") 
    9696        return hoc_commands 
    9797 
  • trunk/src/random.py

    r308 r322  
    1616    print "Warning: GSL random number generators not available" 
    1717import time 
     18import logging 
    1819 
    1920# The following two functions taken from 
     
    6061        self.rng = numpy.random.RandomState() 
    6162        if self.seed: 
     63            if not parallel_safe: 
     64                self.seed += rank # ensure different nodes get different sequences 
     65                if rank != 0: 
     66                    logging.warning("Changing the seed to %s on node %d" % (self.seed, rank)) 
    6267            self.rng.seed(self.seed) 
    6368        else: 
     
    8994            raise ValueError, "The sample number must be positive" 
    9095        if self.parallel_safe and self.num_processes > 1: 
    91             # strip out the random numbers that should be used on other processors 
     96            # strip out the random numbers that should be used on other processors. 
     97            # This assumes that the first neuron in a population is always created on 
     98            # the node with rank 0, and that neurons are distributed in a round-robin 
     99            # This assumption is not true for NEST 
    92100            rarr = rarr[numpy.arange(self.rank, len(rarr), self.num_processes)] 
    93101        return rarr