Esempio n. 1
0
    def simulate(self, **kwargs):

        data = kwargs[str('x_b_l')]
        if self.data_format == 'channels_last' and data.ndim == 4:
            data = np.moveaxis(data, 3, 1)

        x_flat = np.ravel(data)
        if self._poisson_input:
            self.layers[0].set(rate=list(x_flat / self.rescale_fac * 1000))
        elif self._dataset_format == 'aedat':
            raise NotImplementedError
        else:
            spike_times = \
                [np.linspace(0, self._duration, self._duration * amplitude)
                 for amplitude in x_flat]
            self.layers[0].set(spike_times=spike_times)

        if is_module_installed('pynn_object_serialisation'):
            from pynn_object_serialisation.functions import intercept_simulator
            current_time = time.strftime("_%H%M%S_%d%m%Y")
            intercept_simulator(self.sim, "snn_toolbox_pynn_" + current_time)

        self.sim.run(self._duration - self._dt,
                     callbacks=[MyProgressBar(self._dt, self._duration)])
        print("\nCollecting results...")
        output_b_l_t = self.get_recorded_vars(self.layers)

        return output_b_l_t
    def simulate(self, **kwargs):
        self.sim.set_number_of_neurons_per_core(
            self.sim.IF_curr_exp,
            self.config.getfloat('spinnaker', 'number_of_neurons_per_core'))
        data = kwargs[str('x_b_l')]
        if self.data_format == 'channels_last' and data.ndim == 4:
            data = np.moveaxis(data, 3, 1)

        x_flat = np.ravel(data)
        if self._poisson_input:
            rates = 1000 * x_flat / self.rescale_fac
            self.layers[0].set(rate=rates)
        elif self._dataset_format == 'aedat':
            raise NotImplementedError
        else:
            spike_times = \
                [np.linspace(0, self._duration, self._duration * amplitude)
                 for amplitude in x_flat]
            self.layers[0].set(spike_times=spike_times)
        import pylab
        current_time = pylab.datetime.datetime.now().strftime("_%H%M%S_%d%m%Y")

        runlabel = self.config.get("paths", "runlabel")

        try:
            from pynn_object_serialisation.functions import intercept_simulator
            intercept_simulator(self.sim,
                                runlabel + "_serialised",
                                post_abort=False,
                                custom_params={'runtime': self._duration})
        except Exception:
            print("There was a problem with serialisation.")
        if self.config.getboolean('tools', 'serialise_only'):
            import sys
            sys.exit('finished after serialisation')
        self.sim.run(self._duration)
        print("\nCollecting results...")
        output_b_l_t = self.get_recorded_vars(self.layers)

        return output_b_l_t
spikeArray = {'spike_times': [[0]]}
main_pop = p.Population(nNeurons,
                        p.IF_cond_exp(**cell_params_lif),
                        label='pop_1')
input_pop = p.Population(1,
                         p.SpikeSourceArray(**spikeArray),
                         label='inputSpikes_1')

p.Projection(main_pop, main_pop, p.FromListConnector(loopConnections),
             p.StaticSynapse(weight=weight_to_spike, delay=delay))
p.Projection(input_pop, main_pop, p.FromListConnector(injectionConnection),
             p.StaticSynapse(weight=weight_to_spike, delay=1))

main_pop.record(['v', 'gsyn_exc', 'gsyn_inh', 'spikes'])

intercept_simulator(p, "sim_synfire_if_cond_exp")

from importlib import reload

p = reload(p)
populations, projections = restore_simulator_from_file(
    p, "sim_synfire_if_cond_exp")
p.run(runtime)

# get data (could be done as one, but can be done bit by bit as well)
v = main_pop.get_data('v')
gsyn_exc = main_pop.get_data('gsyn_exc')
gsyn_inh = main_pop.get_data('gsyn_inh')
spikes = main_pop.get_data('spikes')

figure_filename = "results.png"
                                      SpikeSourcePoissonVariable(
                                          starts=slots_starts,
                                          rates=rates,
                                          durations=durations),
                                      label='poisson_source')

lif_pop = sim.Population(N_layer, sim.IF_curr_exp, label='pop_1')

conns = [[x, x] for x in range(N_layer)]
sim.Projection(poisson_spike_source, lif_pop, sim.FromListConnector(conns),
               sim.StaticSynapse(weight=2, delay=1))

poisson_spike_source.record(['spikes'])
lif_pop.record(['spikes'])

