def test_injected_config(): pynn.setup(injected_config=pynn.InjectedConfiguration( pre_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()})) pynn.run(None) pynn.end() pynn.setup(injected_config=pynn.InjectedConfiguration( post_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron() })) pynn.run(None) pynn.end() pynn.setup(injected_config=pynn.InjectedConfiguration( pre_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()})) pynn.run(None) pynn.end() pynn.setup(injected_config=pynn.InjectedConfiguration( post_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()})) pynn.run(None) pynn.end() pynn.setup(injected_config=pynn.InjectedConfiguration( pre_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()}, post_non_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()}, pre_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()}, post_realtime={halco.AtomicNeuronOnDLS(): lola.AtomicNeuron()})) pynn.run(None) 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() # 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_default(self): pynn.setup() pop = pynn.Population(2, pynn.cells.HXNeuron(self.coco)) self.assertTrue(np.array_equal(pop.get("leak_i_bias"), [555, 0])) self.assertTrue( np.array_equal(pop.get("threshold_v_threshold"), [0, 123])) pynn.end()
def test_overflow(self): pynn.setup(neuronPermutation=self.permutation) pynn.Population(len(self.permutation), pynn.cells.HXNeuron()) with self.assertRaises(ValueError): pynn.Population(1, pynn.cells.HXNeuron()) pynn.end()
def test_permutation(self): coord = halco.AtomicNeuronOnDLS(halco.common.Enum(8)) neuron = lola.AtomicNeuron() neuron.leak.i_bias = 666 pynn.setup(neuronPermutation=[8]) pop = pynn.Population(1, pynn.cells.HXNeuron({coord: neuron})) self.assertEqual(pop.get("leak_i_bias"), 666) pynn.end()
def test_number_of_neurons(self): # TODO: grenade routing backend does not support 512 neurons? for n_neurons in [1, 16, 32, 64, 128, 256]: with self.subTest(n_neurons=n_neurons): pynn.setup() pynn.Population(n_neurons, pynn.cells.HXNeuron()) pynn.run(None) pynn.end()
def test_reset(self): pynn.setup(neuronPermutation=self.permutation) pynn.Population(1, pynn.cells.HXNeuron()) self.assertEqual( pynn.simulator.state.neuron_placement.id2hwenum(0), self.permutation[0]) pynn.reset() self.assertEqual( pynn.simulator.state.neuron_placement.id2hwenum(0), self.permutation[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 get_isi(tau_ref: int): pynn.setup() cell_params.update({"refractory_period_refractory_time": tau_ref}) pop = pynn.Population(1, pynn.cells.HXNeuron(**cell_params)) pop.record("spikes") pynn.run(0.2) spikes = pop.get_data("spikes").segments[0].spiketrains[0] if len(spikes) == 0: return 0 isi = np.zeros(len(spikes) - 1) for i in range(len(spikes) - 1): isi[i] = spikes[i + 1] - spikes[i] pynn.end() return np.mean(isi)
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 test_mixed_celltypes(self): pynn.setup(neuronPermutation=self.permutation) pynn.Population(1, pynn.cells.SpikeSourceArray(spike_times=[0])) pynn.Population(2, pynn.cells.HXNeuron()) pynn.Population(1, pynn.cells.SpikeSourceArray(spike_times=[0])) pynn.Population(1, pynn.cells.HXNeuron()) self.assertEqual( pynn.simulator.state.neuron_placement.id2hwenum(1), self.permutation[0]) self.assertEqual( pynn.simulator.state.neuron_placement.id2hwenum(2), self.permutation[1]) self.assertEqual( pynn.simulator.state.neuron_placement.id2hwenum(4), self.permutation[2]) pynn.end()
def test_coco_extraction(self): builder = sta.PlaybackProgramBuilderDumper() an_coord0 = halco.AtomicNeuronOnDLS(halco.common.Enum(0)) an_coord1 = halco.AtomicNeuronOnDLS(halco.common.Enum(1)) neuron0 = lola.AtomicNeuron() neuron0.leak.i_bias = 666 neuron1 = lola.AtomicNeuron() neuron1.leak.i_bias = 420 builder.write(an_coord0, neuron0) builder.write(an_coord1, neuron1) common_config = hal.CommonNeuronBackendConfig() common_config.clock_scale_fast = 3 common_coord = halco.CommonNeuronBackendConfigOnDLS() builder.write(common_coord, common_config) full_coco = {} with tempfile.TemporaryDirectory() as tempdir: filename = os.path.join(tempdir, "dump") with open(filename, "wb") as fd: fd.write(sta.to_binary(builder.done())) full_coco = pynn.helper.coco_from_file(filename) self.assertTrue(an_coord0 in full_coco) self.assertTrue(an_coord1 in full_coco) hx_coco = pynn.helper.filter_atomic_neuron(full_coco) self.assertTrue(an_coord0 in hx_coco) self.assertTrue(an_coord1 in hx_coco) self.assertFalse(common_coord in hx_coco) remainder_coco = pynn.helper.filter_non_atomic_neuron(full_coco) self.assertFalse(an_coord0 in remainder_coco) self.assertTrue(common_coord in remainder_coco) self.assertEqual(remainder_coco[common_coord].clock_scale_fast, 3) pynn.setup() pop = pynn.Population(2, pynn.cells.HXNeuron(hx_coco)) self.assertTrue(numpy.array_equal(pop.get("leak_i_bias"), [666, 420])) pynn.run(None) 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 main(params: dict): log = pynn.logger.get("leak_over_threshold") pynn.setup() pop2 = pynn.Population(2, pynn.cells.HXNeuron(**params)) pop1 = pynn.Population(1, pynn.cells.HXNeuron(**params)) pop1.record(["spikes", "v"]) pop2.record("spikes") pynn.run(0.2) spikes1 = pop1.get_data("spikes").segments[0] spikes2 = pop2.get_data("spikes").segments[0] # TODO: Find out how to extract neuron ids. for i, spiketrain in enumerate(spikes2.spiketrains): log.INFO("Number of Spikes of Neuron {}: ".format(i + 1), len(spiketrain)) log.INFO("Spiketimes of Neuron {}: ".format(i + 1), spiketrain) spiketimes = spikes1.spiketrains[0] log.INFO("Number of spikes of single recorded neuron: ", len(spiketimes)) log.INFO("Spiketimes of recorded neuron: ", spiketimes) mem_v = pop1.get_data("v").segments[0] times, membrane = zip(*mem_v.filter(name="v")[0]) log.INFO("Number of MADC Samples: ", len(times)) plt.figure() plt.xlabel("Time [ms]") plt.ylabel("Membrane Potential [LSB]") plt.plot(times, membrane) plt.savefig("plot_leak_over_threshold.pdf") plt.close() pynn.end()
def tearDown(self): pynn.run(None) pynn.end()
def test_missing_coco_entries(self): pynn.setup() pynn.Population(2, pynn.cells.HXNeuron(self.coco)) with self.assertRaises(KeyError): pynn.Population(1, pynn.cells.HXNeuron(self.coco)) pynn.end()
# 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! pynn.run(0.1) times, data = plot_membrane_dynamics(stimulated_p) L.append(data) pynn.end() if i == 0 and j == 0: np.save('times.npy', times) LL.append(L) plt.savefig('v' + str(i) + '.pdf') np.save('LL.npy', np.array(LL)) plt.show()
def tearDown(self): pynn.end()
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_permutation_mismatch(self): pynn.setup(neuronPermutation=[8, 14]) with self.assertRaises(KeyError): pynn.Population(2, pynn.cells.HXNeuron(self.coco)) pynn.end()
def test_user_overwrite(self): pynn.setup() pop = pynn.Population( 2, pynn.cells.HXNeuron(self.coco, leak_i_bias=[100, 150])) self.assertTrue(np.array_equal(pop.get("leak_i_bias"), [100, 150])) pynn.end()
def test_empty(): pynn.setup() pynn.run(0.2) pynn.end()