Beispiel #1
0
def end(compatible_output=True):
    """Do any necessary cleaning up before exiting."""
    for (population, variables, filename) in simulator.state.write_on_end:
        io = get_io(filename)
        population.write_data(io, variables)
    simulator.state.write_on_end = []

    nml_doc = simulator._get_nml_doc()

    import neuroml.writers as writers
    if save_format == 'xml':
        nml_file = '%s.net.nml' % nml_doc.id
        writers.NeuroMLWriter.write(nml_doc, nml_file)
    elif save_format == 'hdf5':
        nml_file = '%s.net.nml.h5' % nml_doc.id
        writers.NeuroMLHdf5Writer.write(nml_doc, nml_file)

    logger.info("Written NeuroML 2 file out to: " + nml_file)

    lems_sim = simulator._get_lems_sim()
    lems_sim.include_neuroml2_file("PyNN.xml", include_included=False)
    lems_sim.include_neuroml2_file(nml_file)
    lems_file = lems_sim.save_to_file()
    logger.info("Written LEMS file (to simulate NeuroML file) to: " +
                lems_file)
Beispiel #2
0
def setup(timestep=DEFAULT_TIMESTEP,
          min_delay=DEFAULT_MIN_DELAY,
          **extra_params):
    """ Set up for saving cell models and network structure to NeuroML """
    common.setup(timestep, min_delay, **extra_params)
    simulator.state.clear()
    simulator.state.dt = timestep  # move to common.setup?
    simulator.state.min_delay = min_delay
    simulator.state.max_delay = extra_params.get('max_delay',
                                                 DEFAULT_MAX_DELAY)
    simulator.state.mpi_rank = extra_params.get('rank', 0)
    simulator.state.num_processes = extra_params.get('num_processes', 1)

    logger.debug("Creating network in NeuroML document to store structure")
    nml_doc = simulator._get_nml_doc(extra_params.get('reference',
                                                      "PyNN_NeuroML2_Export"),
                                     reset=True)
    global save_format
    save_format = extra_params.get('save_format', "xml")

    # Create network
    net = neuroml.Network(id=nml_doc.id)
    nml_doc.networks.append(net)

    lems_sim = simulator._get_lems_sim(reset=True)
    lems_sim.dt = '%s' % timestep

    return rank()
Beispiel #3
0
 def add_to_nml_doc(self, nml_doc, cells):
     ci = neuroml.CompoundInput(id=self.get_id_for_nml(cells))
  
     num_steps = len(self.amplitudes)
     for i in range(num_steps):
         next_time = 1e9 if i==num_steps-1 else self.times[i+1]
         ci.pulse_generators.append(neuroml.PulseGenerator(id='step_%s'%i,delay='%sms'%self.times[i],duration='%sms'%(next_time-self.times[i]),amplitude='%snA'%self.amplitudes[i]))
         
     self.nml_doc = _get_nml_doc()
     self.nml_doc.compound_inputs.append(ci)
     return ci.id
Beispiel #4
0
 def add_to_nml_doc(self, nml_doc, cells):
     id=self.get_id_for_nml(cells)
     pg = neuroml.PulseGenerator(id=id,
                                   delay='%sms'%self.start,
                                   duration='%sms'%(self.stop-self.start),
                                   amplitude='%snA'%self.amplitude)
  
     self.nml_doc = _get_nml_doc()
     found = False
     for pg in self.nml_doc.pulse_generators:
         if pg.id==id: found = True
     if not found:
         self.nml_doc.pulse_generators.append(pg)
     return pg.id
    def __init__(self, **parameters):
        super(StandardCurrentSource, self).__init__(**parameters)
        global current_sources
        self.cell_list = []
        self.indices = []
        self.ind = len(current_sources)  # Todo use self.indices instead...
        current_sources.append(self)
        parameter_space = ParameterSpace(self.default_parameters,
                                         self.get_schema(),
                                         shape=(1, ))
        parameter_space.update(**parameters)
        parameter_space = self.translate(parameter_space)
        self.set_native_parameters(parameter_space)

        self.nml_doc = _get_nml_doc()
        self.network = _get_main_network()
