예제 #1
0
 def BuildNeuronAliases_(self):
   self.neuron_aliases = {}
   for name, spec in self.neuron_alias_definitions.items():
     visited_aliases = set()
     neuron_subgroups = set()
     to_visit = list()
     to_visit.append(name)
     while to_visit:
       subgroup_name = to_visit.pop()
       if subgroup_name in visited_aliases:
         print "In neuron_alias %s:" % name
         print "  Loop detected with subgroup %s" % subgroup_name
         return False
       if subgroup_name in self.neuron_groups:
         neuron_subgroups.add(self.neuron_groups[subgroup_name])
       elif subgroup_name in self.neuron_alias_definitions:
         visited_aliases.add(subgroup_name)
         subgroups = self.neuron_alias_definitions[subgroup_name]["subgroups"]
         to_visit = to_visit + subgroups
       else:
         print "In neuron_alias %s:" % name
         print "  subgroup %s is neither an alias or group" % subgroup_name
         return False
     neuron_alias = (
       pyncs.NeuronAlias(pyncs.neuron_group_list(list(neuron_subgroups)))
     )
     self.neuron_aliases[str(name)] = neuron_alias
   for name, group in self.neuron_groups.items():
     neuron_alias = (
       pyncs.NeuronAlias(pyncs.neuron_group_list([group]))
     )
     self.neuron_aliases[str(name)] = neuron_alias
   return True
예제 #2
0
파일: json_model.py 프로젝트: starhxh/ncs
 def BuildNeuronAliases_(self):
     self.neuron_aliases = {}
     for name, spec in self.neuron_alias_definitions.items():
         visited_aliases = set()
         neuron_subgroups = set()
         to_visit = list()
         to_visit.append(name)
         while to_visit:
             subgroup_name = to_visit.pop()
             if subgroup_name in visited_aliases:
                 print "In neuron_alias %s:" % name
                 print "  Loop detected with subgroup %s" % subgroup_name
                 return False
             if subgroup_name in self.neuron_groups:
                 neuron_subgroups.add(self.neuron_groups[subgroup_name])
             elif subgroup_name in self.neuron_alias_definitions:
                 visited_aliases.add(subgroup_name)
                 subgroups = self.neuron_alias_definitions[subgroup_name][
                     "subgroups"]
                 to_visit = to_visit + subgroups
             else:
                 print "In neuron_alias %s:" % name
                 print "  subgroup %s is neither an alias or group" % subgroup_name
                 return False
         neuron_alias = (pyncs.NeuronAlias(
             pyncs.neuron_group_list(list(neuron_subgroups))))
         self.neuron_aliases[str(name)] = neuron_alias
     for name, group in self.neuron_groups.items():
         neuron_alias = (pyncs.NeuronAlias(pyncs.neuron_group_list([group
                                                                    ])))
         self.neuron_aliases[str(name)] = neuron_alias
     return True
예제 #3
0
파일: json_model.py 프로젝트: starhxh/ncs
    def BuildSynapseGroups_(self):
        self.synapse_groups = {}
        for name, spec in self.synapse_group_definitions.items():
            model_name = str(spec["specification"])
            presynaptic_name = str(spec["presynaptic"])
            probability = float(spec["probability"])
            presynaptic_groups = list()
            if presynaptic_name in self.neuron_groups:
                presynaptic_groups.append(self.neuron_groups[presynaptic_name])
            elif presynaptic_name in self.neuron_aliases:
                for subgroup in self.neuron_aliases[
                        presynaptic_name].getSubgroups():
                    presynaptic_groups.append(subgroup)
            else:
                print "For synapse_group %s:" % name
                print "  %s is not a neuron_group or neuron_alias" % presynaptic_name
                return False

            postsynaptic_name = str(spec["postsynaptic"])
            postsynaptic_groups = list()
            if postsynaptic_name in self.neuron_groups:
                postsynaptic_groups.append(
                    self.neuron_groups[postsynaptic_name])
            elif postsynaptic_name in self.neuron_aliases:
                for subgroup in self.neuron_aliases[
                        postsynaptic_name].getGroups():
                    postsynaptic_groups.append(subgroup)
            else:
                print "For synapse_group %s:" % name
                print "  %s is not a neuron_group or neuron_alias" % postsynaptic_name
                return False

            if model_name not in self.model_parameters:
                print "For synapse_group %s" % name
                print "  %s is not a defined model_parameters" % model_name
                return False
            parameters = self.model_parameters[model_name]
            synapse_group = (pyncs.SynapseGroup(
                pyncs.neuron_group_list(presynaptic_groups),
                pyncs.neuron_group_list(postsynaptic_groups), parameters,
                probability))
            self.synapse_groups[str(name)] = synapse_group
        return True
