Changeset 708 for trunk/src/neuroml.py

Show
Ignore:
Timestamp:
02/12/10 16:02:09 (2 years ago)
Author:
apdavison
Message:

Various fixes from running doctests

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/neuroml.py

    r705 r708  
    77from pyNN import common, connectors, cells 
    88import math 
    9 #import numpy, types, sys, shutil 
     9import numpy 
    1010import sys 
    1111sys.path.append('/usr/lib/python%s/site-packages/oldxml' % sys.version[:3]) # needed for Ubuntu 
     
    2424neuroml_xsd="http://www.neuroml.org/NeuroMLValidator/NeuroMLFiles/Schemata/v"+neuroml_ver+"/Level3/NeuroML_Level3_v"+neuroml_ver+".xsd" 
    2525 
     26strict = False 
     27 
    2628# ============================================================================== 
    2729#   Utility classes 
    2830# ============================================================================== 
    2931 
    30 class ID(common.IDMixin): 
     32class ID(int, common.IDMixin): 
    3133    """ 
    3234    Instead of storing ids as integers, we store them as ID objects, 
     
    3840     
    3941    def __init__(self, n): 
    40         common.IDMixin.__init__(self, n) 
     42        common.IDMixin.__init__(self) 
    4143 
    4244# ============================================================================== 
     
    179181        return cell_node, channel_nodes, synapse_nodes 
    180182 
     183 
     184class NotImplementedModel(object): 
     185     
     186    def __init__(self): 
     187        if strict: 
     188            raise Exception('Cell type %s is not available in NeuroML' % self.__class__.__name__) 
     189     
     190    def build_nodes(self): 
     191        cell_node = build_node(':not_implemented_cell', name=self.label) 
     192        doc_node = build_node('meta:notes', "PyNN %s cell type not implemented" % self.__class__.__name__) 
     193        return cell_node, [], [] 
     194         
     195 
    181196# ============================================================================== 
    182197#   Standard cells 
    183198# ============================================================================== 
    184199 
    185 class IF_curr_exp(cells.IF_curr_exp): 
     200class IF_curr_exp(cells.IF_curr_exp, NotImplementedModel): 
    186201    """Leaky integrate and fire model with fixed threshold and 
    187202    decaying-exponential post-synaptic current. (Separate synaptic currents for 
    188203    excitatory and inhibitory synapses""" 
    189204     
     205    n = 0 
     206    translations = common.build_translations(*[(name, name) 
     207                                               for name in cells.IF_curr_exp.default_parameters]) 
     208     
    190209    def __init__(self, parameters): 
    191         raise Exception('Cell type %s is not available in NeuroML' % self.__class__.__name__) 
    192  
    193 class IF_curr_alpha(cells.IF_curr_alpha): 
     210        NotImplementedModel.__init__(self) 
     211        cells.IF_curr_exp.__init__(self, parameters) 
     212        self.label = '%s%d' % (self.__class__.__name__, self.__class__.n) 
     213        self.synapse_type = "doub_exp_syn" 
     214        self.__class__.n += 1 
     215 
     216class IF_curr_alpha(cells.IF_curr_alpha, NotImplementedModel): 
    194217    """Leaky integrate and fire model with fixed threshold and alpha-function- 
    195218    shaped post-synaptic current.""" 
    196219     
     220    n = 0 
     221    translations = common.build_translations(*[(name, name) 
     222                                               for name in cells.IF_curr_alpha.default_parameters]) 
     223     
    197224    def __init__(self, parameters): 
    198         raise Exception('Cell type %s is not available in NeuroML' % self.__class__.__name__) 
     225        NotImplementedModel.__init__(self) 
     226        cells.IF_curr_exp.__init__(self, parameters) 
     227        self.label = '%s%d' % (self.__class__.__name__, self.__class__.n) 
     228        self.synapse_type = "doub_exp_syn" 
     229        self.__class__.n += 1 
    199230 
    200231class IF_cond_exp(cells.IF_cond_exp, IF_base): 
     
    226257        self.__class__.n += 1 
    227258 
    228 class SpikeSourcePoisson(cells.SpikeSourcePoisson): 
     259class SpikeSourcePoisson(cells.SpikeSourcePoisson, NotImplementedModel): 
    229260    """Spike source, generating spikes according to a Poisson process.""" 
    230261 
     262    n = 0 
     263    translations = common.build_translations(*[(name, name) 
     264                                               for name in cells.SpikeSourcePoisson.default_parameters]) 
     265     
    231266    def __init__(self, parameters): 
    232         raise Exception('Cell type %s not yet implemented' % self.__class__.__name__) 
     267        NotImplementedModel.__init__(self) 
    233268        cells.SpikeSourcePoisson.__init__(self, parameters) 
    234          
    235  
    236 class SpikeSourceArray(cells.SpikeSourceArray): 
     269        self.label = '%s%d' % (self.__class__.__name__, self.__class__.n) 
     270        self.__class__.n += 1 
     271         
     272 
     273class SpikeSourceArray(cells.SpikeSourceArray, NotImplementedModel): 
    237274    """Spike source generating spikes at the times given in the spike_times array.""" 
    238275 
     276    n = 0 
     277    translations = common.build_translations(*[(name, name) 
     278                                               for name in cells.SpikeSourcePoisson.default_parameters]) 
     279 
    239280    def __init__(self, parameters): 
    240         raise Exception('Cell type %s not yet implemented' % self.__class__.__name__) 
    241         cells.SpikeSourceArray.__init__(self, parameters) 
     281        NotImplementedModel.__init__(self) 
     282        cells.SpikeSourceARRAY.__init__(self, parameters) 
     283        self.label = '%s%d' % (self.__class__.__name__, self.__class__.n) 
     284        self.__class__.n += 1 
    242285         
    243286 
     
    253296    simulator but not by others. 
    254297    """ 
    255     global xmldoc, xmlfile, populations_node, projections_node, inputs_node, cells_node, channels_node, neuromlNode 
     298    global xmldoc, xmlfile, populations_node, projections_node, inputs_node, cells_node, channels_node, neuromlNode, strict 
    256299    xmlfile = extra_params['file'] 
    257300    if isinstance(xmlfile, basestring): 
    258301        xmlfile = open(xmlfile, 'w') 
     302    if 'strict' in extra_params: 
     303        strict = extra_params['strict'] 
    259304    dt = timestep 
    260305    xmldoc = xml.dom.minidom.Document() 
     
    296341def num_processes(): 
    297342    return 1 
     343common.num_processes = num_processes 
     344 
     345def rank(): 
     346    return 0 
     347common.rank = rank 
    298348 
    299349 
     
    388438            channels_node.appendChild(synapse_node) 
    389439 
     440        self.first_id = 0 
     441        self.last_id = self.size-1 
     442        self.all_cells = numpy.array([ID(id) for id in range(self.first_id, self.last_id+1)], dtype=ID).reshape(dims) 
     443        self._mask_local = numpy.ones_like(self.all_cells).astype(bool) 
     444        self.local_cells = self.all_cells[self._mask_local] 
     445 
     446    def _record(self, variable, record_from=None, rng=None, to_file=True): 
     447        """ 
     448        Private method called by record() and record_v(). 
     449        """ 
     450        pass 
     451     
     452    def meanSpikeCount(self): 
     453        return -1 
     454     
     455    def printSpikes(self, file, gather=True, compatible_output=True): 
     456        pass 
     457     
     458    def print_v(self, file, gather=True, compatible_output=True): 
     459        pass 
    390460 
    391461class AlltoAllConnector(connectors.AllToAllConnector): 
     
    531601        Projection.n += 1 
    532602 
    533  
    534 # ============================================================================== 
     603    def saveConnections(self, filename, gather=True, compatible_output=True): 
     604        pass 
     605     
     606    def __len__(self): 
     607        return 0 # needs implementing properly 
     608 
     609# ==============================================================================