Exemplo n.º 1
0
def Run(argv):
  if len(argv) < 2:
    print "Usage: %s <model_file>" % argv[0]
  model = json_model.JSONModel(argv[1])
  if not model.valid:
    print "Failed to load model"
    return
  model_specification = model.model_specification
  simulation_parameters = pyncs.SimulationParameters()
  simulation_parameters.thisown = False;
  simulation = pyncs.Simulation(model_specification,
                                simulation_parameters)
  if not simulation.init(pyncs.string_list(argv)):
    print "Failed to initialize simulator."
    return
  print "Injecting pre-specified inputs."
  for name, group in model.input_groups.items():
    simulation.addInput(group)
  print "Injection complete."
  print "Adding reports."
  sinks = {}
  for name, report in model.reports.items():
    source = simulation.addReport(report)
    if not source:
      print "Failed to add report %s" % name
      return
#sinks[name] = pyncs.NullSink(source)
#sinks[name] = pyncs.AsciiStreamSink(source)
#sinks[name] = pyncs.AsciiFileSink(source, "/dev/fd/0")
    sinks[name] = pyncs.AsciiFileSink(source, "/dev/fd/0")
  print "Starting simulation."
  for i in range(0,100):
    simulation.step()
  del simulation
Exemplo n.º 2
0
def Run(argv):
    if len(argv) < 2:
        print "Usage: %s <model_file>" % argv[0]
    model = json_model.JSONModel(argv[1])
    if not model.valid:
        print "Failed to load model"
        return
    model_specification = model.model_specification
    simulation_parameters = pyncs.SimulationParameters()
    simulation_parameters.thisown = False
    simulation = pyncs.Simulation(model_specification, simulation_parameters)
    if not simulation.init(pyncs.string_list(argv)):
        print "Failed to initialize simulator."
        return
    print "Injecting pre-specified inputs."
    for name, group in model.input_groups.items():
        simulation.addInput(group)
    print "Injection complete."
    print "Adding reports."
    sinks = {}
    for name, report in model.reports.items():
        source = simulation.addReport(report)
        if not source:
            print "Failed to add report %s" % name
            return


#sinks[name] = pyncs.NullSink(source)
#sinks[name] = pyncs.AsciiStreamSink(source)
#sinks[name] = pyncs.AsciiFileSink(source, "/dev/fd/0")
        sinks[name] = pyncs.AsciiFileSink(source, "/dev/fd/0")
    print "Starting simulation."
    for i in range(0, 100):
        simulation.step()
    del simulation
Exemplo n.º 3
0
  def addStimulus(self, 
                  type_name, 
                  parameters, 
                  groups, 
                  probability, 
                  start_time, 
                  end_time):
    if not self.simulation.isMaster():
      return True
    group_list = None
    if isinstance(groups, list):
      group_list = list(groups)
    else:
      group_list = [groups]
    group_names = []
    for group in group_list:
      if isinstance(group, str):
        if group not in self.cell_aliases:
          print "Cell group or alias %s was never registered." % group
          return False
        group_names.append(group)
      elif isinstance(group, CellAlias):
        if not group.name:
          print "Anonymous CellAlias cannot be used for input."
          return False
        group_names.append(group.name)
      elif isinstance(group, CellGroup):
        if not group.name:
          print "Anonymous CellGroup cannot be used for input."
          return False
        group_names.append(group.name)
      else:
        print "Unknown input group type."
        return False

    if not group_names:
      print "No groups specified for Input."
      return False

    model_parameters = self.buildModelParameters_(type_name, parameters)
    if not model_parameters:
      print "Failed to build model parameters for input"
      return False
    model_parameters.thisown = False
    input_group = pyncs.InputGroup(pyncs.string_list(group_names),
                                   model_parameters,
                                   probability,
                                   start_time,
                                   end_time)
    return self.simulation.addInput(input_group)
Exemplo n.º 4
0
 def BuildReports_(self):
     self.reports = {}
     for name, spec in self.report_definitions.items():
         target = pyncs.Report.Unknown
         target_string = str(spec["target"])
         if target_string == "neuron":
             target = pyncs.Report.Neuron
         elif target_string == "synapse":
             target = pyncs.Report.Synapse
         else:
             print "invalid target specified in report %s" % name
             return False
         percentage = float(spec["percentage"])
         aliases = [str(x) for x in spec["aliases"]]
         report = pyncs.Report(pyncs.string_list(aliases), target,
                               str(spec["attribute"]), percentage)
         self.reports[str(name)] = report
     return True