예제 #4
0
  def BuildSynapseGroups_(self):
    self.synapse_groups = {}
    for name, spec in self.synapse_group_definitions.items():
      model_name = str(spec["specification"])
      presynaptic_name = str(spec["presynaptic"])
      probability = float(spec["probability"])
      presynaptic_groups = list()
      if presynaptic_name in self.neuron_groups:
        presynaptic_groups.append(self.neuron_groups[presynaptic_name])
      elif presynaptic_name in self.neuron_aliases:
        for subgroup in self.neuron_aliases[presynaptic_name].getSubgroups():
          presynaptic_groups.append(subgroup)
      else:
        print "For synapse_group %s:" % name
        print "  %s is not a neuron_group or neuron_alias" % presynaptic_name
        return False

      postsynaptic_name = str(spec["postsynaptic"])
      postsynaptic_groups = list()
      if postsynaptic_name in self.neuron_groups:
        postsynaptic_groups.append(self.neuron_groups[postsynaptic_name])
      elif postsynaptic_name in self.neuron_aliases:
        for subgroup in self.neuron_aliases[postsynaptic_name].getGroups():
          postsynaptic_groups.append(subgroup)
      else:
        print "For synapse_group %s:" % name
        print "  %s is not a neuron_group or neuron_alias" % postsynaptic_name
        return False

      if model_name not in self.model_parameters:
        print "For synapse_group %s" % name
        print "  %s is not a defined model_parameters" % model_name
        return False
      parameters = self.model_parameters[model_name]
      synapse_group = (
        pyncs.SynapseGroup(pyncs.neuron_group_list(presynaptic_groups),
                           pyncs.neuron_group_list(postsynaptic_groups),
                           parameters,
                           probability)
      )
      self.synapse_groups[str(name)] = synapse_group
    return True
예제 #5
0
파일: ncs.py 프로젝트: starhxh/ncs
    def init(self, argv):
        self.model_specification = pyncs.ModelSpecification()
        self.model_specification.thisown = False
        #self.model_specification.model_parameters = (
        #     pyncs.string_to_model_parameters_map(self.model_parameters)
        #   )
        neuron_group_map = {}
        for name, cell_group in self.cell_groups.items():
            model_parameters = self.getNeuronParameters(cell_group.parameters)
            if not model_parameters:
                print "ModelParameters %s not found" % cell_group.parameters
                return False
            neuron_group = pyncs.NeuronGroup(cell_group.count,
                                             model_parameters,
                                             cell_group.geometry)
            cell_group.neuron_group = neuron_group
            neuron_group.thisown = False
            neuron_group_map[name] = neuron_group
        self.model_specification.neuron_groups = (
            pyncs.string_to_neuron_group_map(neuron_group_map))
        for name, alias in self.cell_aliases.items():
            if not alias.resolved:
                if not self.resolveCellAlias_(alias):
                    print "Failed to resolve CellAlias %s" % name
                    return False
            neuron_groups = [x.neuron_group for x in alias.subgroups]
            neuron_group_list = pyncs.neuron_group_list(neuron_groups)
            alias.neuron_alias = pyncs.NeuronAlias(neuron_group_list)
        neuron_alias_map = {
            n: a.neuron_alias
            for n, a in self.cell_aliases.items()
        }
        self.model_specification.neuron_aliases = (
            pyncs.string_to_neuron_alias_map(neuron_alias_map))

        connection_map = {}
        for name, connection in self.connections.items():
            if not connection.presynaptic.resolved:
                if not self.resolveCellAlias_(connection.presynaptic):
                    print "Invalid presynaptic group in connection %s" % name
                    return False
            if not connection.postsynaptic.resolved:
                if not self.resolveCellAlias_(connection.postsynaptic):
                    print "Invalid postsynaptic group in connection %s" % name
                    return False
            model_parameters = self.getSynapseParameters(connection.parameters)
            if not model_parameters:
                print "ModelParameters %s not found" % connection.parameters
                return False

            group = pyncs.neuron_group_list
            presynaptic_neuron_groups = [
                x.neuron_group for x in connection.presynaptic.subgroups
            ]
            presynaptic = group(
                [x.neuron_group for x in connection.presynaptic.subgroups])
            postsynaptic = group(
                [x.neuron_group for x in connection.postsynaptic.subgroups])
            synapse_group = pyncs.SynapseGroup(presynaptic, postsynaptic,
                                               model_parameters,
                                               connection.probability)
            connection.synapse_group = synapse_group
            synapse_group.thisown = False
            connection_map[name] = synapse_group
        self.model_specification.synapse_groups = (
            pyncs.string_to_synapse_group_map(connection_map))

        for name, alias in self.connection_aliases.items():
            if not alias.resolved:
                if not self.resolveConnectionAlias_(alias):
                    print "Failed to resolve ConnectionAlias %s" % name
                    return False
            synapse_groups = [x.synapse_group for x in alias.subgroups]
            synapse_group_list = pyncs.synapse_group_list(synapse_groups)
            alias.synapse_alias = pyncs.SynapseAlias(synapse_group_list)
        synapse_alias_map = {
            n: a.synapse_alias
            for n, a in self.connection_aliases.items()
        }
        self.model_specification.synapse_aliases = (
            pyncs.string_to_synapse_alias_map(synapse_alias_map))

        self.simulation = pyncs.Simulation(self.model_specification,
                                           self.simulaton_parameters)
        return self.simulation.init(pyncs.string_list(argv))
