Changeset 817 for branches

Show
Ignore:
Timestamp:
11/10/10 16:12:06 (19 months ago)
Author:
apdavison
Message:

Starting to reimplement native model support (in branch)

Location:
branches/nativemodels
Files:
2 added
7 modified

Legend:

Unmodified
Added
Removed
  • branches/nativemodels/src/common.py

    r809 r817  
    7070    """ 
    7171    if hasattr(target_cell, 'local') and target_cell.local and hasattr(target_cell, 'cellclass'): 
    72         if isinstance(target_cell.cellclass, type): 
    73             is_conductance = target_cell.cellclass.conductance_based 
    74         else: # where cellclass is a string, i.e. for native cell types in NEST 
    75             is_conductance = "cond" in target_cell.cellclass 
     72#        if isinstance(target_cell.cellclass, type): 
     73        is_conductance = target_cell.cellclass.conductance_based 
     74#        else: # where cellclass is a string, i.e. for native cell types in NEST 
     75#            is_conductance = "cond" in target_cell.cellclass 
    7676    else: 
    7777        is_conductance = None 
     
    759759        Connect a current source to all cells in the Population. 
    760760        """ 
    761         if 'v' not in self.celltype.recordable: 
     761#        if 'v' not in self.celltype.recordable: 
     762        if not self.celltype.injectable:            
    762763            raise TypeError("Can't inject current into a spike source.") 
    763764        current_source.inject_into(self) 
     
    786787    nPop = 0 
    787788     
    788     def __init__(self, size, cellclass, cellparams=None, structure=None, 
    789                  label=None): 
     789    def __init__(self, size, celltype, structure=None, label=None): 
    790790        """ 
    791791        Create a population of neurons all of the same type. 
     
    822822        self.size = size 
    823823        self.label = label or 'population%d' % Population.nPop          
    824         if isinstance(cellclass, type) and issubclass(cellclass, standardmodels.StandardCellType): 
    825             self.celltype = cellclass(cellparams) 
    826         else: 
    827             self.celltype = cellclass 
     824#        if isinstance(cellclass, type) and issubclass(cellclass, standardmodels.StandardCellType): 
     825#            self.celltype = cellclass(cellparams) 
     826#        else: 
     827#            self.celltype = cellclass 
     828        self.celltype = celltype 
    828829        self._structure = structure or space.Line() 
    829830        self._positions = None 
    830         self.cellparams = cellparams 
     831#        self.cellparams = cellparams 
    831832        # Build the arrays of cell ids 
    832833        # Cells on the local node are represented as ID objects, other cells by integers 
    833834        # All are stored in a single numpy array for easy lookup by address 
    834835        # The local cells are also stored in a list, for easy iteration 
    835         self._create_cells(cellclass, cellparams, size) 
     836        self._create_cells(celltype, size) 
    836837        self.initial_values = {} 
    837838        for variable, value in self.celltype.default_initial_values.items(): 
  • branches/nativemodels/src/nest/__init__.py

    r804 r817  
    167167    recorder_class = Recorder 
    168168 
    169     def _create_cells(self, cellclass, cellparams, n): 
     169    def _create_cells(self, celltype, n): 
    170170        """ 
    171171        Create cells in NEST. 
     
    178178        # perhaps should check for that 
    179179        assert n > 0, 'n must be a positive integer' 
    180         if isinstance(cellclass, basestring):  # celltype is not a standard cell 
    181             nest_model = cellclass 
    182             cell_parameters = cellparams or {} 
    183         elif isinstance(cellclass, type) and issubclass(cellclass, standardmodels.StandardCellType): 
    184             celltype = cellclass(cellparams) 
    185             nest_model = celltype.nest_name[simulator.state.spike_precision] 
    186             cell_parameters = celltype.parameters 
    187         else: 
    188             raise Exception("Invalid cell type: %s" % type(cellclass)) 
     180#        if isinstance(cellclass, basestring):  # celltype is not a standard cell 
     181#            nest_model = cellclass 
     182#            cell_parameters = cellparams or {} 
     183#        elif isinstance(cellclass, type) and issubclass(cellclass, standardmodels.StandardCellType): 
     184        nest_model = celltype.nest_name[simulator.state.spike_precision] 
     185#        cell_parameters = celltype.parameters 
     186#        else: 
     187#            raise Exception("Invalid cell type: %s" % type(cellclass)) 
    189188        try: 
    190189            self.all_cells = nest.Create(nest_model, n) 
     
    193192                raise errors.InvalidModelError("%s Have you compiled NEST with the GSL (Gnu Scientific Library)?" % err) 
    194193            raise errors.InvalidModelError(err) 
    195         if cell_parameters: 
    196             try: 
    197                 nest.SetStatus(self.all_cells, [cell_parameters]) 
    198             except nest.NESTError: 
    199                 print "NEST error when trying to set the following dictionary: %s" % cell_parameters 
    200                 raise 
     194#        if cell_parameters: 
     195        try: 
     196            nest.SetStatus(self.all_cells, [celltype.parameters]) 
     197        except nest.NESTError: 
     198            print "NEST error when trying to set the following dictionary: %s" % cell_parameters 
     199            raise 
    201200        self.first_id = self.all_cells[0] 
    202201        self.last_id = self.all_cells[-1] 
     
    283282            value = rarr #numpy.array(rarr) 
    284283            assert len(rarr) == len(self.local_cells), "%d != %d" % (len(rarr), len(self.local_cells)) 
    285         nest.SetStatus(self.local_cells.tolist(), STATE_VARIABLE_MAP[variable], value) 
     284        if variable in STATE_VARIABLE_MAP: 
     285            variable = STATE_VARIABLE_MAP[variable] 
     286        nest.SetStatus(self.local_cells.tolist(), variable, value) 
    286287        self.initial_values[variable] = core.LazyArray(self.size, value) 
    287288 
  • branches/nativemodels/src/nest/electrodes.py

    r711 r817  
    2424        """Inject this current source into some cells.""" 
    2525        for id in cell_list: 
    26             if id.local and 'v' not in id.cellclass.recordable: 
     26            if id.local and not id.cellclass.injectable: #'v' not in id.cellclass.recordable: 
    2727                raise TypeError("Can't inject current into a spike source.") 
    2828        if isinstance(cell_list, Population): 
  • branches/nativemodels/src/nest/simulator.py

    r792 r817  
    272272         
    273273        try: 
    274             nest.DivergentConnect([source], targets, weights, delays, self.synapse_model)             
     274            nest.DivergentConnect([source], targets, weights, delays, self.synapse_model) 
     275            raise 
    275276        except nest.NESTError, e: 
    276277            raise errors.ConnectionError("%s. source=%s, targets=%s, weights=%s, delays=%s, synapse model='%s'" % ( 
  • branches/nativemodels/src/neuron/__init__.py

    r799 r817  
    105105    recorder_class = Recorder 
    106106     
    107     def __init__(self, size, cellclass, cellparams=None, structure=None, 
     107    def __init__(self, size, celltype, structure=None, 
    108108                 label=None): 
    109109        __doc__ = common.Population.__doc__ 
    110         common.Population.__init__(self, size, cellclass, cellparams, structure, label) 
     110        common.Population.__init__(self, size, celltype, structure, label) 
    111111        simulator.initializer.register(self) 
    112112 
    113     def _create_cells(self, cellclass, cellparams, n): 
     113    def _create_cells(self, celltype, n): 
    114114        """ 
    115115        Create cells in NEURON. 
     
    123123        # perhaps should check for that 
    124124        assert n > 0, 'n must be a positive integer' 
    125         if isinstance(cellclass, basestring): # cell defined in hoc template 
    126             try: 
    127                 cell_model = getattr(h, cellclass) 
    128             except AttributeError: 
    129                 raise errors.InvalidModelError("There is no hoc template called %s" % cellclass) 
    130             cell_parameters = cellparams or {} 
    131         elif isinstance(cellclass, type) and issubclass(cellclass, standardmodels.StandardCellType): 
    132             celltype = cellclass(cellparams) 
    133             cell_model = celltype.model 
    134             cell_parameters = celltype.parameters 
    135         else: 
    136             cell_model = cellclass 
    137             cell_parameters = cellparams 
     125#        if isinstance(cellclass, basestring): # cell defined in hoc template 
     126#            try: 
     127#                cell_model = getattr(h, cellclass) 
     128#            except AttributeError: 
     129#                raise errors.InvalidModelError("There is no hoc template called %s" % cellclass) 
     130#            cell_parameters = cellparams or {} 
     131#        elif isinstance(cellclass, type) and issubclass(cellclass, standardmodels.StandardCellType): 
     132#            celltype = cellclass(cellparams) 
     133        cell_model = celltype.model 
     134        cell_parameters = celltype.parameters 
     135#        else: 
     136#            cell_model = cellclass 
     137#            cell_parameters = cellparams 
    138138        self.first_id = simulator.state.gid_counter 
    139139        self.last_id = simulator.state.gid_counter + n - 1 
  • branches/nativemodels/src/neuron/electrodes.py

    r747 r817  
    6767        for id in cell_list: 
    6868            if id.local: 
    69                 if 'v' not in id.cellclass.recordable: 
     69#                if 'v' not in id.cellclass.recordable: 
     70                if not id.cellclass.injectable: 
    7071                    raise TypeError("Can't inject current into a spike source.") 
    7172                iclamp = h.IClamp(0.5, sec=id._cell.source_section) 
  • branches/nativemodels/src/neuron/simulator.py

    r774 r817  
    152152class _State(object): 
    153153    """Represent the simulator state.""" 
     154    max_delay = numpy.inf 
    154155     
    155156    def __init__(self): 
     
    440441                if self.synapse_model == 'Tsodyks-Markram' and 'TM' not in self.synapse_type: 
    441442                    self.synapse_type += '_TM'         
    442                 synapse_object = getattr(target._cell, self.synapse_type) 
     443                if "." in self.synapse_type: 
     444                    section, synapse_type = self.synapse_type.split(".") 
     445                    synapse_object = getattr(getattr(target._cell, section), synapse_type) 
     446                else: 
     447                    synapse_object = getattr(target._cell, self.synapse_type) 
    443448                nc = state.parallel_context.gid_connect(int(source), synapse_object) 
    444449                nc.weight[0] = weight