Exemplo n.º 5
0
Arquivo: ncs.py Projeto: starhxh/ncs
    def addStimulus(self, type_name, parameters, groups, probability,
                    start_time, end_time):
        if not self.simulation.isMaster():
            return True
        group_list = None
        if isinstance(groups, list):
            group_list = list(groups)
        else:
            group_list = [groups]
        group_names = []
        for group in group_list:
            if isinstance(group, str):
                if group not in self.cell_aliases:
                    print "Cell group or alias %s was never registered." % group
                    return False
                group_names.append(group)
            elif isinstance(group, CellAlias):
                if not group.name:
                    print "Anonymous CellAlias cannot be used for input."
                    return False
                group_names.append(group.name)
            elif isinstance(group, CellGroup):
                if not group.name:
                    print "Anonymous CellGroup cannot be used for input."
                    return False
                group_names.append(group.name)
            else:
                print "Unknown input group type."
                return False

        if not group_names:
            print "No groups specified for Input."
            return False

        model_parameters = self.buildModelParameters_(type_name, parameters)
        if not model_parameters:
            print "Failed to build model parameters for input"
            return False
        model_parameters.thisown = False
        input_group = pyncs.InputGroup(pyncs.string_list(group_names),
                                       model_parameters, probability,
                                       start_time, end_time)
        return self.simulation.addInput(input_group)
Exemplo n.º 6
0
 def BuildReports_(self):
   self.reports = {}
   for name, spec in self.report_definitions.items():
     target = pyncs.Report.Unknown 
     target_string = str(spec["target"])
     if target_string == "neuron":
       target = pyncs.Report.Neuron
     elif target_string == "synapse":
       target = pyncs.Report.Synapse
     else:
       print "invalid target specified in report %s" % name
       return False
     percentage = float(spec["percentage"])
     aliases = [ str(x) for x in spec["aliases"] ]
     report = pyncs.Report(pyncs.string_list(aliases),
                           target,
                           str(spec["attribute"]),
                           percentage)
     self.reports[str(name)] = report
   return True
Exemplo n.º 7
0
  def addReport(self, targets, target_type, attribute, probability, start_time, end_time):
    if not self.simulation.isMaster():
      return EmptyReport() 
    target = pyncs.Report.Unknown
    target_list = None
    if isinstance(targets, list):
      target_list = list(targets)
    else:
      target_list = [targets]
    target_names = None
    if target_type == "neuron":
      target = pyncs.Report.Neuron
      alias = CellAlias(None, targets)
      if not self.resolveCellAlias_(alias):
        print "A target was ill-defined."
        return None
      target_names = [ x.name for x in alias.subgroups ]
    elif target_type == "synapse":
      target = pyncs.Report.Synapse
      alias = ConnectionAlias(None, targets)
      if not self.resolveConnectionAlias_(alias):
        print "A target was ill-defined."
        return None 
      target_names = [ x.name for x in alias.subgroups ]
    else:
      print "Invalid target specified."
      return None 

    report = pyncs.Report(pyncs.string_list(target_names),
                          target,
                          attribute,
                          probability,
                          start_time,
                          end_time)
    data_source = self.simulation.addReport(report)
    if not data_source:
      print "Failed to add report."
      return None 
    return Report(data_source)
Exemplo n.º 8
0
Arquivo: ncs.py Projeto: starhxh/ncs
    def addReport(self, targets, target_type, attribute, probability,
                  start_time, end_time):
        if not self.simulation.isMaster():
            return EmptyReport()
        target = pyncs.Report.Unknown
        target_list = None
        if isinstance(targets, list):
            target_list = list(targets)
        else:
            target_list = [targets]
        target_names = None
        if target_type == "neuron":
            target = pyncs.Report.Neuron
            alias = CellAlias(None, targets)
            if not self.resolveCellAlias_(alias):
                print "A target was ill-defined."
                return None
            target_names = [x.name for x in alias.subgroups]
        elif target_type == "synapse":
            target = pyncs.Report.Synapse
            alias = ConnectionAlias(None, targets)
            if not self.resolveConnectionAlias_(alias):
                print "A target was ill-defined."
                return None
            target_names = [x.name for x in alias.subgroups]
        else:
            print "Invalid target specified."
            return None

        report = pyncs.Report(pyncs.string_list(target_names), target,
                              attribute, probability, start_time, end_time)
        data_source = self.simulation.addReport(report)
        if not data_source:
            print "Failed to add report."
            return None
        return Report(data_source)
Exemplo n.º 9
0
Arquivo: ncs.py Projeto: 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))
Exemplo n.º 10
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))