def test_weight(self): proj = pynn.Projection(self.pop1, self.pop1, pynn.AllToAllConnector()) self.assertEqual(proj.get("weight", format="array"), 0) pynn.run(None) pynn.simulator.state.projections = [] synapse = pynn.standardmodels.synapses.StaticSynapse(weight=32) proj = pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector(), synapse_type=synapse) self.assertEqual(proj.get("weight", format="array"), 32) proj.set(weight=42.5) self.assertEqual(proj.get("weight", format="array"), 42) proj.set(weight=43) self.assertEqual(proj.get("weight", format="list"), [(0, 0, 43)]) with self.assertRaises(ValueError): proj.set(weight=64) with self.assertRaises(ValueError): proj.set(weight=-1) proj = pynn.Projection(self.pop3, self.pop4, pynn.AllToAllConnector(), synapse_type=synapse) connection_list = [(0, 0, 32), (1, 0, 32), (0, 1, 32), (1, 1, 32), (0, 2, 32), (1, 2, 32)] self.assertEqual(proj.get("weight", format="list"), connection_list) proj = pynn.Projection(self.pop4, self.pop3, pynn.AllToAllConnector(), synapse_type=synapse) connection_list = [(0, 0, 32), (1, 0, 32), (2, 0, 32), (0, 1, 32), (1, 1, 32), (2, 1, 32)] self.assertEqual(proj.get("weight", format="list"), connection_list) pynn.run(None)
def test_identicalprojection(self): for pop in self.pops: for pop_in in self.pops_in.values(): pynn.Projection(pop_in, pop, pynn.OneToOneConnector()) pynn.Projection(pynn.PopulationView(pop_in, [0]), pop, pynn.OneToOneConnector())
def test_timing_of_spikes(self): """ Test whether the output spikes have approximately the same timing as the input spikes. """ runtime = 100 # ms n_spikes = 1000 pop_1 = pynn.Population(1, pynn.cells.HXNeuron()) pop_1.record('spikes') pop_2 = pynn.Population(1, pynn.cells.HXNeuron()) pop_2.record('spikes') # Inject spikes spikes_1 = np.arange(0.1, runtime, runtime / n_spikes) input_pop_1 = pynn.Population(1, pynn.cells.SpikeSourceArray( spike_times=spikes_1)) pynn.Projection(input_pop_1, pop_1, pynn.AllToAllConnector(), synapse_type=StaticSynapse(weight=63)) # Take midpoints of spikes_1 to have some variation in timing and spikes_2 = (spikes_1[:-1] + spikes_1[1:]) / 2 input_pop_2 = pynn.Population(1, pynn.cells.SpikeSourceArray( spike_times=spikes_2)) pynn.Projection(input_pop_2, pop_2, pynn.AllToAllConnector(), synapse_type=StaticSynapse(weight=63)) pynn.run(runtime) # Make sure that at least 98% (estimate considering typical spike # loss) of the spikes are read back and that the time difference # between them is less than 0.01ms. # To accomplish that we round the spike times to two decimal places # and then compare the sets of the input and output spike times. # By default numpy does not round '5' to the next higher number but # to the next even number, e.g. np.round(2.5) == 2. Therefore, we # add a small number such that timestamps with a '5' at the third # decimal place are rounded up to the next higher (and not even) number input_set_1 = set(np.round(spikes_1 + 1e-9, 2)) output_set_1 = set(np.round( pop_1.get_data().segments[0].spiketrains[0].magnitude + 1e-9, 2)) self.assertLess(len(input_set_1 - output_set_1) / len(input_set_1), 0.02) input_set_2 = set(np.round(spikes_2 + 1e-9, 2)) output_set_2 = set(np.round( pop_2.get_data().segments[0].spiketrains[0].magnitude + 1e-9, 2)) self.assertLess(len(input_set_2 - output_set_2) / len(input_set_2), 0.02)
def test_number_of_spike_trains(self): """ Here we test that only spikes are recorded for the neurons we set in the spike recording mode. """ runtime = 0.5 # ms pop_size = 4 pops = [] pops.append(pynn.Population(pop_size, pynn.cells.HXNeuron())) pops.append(pynn.Population(pop_size, pynn.cells.HXNeuron())) pops.append(pynn.Population(pop_size, pynn.cells.HXNeuron())) # Once record whole population, once subset and once no neurons pops[0].record(['spikes']) pynn.PopulationView(pops[1], [0]).record(['spikes']) # Spike input input_pop = pynn.Population(1, pynn.cells.SpikeSourceArray( spike_times=np.arange(0.1, runtime, runtime / 10))) for pop in pops: pynn.Projection(input_pop, pop, pynn.AllToAllConnector(), synapse_type=StaticSynapse(weight=63)) pynn.run(runtime) # Assert correct number of recorded spike trains self.assertEqual(len(pops[0].get_data().segments[0].spiketrains), pop_size) self.assertEqual(len(pops[1].get_data().segments[0].spiketrains), 1) self.assertEqual(len(pops[2].get_data().segments[0].spiketrains), 0)
def test_bypass(self): # Create network with single SpikeSourceArray which projects on a # single HX neuron spikes_in = self.poisson_spike_train(self.rate) input_pop = pynn.Population(1, pynn.cells.SpikeSourceArray, cellparams={"spike_times": spikes_in}) output_pop = pynn.Population(1, pynn.cells.HXNeuron()) output_pop.record(["spikes"]) synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63) pynn.Projection(input_pop, output_pop, pynn.AllToAllConnector(), synapse_type=synapse) # Run experiment on chip pynn.run(self.runtime) # Make sure that at least 98% (estimate considering typical spike # loss) of the spikes are read back and that the time difference # between them is less than 0.01ms spikes_out = output_pop.get_data().segments[0].spiketrains[0].magnitude # Add a small number such that timestamps with a '5' the third decimal # place are rounded up to the next higher (and not to the next even) # number input_set = set(np.round(spikes_in + 1e-9, 2)) output_set = set(np.round(spikes_out + 1e-9, 2)) assert len(input_set - output_set) / len(input_set) < 0.02
def main(params: dict): pynn.setup() nrn = pynn.Population(1, pynn.cells.HXNeuron(**params)) nrn.record(["spikes", "v"]) spike_times = [0.01, 0.03, 0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.17, 0.19] pop_input = pynn.Population(20, pynn.cells.SpikeSourceArray, cellparams={"spike_times": spike_times}) synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63) pynn.Projection(pop_input, nrn, pynn.AllToAllConnector(), synapse_type=synapse) pynn.run(0.2) spiketrain = nrn.get_data("spikes").segments[0].spiketrains[0] mem_v = nrn.get_data("v").segments[0] membrane_times, membrane_voltage = zip(*mem_v.filter(name="v")[0]) pynn.end() # Plot data plt.figure() plt.xlabel("Time [ms]") plt.ylabel("Membrane Potential [LSB]") plt.plot(membrane_times, membrane_voltage) plt.savefig("plot_external_input.pdf") plt.close() return spiketrain
def test_delay(self): proj = pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector()) self.assertEqual(proj.get("delay", format="array"), [0]) proj.set(delay=0) self.assertEqual(proj.get("delay", format="array"), [0]) with self.assertRaises(ValueError): proj.set(delay=1) pynn.run(None)
def setUp(self): self.bg_props = dict( start=1, # ms rate=20e3, # Hz duration=100 # ms ) # Emulate the network 1ms longer than Poisson stimulation, in order to # convince oneself that the stimulation ends properly. self.runtime = self.bg_props["start"] + self.bg_props["duration"] + 1 # The refractory time was found to must be set slightly larger 0 (DAC # value) to achieve a short time on hardware (cf. #3741). neuron_params = {"refractory_period_refractory_time": 5} # By enabling the bypass mode, the neuron should spike at the income of # each event. pynn.setup(enable_neuron_bypass=True) pop1 = pynn.Population(1, pynn.cells.HXNeuron(**neuron_params)) pop2 = pynn.Population(1, pynn.cells.HXNeuron(**neuron_params)) pop1.record(["spikes"]) pop2.record(["spikes"]) src = pynn.Population(1, pynn.cells.SpikeSourcePoisson(**self.bg_props)) pynn.Projection(src, pop1, pynn.AllToAllConnector(), synapse_type=StaticSynapse(weight=63)) pynn.Projection(src, pop2, pynn.AllToAllConnector(), synapse_type=StaticSynapse(weight=63)) pynn.run(self.runtime) self.spiketrain1 = pop1.get_data("spikes").segments[0].spiketrains[0] self.spiketrain2 = pop2.get_data("spikes").segments[0].spiketrains[0] pynn.reset() self.rate3 = 10e3 src.set(rate=self.rate3) pynn.run(self.runtime) self.spiketrain3 = pop1.get_data("spikes").segments[1].spiketrains[0] pynn.end()
def main(): """ Run a minimal pyNN-based experiment: Connect two neuron populations and run an emulation. More elaborate examples of using BrainScaleS-2 through the pyNN-API can be found here: https://github.com/electronicvisions/pynn-brainscales/tree/master/brainscales2/examples """ pynn.setup() neurons_1 = get_neuron_population(2) neurons_2 = get_neuron_population(3) pynn.Projection(neurons_1, neurons_2, pynn.AllToAllConnector()) pynn.run(0.2) pynn.end()
def main(params: dict): pynn.setup() nrn = pynn.Population(1, pynn.cells.HXNeuron(**params)) nrn.record(["spikes", "v"]) spike_times = [0.01, 0.03, 0.05, 0.07, 0.09, 0.11, 0.13, 0.15, 0.17, 0.19] pop_input = pynn.Population(20, pynn.cells.SpikeSourceArray, cellparams={"spike_times": spike_times}) synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63) pynn.Projection(pop_input, nrn, pynn.AllToAllConnector(), synapse_type=synapse) pynn.run(0.2) spiketrain = nrn.get_data("spikes").segments[0].spiketrains[0] mem_v = nrn.get_data("v").segments[0] membrane_times, membrane_voltage = zip(*mem_v.filter(name="v")[0]) pynn.end() return spiketrain, membrane_times, membrane_voltage
def test_identical_connection(self): pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector()) pynn.Projection(self.pop1, self.pop2, pynn.AllToAllConnector()) pynn.run(None)
def test_poppopalltoall(self): for pop in self.pops: for pop_in in self.pops_in.values(): pynn.Projection(pop_in, pop, pynn.AllToAllConnector())
def test_popview1to1(self): for pop in self.pops: for pop_in in self.pops_in.values(): pynn.Projection(pop_in, pynn.PopulationView(pop, [0]), pynn.OneToOneConnector())
def test_poppop1to1(self): for pop in self.pops: for pop_in in self.pops_in.values(): pynn.Projection(pop_in, pop, pynn.OneToOneConnector())
def main(): main_log = pynn.logger.get("internal_projections_main") pynn.setup() lot_values = { "threshold_v_threshold": 400, "leak_v_leak": 1022, "leak_i_bias": 420, "leak_enable_division": True, "reset_v_reset": 50, "reset_i_bias": 950, "reset_enable_multiplication": True, "threshold_enable": True, "membrane_capacitance_capacitance": 10, "refractory_period_refractory_time": 95 } cell_params = deepcopy(lot_values) cell_params.update({ "leak_v_leak": 650, "reset_v_reset": 650, "excitatory_input_enable": True, "excitatory_input_i_bias_tau": 150, "excitatory_input_i_bias_gm": 200, # FIXME: replace by i_drop_input and i_shift_reference # "excitatory_input_v_syn": 700}) }) # not leak over threshold pop1 = pynn.Population(1, pynn.standardmodels.cells.HXNeuron(**cell_params)) # leak over threshold pop2 = pynn.Population(100, pynn.standardmodels.cells.HXNeuron(**lot_values)) pop1.record(["spikes", "v"]) pop2.record("spikes") synapse = pynn.standardmodels.synapses.StaticSynapse(weight=63) pynn.Projection(pop2, pop1, pynn.AllToAllConnector(), synapse_type=synapse) pynn.run(0.2) spiketimes1 = pop1.get_data("spikes").segments[0].spiketrains[0] main_log.INFO("Spiketimes of first neuron: ", spiketimes1) spikes2 = pop2.get_data("spikes").segments[0] spikenumber2 = 0 for i in range(len(pop2)): spikes = len(spikes2.spiketrains[i]) spikenumber2 += spikes main_log.INFO("Number of spikes from pop2: ", spikenumber2) mem_v = pop1.get_data("v").segments[0] membrane_times, membrane_voltage = zip(*mem_v.filter(name="v")[0]) pynn.end() # Plot data plt.figure() plt.xlabel("Time [ms]") plt.ylabel("Membrane Potential [LSB]") plt.plot(membrane_times, membrane_voltage) plt.savefig("plot_internal_projections.pdf") plt.close() return len(spiketimes1)
def test_popviewalltoall(self): for pop in self.pops: for pop_in in self.pops_in.values(): pynn.Projection(pop_in, pynn.PopulationView(pop, [0]), pynn.AllToAllConnector())
excitatory_input_i_shift_reference=300, inhibitory_input_i_shift_reference=300)) stimulated_p.record(["v", "spikes"]) # Create off-chip populations serving as excitatory external spike sources exc_spiketimes = [0.01, 0.05, 0.07, 0.08] exc_stim_pop = pynn.Population(1, SpikeSourceArray(spike_times=exc_spiketimes)) # We represent projections as entries in the synapse matrix on the neuromorphic # chip. Weights are stored in digital 6bit values (plus sign), the value # range for on-chip weights is therefore -63 to 63. # With this first projection, we connect the external spike source to the # observed on-chip neuron population. pynn.Projection(exc_stim_pop, stimulated_p, pynn.AllToAllConnector(), synapse_type=StaticSynapse(weight=63), receptor_type="excitatory") # Create off-chip populations serving as inhibitory external spike sources. inh_spiketimes = [0.03] inh_stim_pop = pynn.Population(1, SpikeSourceArray(spike_times=inh_spiketimes)) pynn.Projection(inh_stim_pop, stimulated_p, pynn.AllToAllConnector(), synapse_type=StaticSynapse(weight=63), receptor_type="inhibitory") # You may play around with the parameters in this experiment to achieve # different traces. Try to stack multiple PSPs, try to make the neurons spike, # try to investigate differences between individual neuron instances, # be creative!