| 23 | | def generate_spiking_node_description_map(): |
| 24 | | """ |
| 25 | | Return a mapping between URIs and StandardCellType classes. |
| 26 | | """ |
| 27 | | map = {} |
| 28 | | for m in pyNN.nineml.list_standard_models(): |
| 29 | | definition_url = m.spiking_mechanism_definition_url |
| 30 | | if definition_url in map: |
| 31 | | map[definition_url].add(m) |
| 32 | | else: |
| 33 | | map[definition_url] = set([m]) |
| 34 | | return map |
| 35 | | |
| 36 | | def generate_post_synaptic_response_description_map(): |
| 37 | | """ |
| 38 | | Return a mapping between URIs and StandardCellType classes. |
| 39 | | """ |
| 40 | | map = {} |
| 41 | | for m in pyNN.nineml.list_standard_models(): |
| 42 | | if m.synapse_types: # exclude spike sources |
| 43 | | definition_url = m.synaptic_mechanism_definition_urls['excitatory'] |
| 44 | | assert definition_url == m.synaptic_mechanism_definition_urls['inhibitory'] |
| 45 | | if definition_url in map: |
| 46 | | map[definition_url].add(m) |
| 47 | | else: |
| 48 | | map[definition_url] = set([m]) |
| 49 | | return map |
| 50 | | |
| 51 | | def generate_connector_map(): |
| 52 | | """ |
| 53 | | Return a mapping between URIs and Connector classes. |
| 54 | | """ |
| 55 | | map = {} |
| 56 | | for c in pyNN.nineml.connectors.list_connectors(): |
| 57 | | map[c.definition_url] = c |
| 58 | | return map |
| | 18 | #def generate_spiking_node_description_map(): |
| | 19 | # """ |
| | 20 | # Return a mapping between URIs and StandardCellType classes. |
| | 21 | # """ |
| | 22 | # map = {} |
| | 23 | # for m in pyNN.nineml.list_standard_models(): |
| | 24 | # definition_url = m.spiking_mechanism_definition_url |
| | 25 | # if definition_url in map: |
| | 26 | # map[definition_url].add(m) |
| | 27 | # else: |
| | 28 | # map[definition_url] = set([m]) |
| | 29 | # return map |
| | 30 | |
| | 31 | #def generate_post_synaptic_response_description_map(): |
| | 32 | # """ |
| | 33 | # Return a mapping between URIs and StandardCellType classes. |
| | 34 | # """ |
| | 35 | # map = {} |
| | 36 | # for m in pyNN.nineml.list_standard_models(): |
| | 37 | # if m.synapse_types: # exclude spike sources |
| | 38 | # definition_url = m.synaptic_mechanism_definition_urls['excitatory'] |
| | 39 | # assert definition_url == m.synaptic_mechanism_definition_urls['inhibitory'] |
| | 40 | # if definition_url in map: |
| | 41 | # map[definition_url].add(m) |
| | 42 | # else: |
| | 43 | # map[definition_url] = set([m]) |
| | 44 | # return map |
| | 45 | |
| | 46 | #def generate_connector_map(): |
| | 47 | # """ |
| | 48 | # Return a mapping between URIs and Connector classes. |
| | 49 | # """ |
| | 50 | # map = {} |
| | 51 | # for c in pyNN.nineml.connectors.list_connectors(): |
| | 52 | # map[c.definition_url] = c |
| | 53 | # return map |
| 235 | | def _determine_cell_type(self, nineml_population): |
| 236 | | """Determine cell class from standardcell--catalog mapping""" |
| 237 | | cellclass_map = generate_spiking_node_description_map() |
| 238 | | possible_cell_classes_from_spiking_node = cellclass_map[nineml_population.prototype.definition.url] |
| 239 | | if nineml_population.name in self.psr_map: |
| 240 | | synapse_definition_urls = set(psr.definition.url for psr in self.psr_map[nineml_population.name]) |
| 241 | | assert len(synapse_definition_urls) == 1 # exc and inh always same model at present |
| 242 | | synapse_definition_url = list(synapse_definition_urls)[0] |
| 243 | | synapsetype_map = generate_post_synaptic_response_description_map() |
| 244 | | possible_cell_classes_from_psr = synapsetype_map[synapse_definition_url] |
| 245 | | possible_cell_classes = possible_cell_classes_from_spiking_node.intersection(possible_cell_classes_from_psr) |
| 246 | | assert len(possible_cell_classes) == 1 |
| 247 | | cell_class = list(possible_cell_classes)[0] |
| 248 | | else: |
| 249 | | print "Population '%s' is not the target of any Projections, so we can choose any synapse model." % nineml_population.name |
| 250 | | cell_class = list(possible_cell_classes_from_spiking_node)[0] |
| 251 | | return cell_class |
| 252 | | |
| 253 | | def _determine_cell_type_and_parameters(self, nineml_population): |
| | 236 | #def _determine_cell_type(self, nineml_population): |
| | 237 | # """Determine cell class from standardcell--catalog mapping""" |
| | 238 | # cellclass_map = generate_spiking_node_description_map() |
| | 239 | # possible_cell_classes_from_spiking_node = cellclass_map[nineml_population.prototype.definition.url] |
| | 240 | # if nineml_population.name in self.psr_map: |
| | 241 | # synapse_definition_urls = set(psr.definition.url for psr in self.psr_map[nineml_population.name]) |
| | 242 | # assert len(synapse_definition_urls) == 1 # exc and inh always same model at present |
| | 243 | # synapse_definition_url = list(synapse_definition_urls)[0] |
| | 244 | # synapsetype_map = generate_post_synaptic_response_description_map() |
| | 245 | # possible_cell_classes_from_psr = synapsetype_map[synapse_definition_url] |
| | 246 | # possible_cell_classes = possible_cell_classes_from_spiking_node.intersection(possible_cell_classes_from_psr) |
| | 247 | # assert len(possible_cell_classes) == 1 |
| | 248 | # cell_class = list(possible_cell_classes)[0] |
| | 249 | # else: |
| | 250 | # print "Population '%s' is not the target of any Projections, so we do not have a synapse model." % nineml_population.name |
| | 251 | # return cell_class |
| | 252 | |
| | 253 | |
| | 254 | |
| | 255 | def _generate_cell_type_and_parameters(self, nineml_population): |
| 265 | | synapse_params = list(self.psr_map[nineml_population.name])[0].parameters |
| 266 | | for target in "excitatory", "inhibitory": |
| 267 | | for name, value in synapse_params.items(): |
| 268 | | nineml_params["%s_%s" % (target, name)] = value |
| 269 | | else: # take default values, since the synapses won't be used in any case. |
| 270 | | synapse_params = {"excitatory_decayTimeConstant": nineml.Parameter("decayTimeConstant", 5.0, "ms"), |
| 271 | | "inhibitory_decayTimeConstant": nineml.Parameter("decayTimeConstant", 5.0, "ms"), |
| 272 | | "excitatory_reversalPotential": nineml.Parameter("reversalPotential", 0.0, "mV"), |
| 273 | | "inhibitory_reversalPotential": nineml.Parameter("reversalPotential", -70.0, "mV")} |
| 274 | | nineml_params.update(synapse_params) |
| 275 | | |
| 276 | | cell_params = cell_class.reverse_translate(nineml_params) |
| | 265 | for psr_component in self.psr_map[nineml_population.name]: |
| | 266 | synapse_models[_generate_variable_name(psr_component.name)] = psr_component.definition.component |
| | 267 | subnodes = {neuron_namespace: neuron_model} |
| | 268 | subnodes.update(synapse_models) |
| | 269 | combined_model = al.ComponentClass(name=_generate_variable_name(nineml_population.name), |
| | 270 | subnodes=subnodes) |
| | 271 | # now connect ports |
| | 272 | connections = [] |
| | 273 | for source in [port for port in neuron_model.analog_ports if port.mode == 'send']: |
| | 274 | for synapse_name, syn_model in synapse_models.items(): |
| | 275 | for target in [port for port in syn_model.analog_ports if port.mode == 'recv']: |
| | 276 | connections.append(("%s.%s" % (neuron_namespace, source.name), "%s.%s" % (synapse_name, target.name))) |
| | 277 | for synapse_name, syn_model in synapse_models.items(): |
| | 278 | for source in [port for port in syn_model.analog_ports if port.mode == 'send']: |
| | 279 | for target in [port for port in neuron_model.analog_ports if port.mode in ('recv, reduce')]: |
| | 280 | connections.append(("%s.%s" % (synapse_name, source.name), "%s.%s" % (neuron_namespace, target.name))) |
| | 281 | #import pdb; pdb.set_trace() |
| | 282 | for connection in connections: |
| | 283 | combined_model.connect_ports(*connection) |
| | 284 | synapse_components = [self._nineml_module.CoBaSyn(namespace=name, weight_connector='q') for name in synapse_models.keys()] |
| | 285 | celltype_cls = self._nineml_module.nineml_cell_type( |
| | 286 | combined_model.name, combined_model, synapse_components) |
| 278 | | return cell_class, cell_params, random_params |
| | 288 | return celltype_cls, cell_params, random_params |
| | 289 | |
| | 290 | |
| | 291 | # iaf_2coba_model = al.ComponentClass( |
| | 292 | # name="iaf_2coba", |
| | 293 | # subnodes = {"iaf" : iaf.get_component(), |
| | 294 | # "cobaExcit" : coba_synapse.get_component(), |
| | 295 | # "cobaInhib" : coba_synapse.get_component()} ) |
| | 296 | # |
| | 297 | ## Connections have to be setup as strings, because we are deep-copying objects. |
| | 298 | #iaf_2coba_model.connect_ports( "iaf.V", "cobaExcit.V" ) |
| | 299 | #iaf_2coba_model.connect_ports( "iaf.V", "cobaInhib.V" ) |
| | 300 | #iaf_2coba_model.connect_ports( "cobaExcit.I", "iaf.ISyn" ) |
| | 301 | #iaf_2coba_model.connect_ports( "cobaInhib.I", "iaf.ISyn" ) |