예제 #6
0
  def init(self, argv):
    self.model_specification = pyncs.ModelSpecification()
    self.model_specification.thisown = False
#self.model_specification.model_parameters = (
#     pyncs.string_to_model_parameters_map(self.model_parameters)
#   )
    neuron_group_map = {}
    for name, cell_group in self.cell_groups.items():
      model_parameters = self.getNeuronParameters(cell_group.parameters)
      if not model_parameters:
        print "ModelParameters %s not found" % cell_group.parameters
        return False
      neuron_group = pyncs.NeuronGroup(cell_group.count,
                                       model_parameters,
                                       cell_group.geometry)
      cell_group.neuron_group = neuron_group
      neuron_group.thisown = False
      neuron_group_map[name] = neuron_group
    self.model_specification.neuron_groups = (
      pyncs.string_to_neuron_group_map(neuron_group_map)
    )
    for name, alias in self.cell_aliases.items():
      if not alias.resolved:
        if not self.resolveCellAlias_(alias):
          print "Failed to resolve CellAlias %s" % name
          return False
      neuron_groups = [x.neuron_group for x in alias.subgroups]
      neuron_group_list = pyncs.neuron_group_list(neuron_groups)
      alias.neuron_alias = pyncs.NeuronAlias(neuron_group_list)
    neuron_alias_map = { n : a.neuron_alias 
                         for n, a in self.cell_aliases.items() }
    self.model_specification.neuron_aliases = (
      pyncs.string_to_neuron_alias_map(neuron_alias_map)
    )

    connection_map = {}
    for name, connection in self.connections.items():
      if not connection.presynaptic.resolved:
        if not self.resolveCellAlias_(connection.presynaptic):
          print "Invalid presynaptic group in connection %s" % name
          return False
      if not connection.postsynaptic.resolved:
        if not self.resolveCellAlias_(connection.postsynaptic):
          print "Invalid postsynaptic group in connection %s" % name
          return False
      model_parameters = self.getSynapseParameters(connection.parameters)
      if not model_parameters:
        print "ModelParameters %s not found" % connection.parameters
        return False

      group = pyncs.neuron_group_list
      presynaptic_neuron_groups = [x.neuron_group 
                                   for x in connection.presynaptic.subgroups]
      presynaptic = group([x.neuron_group 
                           for x in connection.presynaptic.subgroups])
      postsynaptic = group([x.neuron_group
                            for x in connection.postsynaptic.subgroups])
      synapse_group = pyncs.SynapseGroup(presynaptic,
                                         postsynaptic,
                                         model_parameters,
                                         connection.probability)
      connection.synapse_group = synapse_group
      synapse_group.thisown = False
      connection_map[name] = synapse_group
    self.model_specification.synapse_groups = (
      pyncs.string_to_synapse_group_map(connection_map)
    )

    for name, alias in self.connection_aliases.items():
      if not alias.resolved:
        if not self.resolveConnectionAlias_(alias):
          print "Failed to resolve ConnectionAlias %s" % name
          return False
      synapse_groups = [x.synapse_group for x in alias.subgroups]
      synapse_group_list = pyncs.synapse_group_list(synapse_groups)
      alias.synapse_alias = pyncs.SynapseAlias(synapse_group_list)
    synapse_alias_map = { n : a.synapse_alias
                          for n, a in self.connection_aliases.items() }
    self.model_specification.synapse_aliases = (
      pyncs.string_to_synapse_alias_map(synapse_alias_map)
    )
  
    self.simulation = pyncs.Simulation(self.model_specification,
                                       self.simulaton_parameters)
    return self.simulation.init(pyncs.string_list(argv))