intercept_simulator(sim, "variable_rate_pss")
sim.run(runtime)
pss_spikes = poisson_spike_source.spinnaker_get_data('spikes')
lif_spikes = lif_pop.spinnaker_get_data('spikes')
sim.end()

from importlib import reload

sim = reload(sim)
populations, projections, _ = restore_simulator_from_file(
    sim, "variable_rate_pss")
sim.set_number_of_neurons_per_core(SpikeSourcePoissonVariable, 13)
intercept_simulator(sim, "comparison_variable_rate_pss")
# PSS recording is not picked up by interception!
populations[0].record(['spikes'])
sim.run(runtime)
runtime = 5000
sim.setup(timestep=1.0, min_delay=1.0, max_delay=10.0)
nNeurons = 200  # number of neurons in each population

# Spike sources
poisson_spike_source = sim.Population(nNeurons,
                                      sim.SpikeSourcePoisson(rate=[[50]] *
                                                             nNeurons,
                                                             duration=runtime),
                                      label='poisson_source')

lif_pop = sim.Population(nNeurons, sim.IF_curr_exp, label='pop_1')

loopConnections = list()
for i in range(0, nNeurons):
    singleConnection = ((i, (i + 1) % nNeurons, 1, 1))

    loopConnections.append(singleConnection)
sim.Projection(poisson_spike_source, lif_pop,
               sim.FromListConnector(loopConnections))

intercept_simulator(sim, "one_pss")

from importlib import reload

sim = reload(sim)
populations, projections, _ = restore_simulator_from_file(sim, "one_pss")
intercept_simulator(sim, "comparison_one_pss")
sim.run(runtime)
sim.end()
        receptor_type='excitatory',
        synapse_type=p.StaticSynapse(weight=0.1))

# === Setup recording ===
print("%s Setting up recording..." % node_id)
exc_cells.record("spikes")

buildCPUTime = timer.diff()

# === Run simulation ===
print("%d Running simulation..." % node_id)

print("timings: number of neurons: {}".format(n))
print("timings: number of synapses: {}".format(n * n * pconn))

intercept_simulator(p, "va_benchmark")

from importlib import reload

p = reload(p)
populations, projections, _ = restore_simulator_from_file(p, "va_benchmark")
intercept_simulator(p, "comparison_va_benchmark")
p.run(tstop)

simCPUTime = timer.diff()

# === Print results to file ===

exc_spikes = exc_cells.get_data("spikes")

Figure(
weight_to_spike = 2.0
delay = 17

loopConnections = list()
for i in range(0, nNeurons):
    singleConnection = ((i, (i + 1) % nNeurons, weight_to_spike, delay))
    loopConnections.append(singleConnection)

injectionConnection = [(0, 0)]
spikeArray = {'spike_times': [[0]]}
populations.append(
    p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif), label='pop_1'))
populations.append(
    p.Population(1, p.SpikeSourceArray(**spikeArray), label='inputSpikes_1'))

projections.append(
    p.Projection(populations[0], populations[0],
                 p.FromListConnector(loopConnections),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay)))
projections.append(
    p.Projection(populations[1], populations[0],
                 p.FromListConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=1)))

intercept_simulator(p)
p.run(runtime)

print(projections[0].get(['weight', 'delay'], 'list'))

p.end()
Esempio n. 8
0
                 p.SpikeSourceArray,
                 cellparams=spikeArray,
                 label='inputSpikes_1'))

projections.append(
    p.Projection(populations[0], populations[0],
                 p.FromListConnector(loopConnections),
                 p.StaticSynapse(weight=weight_to_spike, delay=delay)))
projections.append(
    p.Projection(populations[1], populations[0],
                 p.FromListConnector(injectionConnection),
                 p.StaticSynapse(weight=weight_to_spike, delay=1)))

populations[0].record(['v', 'gsyn_exc', 'gsyn_inh', 'spikes'])

intercept_simulator(p, "sim_synfire_if_curr_exp")

from importlib import reload

p = reload(p)
populations, projections, _ = restore_simulator_from_file(
    p, "sim_synfire_if_curr_exp")
intercept_simulator(p, "comparison_sim_synfire_if_curr_exp")
p.run(runtime)

# get data (could be done as one, but can be done bit by bit as well)
v = populations[0].get_data('v')
gsyn_exc = populations[0].get_data('gsyn_exc')
gsyn_inh = populations[0].get_data('gsyn_inh')
spikes = populations[0].get_data('spikes')