def test_placement_constraint(self): """ test the get_placements call. """ sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 50) pop_1 = sim.Population(200, sim.IF_curr_exp(), label="pop_1") pop_1.add_placement_constraint(x=1, y=1) input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") sim.Projection(input, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) simtime = 10 sim.run(simtime) placements = self.get_placements("pop_1") sim.end() self.assertGreater(len(placements), 0) for [x, y, _] in placements: self.assertEqual("1", x) self.assertEqual("1", y)
def do_run(nNeurons): p.setup(timestep=0.1, min_delay=1.0, max_delay=7.5) p.set_number_of_neurons_per_core(p.IF_curr_exp, 100) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 10.0, 'tau_refrac': 2.0, 'tau_syn_E': 0.5, 'tau_syn_I': 0.5, 'v_reset': -65.0, 'v_rest': -65.0, 'v_thresh': -64.4 } populations = list() projections = list() weight_to_spike = 0.5 injection_delay = 2 spikeArray = {'spike_times': [[0, 10, 20, 30]]} populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='pop_0')) populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_2')) connector = p.AllToAllConnector() synapse_type = p.StaticSynapse(weight=weight_to_spike, delay=injection_delay) projections.append( p.Projection(populations[0], populations[1], connector, synapse_type=synapse_type)) connector = p.AllToAllConnector() projections.append( p.Projection(populations[1], populations[2], connector, synapse_type=synapse_type)) populations[2].record("v") populations[2].record("spikes") p.run(100) neo = populations[2].get_data(["v", "spikes"]) v = neo_convertor.convert_data(neo, name="v") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, spikes)
def do_run(n_neurons, n_cores, new_i_offset): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core(p.IF_curr_exp, n_neurons / n_cores) cell_params_lif = {'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } populations = list() populations.append(p.Population(n_neurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations[0].record("all") p.run(2000) populations[0].set(i_offset=new_i_offset) p.run(2000) neo = populations[0].get_data() p.end() return neo
def do_run(self): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, neurons_per_core) input_spikes = list(range(0, simtime - 50, 10)) input = sim.Population(1, sim.SpikeSourceArray(spike_times=input_spikes), label="input") pop_1 = sim.Population(n_neurons, sim.IF_curr_exp(), label="pop_1") sim.Projection(input, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) pop_1.record(["spikes", "v", "gsyn_exc"]) sim.run(simtime) sim.reset() pop_2 = sim.Population(n_neurons, sim.IF_curr_exp(), label="pop_2") pop_2.record(["spikes", "v", "gsyn_exc"]) sim.Projection(input, pop_2, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) sim.run(simtime) self.check_data(pop_1, len(input_spikes), simtime, [0, 1]) self.check_data(pop_2, len(input_spikes), simtime, [1]) sim.end()
def do_run(self): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") pop_1 = sim.Population(200, sim.IF_curr_exp(), label="pop_1") sim.Projection(input, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=18)) sim.run(500) provenance_files = self.get_provenance_files() sim.end() # assuming placements as expected xmls = { # extract_iobuf_from_binary_types = IF_curr_exp.aplx "0_0_5_pop_1_0_99.xml", "0_0_6_pop_1_100_199.xml", } if xmls < set(provenance_files): # extract_iobuf_from_cores = None self.assertNotIn("iobuf_for_chip_0_0_processor_id_2.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_3.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_4.txt", provenance_files) self.assertIn("iobuf_for_chip_0_0_processor_id_5.txt", provenance_files) self.assertIn("iobuf_for_chip_0_0_processor_id_6.txt", provenance_files) else: raise SkipTest("Unexpected placements {}".format(provenance_files))
def multiple_connectors(self): n_destinations = 5 sim.setup(1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 2) input_pop = sim.Population( SOURCES, sim.SpikeSourceArray(spike_times=[[0], [20], [40], [60], [80]]), label="input_pop") destination = sim.Population(n_destinations, sim.IF_curr_exp(tau_syn_E=1, tau_refrac=0, tau_m=1), label="destination") synapse_type = sim.StaticSynapse(weight=5, delay=1) sim.Projection(input_pop, destination, sim.OneToOneConnector(), synapse_type=synapse_type) sim.Projection(input_pop, destination, sim.AllToAllConnector(), synapse_type=synapse_type) destination.record("v") sim.run(100) neo = destination.get_data(["v"]) v = neo.segments[0].filter(name="v")[0] # pylint: disable=no-member counts = self.calc_spikes_received(v) for i, count in enumerate(counts): for j in range(n_destinations): if i == j: self.assertEqual(count[j], 2) else: self.assertEqual(count[j], 1) sim.end()
def recording_poisson_spikes_big(self): sim.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 2560 # number of neurons in each population sim.set_number_of_neurons_per_core(sim.IF_curr_exp, n_neurons / 2) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } pop_1 = sim.Population(n_neurons, sim.IF_curr_exp, cell_params_lif, label='pop_1') input = sim.Population(n_neurons, sim.SpikeSourcePoisson, {}, label='inputSpikes_1') sim.Projection(input, pop_1, sim.OneToOneConnector()) input.record("spikes") sim.run(5000) self.check_spikes(n_neurons, input, 5) sim.end()
def do_run(): sim.setup(1.0) simulator = get_simulator() simulator.do_load_normal = simulator._do_load simulator._do_load = fancy_do_load # Break up the pre population as that is where delays happen sim.set_number_of_neurons_per_core(sim.SpikeSourceArray, 50) pop1 = sim.Population(100, sim.SpikeSourceArray([1]), label="pop1") pop2 = sim.Population(10, sim.IF_curr_exp(), label="pop2") pop2.record("spikes") # Choose to use delay extensions synapse_type = sim.StaticSynapse(weight=0.5, delay=17) conn = sim.FixedNumberPreConnector(10) projection = sim.Projection( pop1, pop2, conn, synapse_type=synapse_type) delays = projection.get(["delay"], "list") sim.run(30) # There are 100 connections, as there are 10 for each post-neuron assert (len(delays) == 100) # If the delays are done right, all pre-spikes should arrive at the # same time causing each neuron in the post-population to spike spikes = pop2.get_data("spikes").segments[0].spiketrains for s in spikes: assert (len(s) == 1) sim.end()
def onetoone_multicore_population_views(self): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 10) sim.set_number_of_neurons_per_core(sim.SpikeSourceArray, 10) in_pop = sim.Population(14, sim.SpikeSourceArray([0]), label="in_pop") pop = sim.Population(17, sim.IF_curr_exp(), label="pop") conn = sim.Projection(in_pop[6:12], pop[9:16], sim.OneToOneConnector(), sim.StaticSynapse(weight=0.5, delay=2), label="test") sim.run(1) weights = conn.get(['weight', 'delay'], 'list') machine_graph = globals_variables.get_simulator()._machine_graph projection_edges = [ edge for edge in machine_graph.edges if (edge.label == 'machine_edge_for_test') ] sim.end() # Check the connections are correct target = [[6, 9, 0.5, 2.], [7, 10, 0.5, 2.], [8, 11, 0.5, 2.], [9, 12, 0.5, 2.], [10, 13, 0.5, 2.], [11, 14, 0.5, 2.]] self.assertCountEqual(weights, target) # In this instance there should be three MachineEdges: one of the four # possible at the start should have been filtered out self.assertEqual(len(projection_edges), 3)
def do_run(n_neurons, n_cores, new_i_offset): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) p.set_number_of_neurons_per_core(p.Izhikevich, n_neurons / n_cores) cell_params_izk = { 'a': 0.02, 'b': 0.2, 'c': -65, 'd': 8, 'v': -75, 'u': 0, 'tau_syn_E': 2, 'tau_syn_I': 2, 'i_offset': 0 } populations = list() populations.append( p.Population(n_neurons, p.Izhikevich, cell_params_izk, label='pop_1')) populations[0].record("all") p.run(2000) populations[0].set(i_offset=new_i_offset) p.run(2000) neo = populations[0].get_data() p.end() return neo
def do_run(self): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") pop_1 = sim.Population(200, sim.IF_curr_exp(), label="pop_1") sim.Projection(input, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=18)) sim.run(500) provenance_files = self.get_provenance_files() sim.end() # extract_iobuf_from_cores = 0,0,1 self.assertIn("iobuf_for_chip_0_0_processor_id_1.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_2.txt", provenance_files) self.assertIn("iobuf_for_chip_0_0_processor_id_3.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_4.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_5.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_6.txt", provenance_files) self.assertIn("iobuf_for_chip_1_1_processor_id_1.txt", provenance_files)
def test_thrtytwo(self): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) pop_1 = sim.Population(40, sim.IF_curr_exp(), label="pop_1") input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") sim.Projection(input, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) pop_1.record(["spikes", "v"], indexes=range(32)) simtime = 10 sim.run(simtime) neo = pop_1.get_data(variables=["spikes", "v"]) spikes = neo.segments[0].spiketrains # Include all the spiketrains as there is no outside index self.assertEqual(40, len(spikes)) for i in range(32): self.assertEqual(1, len(spikes[i])) for i in range(32, 40): self.assertEqual(0, len(spikes[i])) v = neo.segments[0].filter(name='v')[0] self.assertEqual(32, len(v.channel_index.index)) self.assertEqual(32, len(v[0])) sim.end()
def run_simple_split(): sim.setup(0.1, time_scale_factor=1) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 16) # Note, this next one is ignored on one-to-one Poisson sources sim.set_number_of_neurons_per_core(sim.SpikeSourcePoisson, 10) one_to_one_source = sim.Population(50, sim.SpikeSourcePoisson(rate=10000), additional_parameters={ "seed": 0, "splitter": SplitterPoissonDelegate() }) rand_source = sim.Population(50, sim.SpikeSourcePoisson(rate=10), additional_parameters={ "seed": 1, "splitter": SplitterSliceLegacy() }) rand_source.record("spikes") target = sim.Population( 50, sim.IF_curr_exp(), additional_parameters={ "splitter": SplitterAbstractPopulationVertexNeuronsSynapses(3) }) target.record(["spikes", "packets-per-timestep"]) sim.Projection(one_to_one_source, target, sim.OneToOneConnector(), sim.StaticSynapse(weight=0.01)) sim.Projection(rand_source, target, sim.OneToOneConnector(), sim.StaticSynapse(weight=2.0)) sim.run(1000) source_spikes = [ s.magnitude for s in rand_source.get_data("spikes").segments[0].spiketrains ] target_spikes = [ s.magnitude for s in target.get_data("spikes").segments[0].spiketrains ] target_ppts = (numpy.nonzero( numpy.sum([ s.magnitude for s in target.get_data("packets-per-timestep"). segments[0].filter(name='packets-per-timestep')[0] ], axis=1))[0] - 1) / 10 sim.end() # The only actual spikes received should be from the random source all_source_spikes = numpy.unique( numpy.sort(numpy.concatenate(source_spikes))) assert (numpy.allclose(all_source_spikes, target_ppts)) # A target spike should be caused by a source spike (though not all sources # will cause a target spike) for s, t in zip(source_spikes, target_spikes): assert (len(t) <= len(s))
def do_run(): """ test that tests the printing of v from a pre determined recording :return: """ p.setup(timestep=0.04, min_delay=1.0, max_delay=4.0) n_neurons = 128 * 128 # number of neurons in each population p.set_number_of_neurons_per_core(p.IF_cond_exp, 256) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0, 'e_rev_E': 0., 'e_rev_I': -80. } populations = list() projections = list() weight_to_spike = 0.035 delay = 1.7 current_file_path = os.path.dirname(os.path.abspath(__file__)) spikes_file = os.path.join(current_file_path, 'test.spikes') spikes = read_spikefile(spikes_file, n_neurons) populations.append( p.Population(n_neurons, p.SpikeSourceArray(spike_times=spikes), label='inputSpikes_1')) populations.append( p.Population(n_neurons, p.IF_cond_exp(**cell_params_lif), label='pop_1')) projections.append( p.Projection(populations[0], populations[1], p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=weight_to_spike, delay=delay))) populations[1].record("spikes") p.run(1000) spikes = populations[1].get_data("spikes") p.end() return spikes
def recording_numerious_element(self, run_zero): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 20 # number of neurons in each population p.set_number_of_neurons_per_core(p.IF_curr_exp, n_neurons / 2) random.seed(12480235) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } populations = list() projections = list() boxed_array = numpy.zeros(shape=(0, 2)) spike_array = list() for neuron_id in range(0, n_neurons): spike_array.append(list()) for counter in range(0, 20): random_time = random.randint(0, 4999) boxed_array = numpy.append(boxed_array, [[neuron_id, random_time]], axis=0) spike_array[neuron_id].append(random_time) spike_array_params = {'spike_times': spike_array} populations.append( p.Population(n_neurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(n_neurons, p.SpikeSourceArray, spike_array_params, label='inputSpikes_1')) projections.append( p.Projection(populations[1], populations[0], p.OneToOneConnector())) populations[1].record("spikes") if run_zero: p.run(0) p.run(5000) spike_array_spikes = populations[1].spinnaker_get_data("spikes") boxed_array = boxed_array[numpy.lexsort( (boxed_array[:, 1], boxed_array[:, 0]))] numpy.testing.assert_array_equal(spike_array_spikes, boxed_array) p.end()
def do_run(self): nNeurons = 500 p.setup(timestep=1.0, min_delay=1.0) p.set_number_of_neurons_per_core(p.IF_curr_exp, 100) cm = list() i_off = list() tau_m = list() tau_re = list() tau_syn_e = list() tau_syn_i = list() v_reset = list() v_rest = list() for atom in range(0, nNeurons): cm.append(0.25) i_off.append(0.0 + atom * 0.01) tau_m.append(10.0 + atom // 2 * 0.1) tau_re.append(2.0 + atom % 2 * 0.01) tau_syn_e.append(0.5) tau_syn_i.append(0.5 + atom * 0.01) v_reset.append(-65.0 + atom // 2 * 0.01) v_rest.append(-65.0 + atom % 2 * 0.01) gbar_na_distr = RandomDistribution('normal', (20.0, 2.0), rng=NumpyRNG(seed=85524)) cell_params_lif = { 'cm': 0.25, 'i_offset': i_off, 'tau_m': tau_m, 'tau_refrac': tau_re, 'v_thresh': gbar_na_distr } pop_1 = p.Population(nNeurons, p.IF_curr_exp, cell_params_lif, label='pop_1') pop_1.set(tau_syn_E=0.5) pop_1.set(tau_syn_I=tau_syn_i) pop_1.set(v_reset=v_reset, v_rest=v_rest) p.run(1) self.assertEqual(cm, pop_1.get("cm")) self.assertEqual(i_off, pop_1.get("i_offset")) self.assertEqual(tau_m, pop_1.get("tau_m")) self.assertEqual(tau_re, pop_1.get("tau_refrac")) self.assertEqual(tau_syn_e, pop_1.get("tau_syn_E")) self.assertEqual(tau_syn_i, pop_1.get("tau_syn_I")) self.assertEqual(v_reset, pop_1.get("v_reset")) self.assertEqual(v_rest, pop_1.get("v_rest")) self.assertGreater(len(set(pop_1.get("v_thresh"))), nNeurons / 2) p.end()
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core(p.Izhikevich, 100) cell_params_izk = { 'a': 0.02, 'b': 0.2, 'c': -65, 'd': 8, 'v': -75, 'u': 0, 'tau_syn_E': 2, 'tau_syn_I': 2, 'i_offset': 0 } populations = list() projections = list() weight_to_spike = 40 delay = 1 connections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, delay)] spikeArray = {'spike_times': [[50]]} populations.append( p.Population(nNeurons, p.Izhikevich, cell_params_izk, label='pop_1')) populations.append( p.Population(1, p.SpikeSourceArray, spikeArray, label='inputSpikes_1')) projections.append( p.Projection(populations[0], populations[0], p.FromListConnector(connections))) projections.append( p.Projection(populations[1], populations[0], p.FromListConnector(injectionConnection))) populations[0].record("v") populations[0].record("gsyn_exc") populations[0].record("spikes") p.run(500) neo = populations[0].get_data(["v", "spikes", "gsyn_exc"]) v = neo_convertor.convert_data(neo, name="v") gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") spikes = neo_convertor.convert_spikes(neo) p.end() return (v, gsyn, spikes)
def do_run(): """ test that tests the printing of v from a pre determined recording :return: """ p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 128 * 128 # number of neurons in each population p.set_number_of_neurons_per_core(p.IF_cond_exp, 256) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0, 'e_rev_E': 0., 'e_rev_I': -80. } populations = list() projections = list() weight_to_spike = 0.035 delay = 17 spikes = read_spikefile('test.spikes', n_neurons) spike_array = {'spike_times': spikes} populations.append( p.Population(n_neurons, p.SpikeSourceArray, spike_array, label='inputSpikes_1')) populations.append( p.Population(n_neurons, p.IF_cond_exp, cell_params_lif, label='pop_1')) projections.append( p.Projection(populations[0], populations[1], p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=weight_to_spike, delay=delay))) populations[1].record("spikes") p.run(1000) spikes = populations[1].spinnaker_get_data('spikes') p.end() return spikes
def do_run(nNeurons): p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core(p.IF_curr_exp, 100) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 10.0, 'tau_refrac': 2.0, 'tau_syn_E': 0.5, 'tau_syn_I': 0.5, 'v_reset': -65.0, 'v_rest': -65.0, 'v_thresh': -64.4 } populations = list() projections = list() weight_to_spike = 2 delay = 1 connections = list() for i in range(0, nNeurons): singleConnection = (i, ((i + 1) % nNeurons), weight_to_spike, delay) connections.append(singleConnection) injectionConnection = [(0, 0, weight_to_spike, delay)] spikeArray = {'spike_times': [[0]]} for x in range(6): populations.append( p.Population(nNeurons, p.IF_curr_exp, cell_params_lif)) populations.append(p.Population(1, p.SpikeSourceArray, spikeArray)) for x in range(0, 12, 2): projections.append( p.Projection(populations[x], populations[x], p.FromListConnector(connections))) connector = p.FromListConnector(injectionConnection) projections.append( p.Projection(populations[x + 1], populations[x], connector)) populations[x].record("spikes") p.run(1000) spikes = [] for x in range(0, 12, 2): spikes.append(populations[x].spinnaker_get_data("spikes")) p.end() return spikes
def testReset_add(self): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 1) input = sim.Population( 1, sim.SpikeSourceArray(spike_times=[0]), label="input") pop_1 = sim.Population(2, sim.IF_curr_exp(), label="pop_1") sim.Projection(input, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) sim.run(10) sim.Population(2, sim.IF_curr_exp(), label="pop_2") with self.assertRaises(NotImplementedError): sim.run(10)
def multi_core(self): sim.setup(1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 2) pop = sim.Population(6, sim.IF_curr_exp(i_offset=1, tau_syn_E=1), label="pop") pop.record("v") sim.run(3) pop.set(tau_syn_E=1) sim.run(2) v1 = pop.spinnaker_get_data('v') sim.end() self.check_from_65(v1)
def test_cause_error(self): with self.assertRaises(ConfigurationException): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) pop_1 = sim.Population(1, sim.IF_curr_exp(), label="pop_1") input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") sim.Projection(input, pop_1, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) simtime = 10 sim.run(simtime) pop_1.get_data(variables=["v"])
def do_run(self): sim.setup(timestep=1.0, n_boards_required=1) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 100) machine = globals_variables.get_simulator().machine input1 = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input1") input2 = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input2") pop_1 = sim.Population(5, sim.IF_curr_exp(), label="pop_1") pop_2 = sim.Population(5, sim.IF_curr_exp(), label="pop_2") sim.Projection(input1, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) sim.Projection(input2, pop_2, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) # Make sure there is stuff at the cores specified in the cfg file input1.set_constraint(ChipAndCoreConstraint(0, 0, 1)) input2.set_constraint(ChipAndCoreConstraint(0, 0, 3)) # While there must be a chip 0,0 chip 1,1 could be missing if machine.is_chip_at(1, 1): pop_1.set_constraint(ChipAndCoreConstraint(1, 1, 1)) # Make sure there is stuff at a core not specified in the cfg file pop_2.set_constraint(ChipAndCoreConstraint(0, 0, 2)) sim.run(500) provenance_files = self.get_app_iobuf_files() sim.end() self.assertIn("iobuf_for_chip_0_0_processor_id_1.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_2.txt", provenance_files) self.assertIn("iobuf_for_chip_0_0_processor_id_3.txt", provenance_files) self.assertNotIn("iobuf_for_chip_0_0_processor_id_4.txt", provenance_files) if machine.is_chip_at(1, 1): self.assertIn("iobuf_for_chip_1_1_processor_id_1.txt", provenance_files) self.assertNotIn("iobuf_for_chip_1_1_processor_id_2.txt", provenance_files)
def do_one_to_one_conductance_test(self, neurons_per_core, pre_size, post_size, weight, delay): sim.setup(1.0) sim.set_number_of_neurons_per_core(sim.IF_cond_exp, neurons_per_core) pre = sim.Population(pre_size, sim.IF_cond_exp()) post = sim.Population(post_size, sim.IF_cond_exp()) proj = sim.Projection(pre, post, sim.OneToOneConnector(), sim.StaticSynapse(weight=weight, delay=delay)) sim.run(0) conns = proj.get(["weight", "delay"], "list") sim.end() for pre, post, w, d in conns: assert pre == post assert numpy.allclose(w, weight, rtol=0.0001) assert d == delay
def do_run(split, seed=None): p.setup(1.0) if split: p.set_number_of_neurons_per_core(p.SpikeSourcePoisson, 27) p.set_number_of_neurons_per_core(p.IF_curr_exp, 22) inp = p.Population(100, p.SpikeSourcePoisson(rate=100, seed=seed), label="input") pop = p.Population(100, p.IF_curr_exp, {}, label="pop") p.Projection(inp, pop, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=5)) pop.record("spikes") inp.record("spikes") p.run(100) inp.set(rate=10) # pop.set("cm", 0.25) pop.set(tau_syn_E=1) p.run(100) pop_spikes1 = pop.spinnaker_get_data('spikes') inp_spikes1 = inp.spinnaker_get_data('spikes') p.reset() inp.set(rate=0) pop.set(i_offset=1.0) vs = p.RandomDistribution("uniform", [-65.0, -55.0], rng=NumpyRNG(seed=seed)) pop.initialize(v=vs) p.run(100) pop_spikes2 = pop.spinnaker_get_data('spikes') inp_spikes2 = inp.spinnaker_get_data('spikes') p.end() return (pop_spikes1, inp_spikes1, pop_spikes2, inp_spikes2)
def multi_core(self): sim.setup(1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 2) pop = sim.Population(6, sim.IF_curr_exp(i_offset=1, tau_syn_E=1), label="pop") pop.record("v") sim.run(3) pop.set(tau_syn_E=1) sim.run(2) v1 = pop.spinnaker_get_data('v') try: self.check_from_65(v1) except AssertionError: self.known_issue( "https://github.com/SpiNNakerManchester/sPyNNaker/issues/603") sim.end()
def recording_1_element(self): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) n_neurons = 200 # number of neurons in each population p.set_number_of_neurons_per_core(p.IF_curr_exp, n_neurons / 2) cell_params_lif = { 'cm': 0.25, 'i_offset': 0.0, 'tau_m': 20.0, 'tau_refrac': 2.0, 'tau_syn_E': 5.0, 'tau_syn_I': 5.0, 'v_reset': -70.0, 'v_rest': -65.0, 'v_thresh': -50.0 } populations = list() projections = list() spike_array = {'spike_times': [[0]]} populations.append( p.Population(n_neurons, p.IF_curr_exp, cell_params_lif, label='pop_1')) populations.append( p.Population(1, p.SpikeSourceArray, spike_array, label='inputSpikes_1')) projections.append( p.Projection(populations[1], populations[0], p.AllToAllConnector())) populations[1].record("spikes") p.run(5000) spike_array_spikes = populations[1].spinnaker_get_data("spikes") boxed_array = numpy.zeros(shape=(0, 2)) boxed_array = numpy.append(boxed_array, [[0, 0]], axis=0) numpy.testing.assert_array_equal(spike_array_spikes, boxed_array) p.end()
def test_levels(rates=(500, 1000), weights=(0.005, 0.0005)): counter = 0 receive_pop = [] spike_input = [] p.setup(timestep=1, min_delay=1, max_delay=127) p.set_number_of_neurons_per_core(p.IF_cond_exp, 10) for rate in rates: for weight in weights: pop_size = 10 receive_pop.append(p.Population(pop_size, p.IF_cond_exp( ))) #, label="receive_pop{}-{}".format(rate, weight))) receive_pop[counter].record(['spikes', 'v']) #["spikes"]) # Connect key spike injector to input population spike_input.append( p.Population(pop_size, p.SpikeSourcePoisson(rate=rate)) ) #, label="input_connect{}-{}".format(rate, weight))) p.Projection(spike_input[counter], receive_pop[counter], p.OneToOneConnector(), p.StaticSynapse(weight=weight)) print "reached here 1" runtime = 11000 counter += 1 p.run(runtime) print "reached here 2" for i in range(counter): weight_index = i % len(weights) rate_index = (i - weight_index) / len(weights) print weight_index print rate_index # for j in range(receive_pop_size): spikes = receive_pop[i].get_data('spikes').segments[0].spiketrains v = receive_pop[i].get_data('v').segments[0].filter(name='v')[0] plt.figure("rate = {} - weight = {}".format(rates[rate_index], weights[weight_index])) Figure(Panel(spikes, xlabel="Time (ms)", ylabel="nID", xticks=True), Panel(v, ylabel="Membrane potential (mV)", yticks=True)) plt.show() # End simulation p.end()
def test_radial_some(self): sim.setup(timestep=1.0) sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 50) pop_1 = sim.Population(200, sim.IF_curr_exp(), label="pop_1") pop_1.set_constraint(RadialPlacementFromChipConstraint(1, 1)) input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") sim.Projection(input, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) simtime = 10 sim.run(simtime) placements = self.get_placements("pop_1") sim.end() self.assertEqual(4, len(placements)) for [x, y, _] in placements: self.assertEqual("1", x) self.assertEqual("1", y)
def do_run(nNeurons, _neurons_per_core): spike_list = {'spike_times': [float(x) for x in range(0, 599, 50)]} p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) p.set_number_of_neurons_per_core(p.SpikeSourceArray, _neurons_per_core) pop = p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input') pop.record("spikes") p.run(1000) neo = pop.get_data("spikes") p.end() return neo