Beispiel #6
0
 def inject_into(self, cells):
     __doc__ = StandardCurrentSource.inject_into.__doc__
     
     logger.debug("%s injecting into: %s"%(self.__class__.__name__, cells))
     
     self.nml_doc = _get_nml_doc()
     id = self.add_to_nml_doc(self.nml_doc, cells)
     
     
     
     for cell in cells:
         pop_id = cell.parent.label
         index = cell.parent.id_to_index(cell)
         celltype = cell.parent.celltype.__class__.__name__
         logger.debug("Injecting: %s to %s (%s[%s])"%(id, cell, pop_id, index))
         
         input_list = self._get_input_list(id, pop_id)
         
         input = neuroml.Input(id=len(input_list.input), 
                           target="../%s/%i/%s_%s"%(pop_id, index, celltype, pop_id), 
                           destination="synapses")  
         input_list.input.append(input)
Beispiel #7
0
 def add_to_nml_doc(self, nml_doc, cells):
     
     ci = neuroml.CompoundInput(id=self.get_id_for_nml(cells))
 
     sg = neuroml.SineGenerator(id='SG_'+self.get_id_for_nml(cells),
                          delay='%sms'%self.start,
                          duration='%sms'%(self.stop-self.start),
                          amplitude='%snA'%self.amplitude,
                          period='%s s'%(1/float(self.frequency)),
                          phase=(3.14159265 * self.phase/180))
                          
     pg = neuroml.PulseGenerator(id='PG_'+self.get_id_for_nml(cells),
                                   delay='%sms'%self.start,
                                   duration='%sms'%(self.stop-self.start),
                                   amplitude='%snA'%self.offset)
  
     ci.sine_generators.append(sg)
     ci.pulse_generators.append(pg)
     
     self.nml_doc = _get_nml_doc()
     self.nml_doc.compound_inputs.append(ci)
     return ci.id
Beispiel #8
0
def end(compatible_output=True):
    """Do any necessary cleaning up before exiting."""
    for (population, variables, filename) in simulator.state.write_on_end:
        io = get_io(filename)
        population.write_data(io, variables)
    simulator.state.write_on_end = []
    
    nml_doc = simulator._get_nml_doc()

    import neuroml.writers as writers
    if save_format == 'xml':
        nml_file = '%s.net.nml'%nml_doc.id
        writers.NeuroMLWriter.write(nml_doc, nml_file)
    elif save_format == 'hdf5':
        nml_file = '%s.net.nml.h5'%nml_doc.id
        writers.NeuroMLHdf5Writer.write(nml_doc, nml_file)
        
    logger.info("Written NeuroML 2 file out to: "+nml_file)
    
    lems_sim = simulator._get_lems_sim()
    lems_sim.include_neuroml2_file("PyNN.xml", include_included=False)
    lems_sim.include_neuroml2_file(nml_file)
    lems_file = lems_sim.save_to_file()
    logger.info("Written LEMS file (to simulate NeuroML file) to: "+lems_file)
Beispiel #9
0
def setup(timestep=DEFAULT_TIMESTEP, min_delay=DEFAULT_MIN_DELAY,
          **extra_params):
    """ Set up for saving cell models and network structure to NeuroML """
    common.setup(timestep, min_delay, **extra_params)
    simulator.state.clear()
    simulator.state.dt = timestep  # move to common.setup?
    simulator.state.min_delay = min_delay
    simulator.state.max_delay =  extra_params.get('max_delay', DEFAULT_MAX_DELAY)
    simulator.state.mpi_rank = extra_params.get('rank', 0)
    simulator.state.num_processes = extra_params.get('num_processes', 1)

    logger.debug("Creating network in NeuroML document to store structure")
    nml_doc = simulator._get_nml_doc(extra_params.get('reference', "PyNN_NeuroML2_Export"),reset=True)
    global save_format
    save_format = extra_params.get('save_format', "xml")
    
    # Create network
    net = neuroml.Network(id="network")
    nml_doc.networks.append(net)
    
    lems_sim = simulator._get_lems_sim(reset=True)
    lems_sim.dt = '%s'%timestep

    return rank()