Changeset 410

Show
Ignore:
Timestamp:
07/14/08 16:08:37 (1 month ago)
Author:
apdavison
Message:

The attempted optimisation of setting parameter values in r408 broke the translation mechanism for those parameters whose values are computed from the values of more than one native parameter. It is for these "computed parameters" that we got all the native parameters.

I have fixed the bug while attempting to keep the optimisation by checking whether the list of parameters to be set contains any computed parameters, and only getting/translating all parameters in this case.

If the list contains only simple or scaled parameters, setting should be much faster.

Pierre, could you use your code profiling to check that this is the case?

Files:

Legend:

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

    r408 r410  
    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        # if some of the parameters are computed from the values of other 
     128        # parameters, need to get and translate all parameters 
    129129        if self.is_standard_cell(): 
     130            computed_parameters = self.cellclass.computed_parameters() 
     131            have_computed_parameters = any([p_name in computed_parameters for p_name in parameters]) 
     132            if have_computed_parameters:      
     133                all_parameters = self.get_parameters() 
     134                all_parameters.update(parameters) 
     135                parameters = all_parameters 
    130136            parameters = self.cellclass.translate(parameters) 
    131137        self.set_native_parameters(parameters) 
     
    315321        parameters = cls.checkParameters(parameters, with_defaults=False) 
    316322        native_parameters = {} 
    317         for name,value in parameters.items(): 
    318             D = cls.translations[name] 
    319         #for name,D  in cls.translations.items(): 
     323        for name in parameters: 
     324            D = cls.translations[name] 
    320325            pname = D['translated_name'] 
    321326            try: 
    322327                pval = eval(D['forward_transform'], globals(), parameters) 
    323             except NameError
    324                 raise Exception("%s in %s. Transform: %s. Parameters: %s." \ 
    325                                 % (pname, cls.__name__, D['forward_transform'], parameters)) 
     328            except NameError, errmsg
     329                raise Exception("Problem translating %s in %s. Transform: %s. Parameters: %s. %s" \ 
     330                                % (pname, cls.__name__, D['forward_transform'], parameters, errmsg)) 
    326331            except ZeroDivisionError: 
    327332                pval = 1e30 # this is about the highest value hoc can deal with 
     
    12931298class FromListConnector(Connector): 
    12941299    """ 
    1295     Connects all cells in the presynaptic population to all cells in the 
    1296     postsynaptic population. 
     1300    Make connections according to a list. 
    12971301    """ 
    12981302     
     
    13041308class FromFileConnector(Connector): 
    13051309    """ 
    1306     Connects all cells in the presynaptic population to all cells in the 
    1307     postsynaptic population. 
     1310    Make connections according to a list contained in a file. 
    13081311    """ 
    13091312     
     
    13161319class FixedNumberPostConnector(Connector): 
    13171320    """ 
    1318     Each postsynaptic cell receives a fixed number of connections, chosen 
    1319     randomly from the presynaptic cells
     1321    Each pre-synaptic neuron is connected to exactly n post-synaptic neurons 
     1322    chosen at random
    13201323    """ 
    13211324     
     
    13371340class FixedNumberPreConnector(Connector): 
    13381341    """ 
    1339     Connects all cells in the postsynaptic population to fixed number of 
    1340     cells in the presynaptic population, randomly choosen
     1342    Each post-synaptic neuron is connected to exactly n pre-synaptic neurons 
     1343    chosen at random
    13411344    """ 
    13421345    def __init__(self, n, allow_self_connections=True, weights=0.0, delays=None): 
  • trunk/test/unittests/nest2tests.py

    r396 r410  
    610610        self.pop1 = nest.Population((5,),nest.IF_curr_alpha,{'tau_m':10.0}) 
    611611        self.pop2 = nest.Population((5,4),nest.IF_curr_exp,{'v_reset':-60.0}) 
     612        self.pop3 = nest.Population((10,), nest.IF_cond_alpha) 
    612613     
    613614    def testIDSetAndGet(self): 
    614615        self.pop1[3].tau_m = 20.0 
    615616        self.pop2[3,2].v_reset = -70.0 
     617        self.pop3[5].tau_m = -55.0 
    616618        ifcell_params = nest.nest.GetStatus([self.pop1[3]])[0] 
    617619        self.assertEqual(20.0, ifcell_params['tau_m']) 
     
    620622        self.assertEqual(-70.0, self.pop2[3,2].v_reset) 
    621623        self.assertEqual(-60.0, self.pop2[0,0].v_reset) 
     624        self.assertAlmostEqual(-55.0, self.pop3[5].tau_m, 9) 
    622625 
    623626    def testGetCellClass(self):