def do_run(): p.setup(0.1) runtime = 50 populations = [] pop_src1 = p.Population(1, p.SpikeSourceArray, {'spike_times': [[5, 15, 20, 30]]}, label="src1") populations.append(p.Population(1, p.IF_curr_alpha, {}, label="test")) populations[0].set(tau_syn_E=2) populations[0].set(tau_syn_I=4) # define the projections p.Projection(pop_src1, populations[0], p.OneToOneConnector(), p.StaticSynapse(weight=1, delay=1), receptor_type="excitatory") p.Projection(pop_src1, populations[0], p.OneToOneConnector(), p.StaticSynapse(weight=1, delay=10), receptor_type="inhibitory") populations[0].record("all") p.run(runtime) p.end()
def run_script(): n_neurons = 500 simtime = SIMTIME sim.setup(timestep=1) pop_1 = sim.Population(n_neurons, sim.IF_curr_exp(), label="pop_1") input1 = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") sim.Projection(input1, pop_1, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) input2 = sim.Population(n_neurons, sim.SpikeSourcePoisson( rate=100.0, seed=1), label="Stim_Exc") sim.Projection(input2, pop_1, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) pop_1.record(['spikes', 'v', 'gsyn_exc', 'gsyn_inh']) sim.run(simtime) neo = pop_1.get_data() spikes = neo.segments[0].spiketrains v = neo.segments[0].filter(name='v')[0] exc = neo.segments[0].filter(name='gsyn_exc')[0] inh = neo.segments[0].filter(name='gsyn_inh')[0] sim.end() return spikes, v, exc, inh
def fixedtotal_population_views(self): sim.setup(timestep=1.0) in_pop = sim.Population(4, sim.SpikeSourceArray([0]), label="in_pop") pop = sim.Population(4, sim.IF_curr_exp(), label="pop") rng = NumpyRNG(seed=1) n_conns = 5 conn = sim.Projection( in_pop[0:3], pop[1:4], sim.FixedTotalNumberConnector(n_conns, with_replacement=False, rng=rng), sim.StaticSynapse(weight=0.5, delay=2)) conn2 = sim.Projection( in_pop[0:3], pop[1:4], sim.FixedTotalNumberConnector(n_conns, with_replacement=True, rng=rng), sim.StaticSynapse(weight=0.5, delay=2)) sim.run(1) weights = conn.get(['weight', 'delay'], 'list') weights2 = conn2.get(['weight', 'delay'], 'list') sim.end() # The fixed seed means this gives the same answer each time target = [[0, 2, 0.5, 2.0], [0, 3, 0.5, 2.0], [1, 1, 0.5, 2.0], [1, 3, 0.5, 2.0], [2, 1, 0.5, 2.0]] target2 = [[0, 2, 0.5, 2.0], [0, 2, 0.5, 2.0], [1, 1, 0.5, 2.0], [2, 2, 0.5, 2.0], [2, 3, 0.5, 2.0]] self.assertCountEqual(weights, target) self.assertEqual(len(weights), n_conns) self.assertCountEqual(weights2, target2) self.assertEqual(len(weights2), n_conns)
def do_run(): sim.setup(timestep=1) pop_1 = sim.Population(1, sim.IF_curr_exp, {}, label="pop_1") inp = sim.Population( 1, sim.SpikeSourceArray, {'spike_times': [[0]]}, label="input") sim.Projection( pop_1, pop_1, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory", source=None, space=None) pop_1.record("spikes") sim.run(20) first_spikes = pop_1.spinnaker_get_data("spikes") sim.Projection( inp, pop_1, sim.FromListConnector([[0, 0, 5, 5]]), synapse_type=sim.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory", source=None, space=None) sim.reset() sim.run(20) second_spikes = pop_1.spinnaker_get_data("spikes") return first_spikes, second_spikes
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 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_one_run(): n_source = 2000 n_target = 16 n_neurons = 1 n_boards = math.ceil((n_source + n_target) / 16 / 48) sim.setup(timestep=1.0, n_boards_required=n_boards) try: machine = sim.get_machine() except ConfigurationException as oops: if "Failure to detect machine " in str(oops): raise SkipTest( "You Need at least {} boards to run this test".format( n_boards)) from oops raise oops target_x, target_y = find_good_chip(machine, n_target) print(machine) print(target_x, target_y) sources = [] for s in range(n_source): sources.append( sim.Population(n_neurons, sim.IF_curr_exp(), label="source_{}".format(s), additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() })) targets = [] for t in range(n_target): pop = sim.Population(n_neurons, sim.IF_curr_exp(), label="target_{}".format(t), additional_parameters={ "splitter": SplitterAbstractPopulationVertexSlice() }) pop.add_placement_constraint(x=target_x, y=target_y) targets.append(pop) for s in range(n_source): for t in range(n_target): sim.Projection(sources[s], targets[t], sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1), receptor_type="excitatory") if t > 1 and s % t == 0: sim.Projection(sources[s], targets[t], sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1), receptor_type="inhibitory") sim.run(1) sim.end()
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_run(): p.setup(timestep=1.0, min_delay=1.0, max_delay=10.0, db_name='if_cond.sqlite') cell_params = { 'i_offset': .1, 'tau_refrac': 3.0, 'v_rest': -65.0, 'v_thresh': -51.0, 'tau_syn_E': 2.0, 'tau_syn_I': 5.0, 'v_reset': -70.0 } ifcell = p.Population(1, p.IF_curr_exp, cell_params, label='IF_curr_exp') spike_sourceE = p.Population( 1, p.SpikeSourceArray, {'spike_times': [ [i for i in range(5, 105, 10)], ]}, label='spike_sourceE') p.Projection(spike_sourceE, ifcell, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=1, delay=2), receptor_type="excitatory") breakMe = True if breakMe: p.Projection(spike_sourceE, ifcell, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=1, delay=2), receptor_type="excitatory") ifcell.record("v") ifcell.record("gsyn_exc") p.run(200.0) neo = ifcell.get_data(["v", "gsyn_exc"]) recorded_v = neo_convertor.convert_data(neo, name="v") recorded_gsyn = neo_convertor.convert_data(neo, name="gsyn_exc") p.end() return (recorded_v, recorded_gsyn)
def record_v(self): sim.setup(timestep=1) simtime = 100 input = sim.Population(1, sim.SpikeSourceArray(spike_times=[0, 30]), label="input") pop = sim.Population(32, sim.IF_curr_exp(), label="pop") sim.Projection(input, pop, sim.AllToAllConnector(), synapse_type=sim.StaticSynapse(weight=5, delay=1)) pop.record("v") sim.run(simtime) neo = pop.get_data("all") pop.write_data(pickle_path, "all") io = PickleIO(filename=pickle_path) saved = io.read()[0] neo_compare.compare_blocks(neo, saved) assert len(neo.segments[0].spiketrains) == 0 assert len(neo.segments[0].filter(name="v")) > 0 assert len(neo.segments[0].filter(name="gsyn_exc")) == 0 v_neo = pop.get_data("v") pop.write_data(pickle_path, "v") io = PickleIO(filename=pickle_path) v_saved = io.read()[0] neo_compare.compare_blocks(v_neo, v_saved) neo_compare.compare_blocks(v_neo, neo) with self.assertRaises(ConfigurationException): pop.get_data("spikes") with self.assertRaises(ConfigurationException): pop.get_data("gsyn_exc") with self.assertRaises(ConfigurationException): pop.write_data(pickle_path, "spikes") with self.assertRaises(ConfigurationException): pop.write_data(pickle_path, "gsyn_exc")
def do_run(self, psh, psw, ksh, ksw, pre_start=[0, 0], post_start=[0, 0], pre_step=[1, 1], post_step=[1, 1]): sim.setup(timestep=1.0) # determine population size and runtime from the kernel sizes n_pop = psw * psh runtime = (n_pop * 5) + 1000 spiking = [[n * 5, (n_pop * 5) - 1 - (n * 5)] for n in range(n_pop)] input_pop = sim.Population(n_pop, sim.SpikeSourceArray(spiking), label="input") pop = sim.Population(n_pop // 4, sim.IF_curr_exp(), label="pop") weights = 5.0 delays = 17.0 shape_pre = [psh, psw] shape_post = [psh // 2, psw // 2] shape_kernel = [ksh, ksw] weight_list = [[ 7.0 if ((a + b) % 2 == 0) else 5.0 for a in range(ksw) ] for b in range(ksh)] delay_list = [[ 20.0 if ((a + b) % 2 == 1) else 10.0 for a in range(ksw) ] for b in range(ksh)] weight_kernel = np.asarray(weight_list) delay_kernel = np.asarray(delay_list) kernel_connector = sim.KernelConnector(shape_pre, shape_post, shape_kernel, weight_kernel=weight_kernel, delay_kernel=delay_kernel, pre_sample_steps=pre_step, post_sample_steps=post_step, pre_start_coords=pre_start, post_start_coords=post_start) c2 = sim.Projection(input_pop, pop, kernel_connector, sim.StaticSynapse(weight=weights, delay=delays)) pop.record(['v', 'spikes']) sim.run(runtime) weightsdelays = sorted(c2.get(['weight', 'delay'], 'list'), key=lambda x: x[1]) sim.end() return weightsdelays
def do_run(self): sim.setup(timestep=1.0) runtime = 500 n_neurons = 10 spike_times = list(n for n in range(0, runtime, 100)) pop_src = sim.Population(n_neurons, sim.SpikeSourceArray(spike_times), label="src") pop_lif = sim.Population(n_neurons, sim.IF_curr_exp(), label="lif") weight = 5 delay = 5 sim.Projection(pop_src, pop_lif, sim.OneToOneConnector(), sim.StaticSynapse(weight=weight, delay=delay), receptor_type="excitatory") pop_lif.record("packets-per-timestep") sim.run(runtime) pps = pop_lif.get_data('packets-per-timestep') pps_array = pps.segments[0].filter(name='packets-per-timestep')[0] # Packets at the destination arrive one timestep after src spike_times for n in range(runtime): if (n - 1) in spike_times: assert (pps_array[n] == n_neurons) else: assert (pps_array[n] == 0) sim.end()
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 add_correlation_population(sim, populations, projections): print("Adding a input/output correlation population...") #Define neuron model for population (long intergration time) propably the same as the others corr_neuron_model_params = populations[1].celltype.default_parameters input_size = populations[0].size # Make a population that correlates input and output corr_pop = sim.Population(input_size, cellclass=sim.IF_cond_exp(), label='corr_pop') # Add it to populations populations.append(corr_pop) #Weight for just one spike low_weight = 0.01 weight = 0.1 #Proj from input (remember delay) #Add to projections projections.append( sim.Projection(populations[0], corr_pop, sim.OneToOneConnector(), sim.StaticSynapse(weight=low_weight, delay=len(populations) - 1), receptor_type='excitatory')) #Proj from output classes #Add to projections from_list = [(7, x, weight, 0) for x in range(input_size)] projections.append( sim.Projection(populations[-2], corr_pop, sim.FromListConnector(from_list), receptor_type='excitatory')) return populations, projections
def test_props(self): p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0) cell_params_lif = {'cm': 0.25, # nF '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} source = p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_1') dest = p.Population(1, p.IF_curr_exp, cell_params_lif, label='pop_2') connector = p.AllToAllConnector() synapse_type = p.StaticSynapse(weight=0, delay=1) test_label = "BLAH!" proj = p.Projection( presynaptic_population=source, postsynaptic_population=dest, connector=connector, synapse_type=synapse_type, label="BLAH!") proj_label = proj.label proj_source = proj.pre proj_dest = proj.post self.assertEqual(source, proj_source) self.assertEqual(dest, proj_dest) self.assertEqual(test_label, proj_label)
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 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 do_run(nNeurons): spike_list = {'spike_times': [11, 22]} print(spike_list) p.setup(timestep=1.0, min_delay=1.0, max_delay=32.0) inpop = p.Population(nNeurons, p.SpikeSourceArray, spike_list, label='input') pop = p.Population(nNeurons, p.IF_curr_exp(), label='rec') p.Projection(inpop, pop, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=5, delay=3), receptor_type="excitatory") pop.record("spikes") p.run(200) neo = pop.get_data("spikes") p.end() return neo
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 check_connector(self, connector, connections, repeats, conn_type="post", n_destinations=DESTINATIONS): sim.setup(1.0) # sim.set_number_of_neurons_per_core(sim.IF_curr_exp, 2) in_pop = sim.Population( SOURCES, sim.SpikeSourceArray(spike_times=[[0], [20], [40], [60], [80]]), label="in_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) projection = sim.Projection(in_pop, destination, connector, synapse_type=synapse_type) destination.record("v") sim.run(100) self.check_connection(projection, destination, connections, repeats, conn_type, n_destinations) sim.end()
def test_big(self): sources = 3000 destinations = 3000 aslist = [] spiketimes = [] for s in range(sources): for d in range(destinations): aslist.append((s, d, 5 + random.random(), random.randint(1, 5))) spiketimes.append([s * 20]) sim.setup(1.0) pop1 = sim.Population(sources, sim.SpikeSourceArray(spike_times=spiketimes), label="input") pop2 = sim.Population(destinations, sim.IF_curr_exp(), label="pop2") synapse_type = sim.StaticSynapse(weight=5, delay=2) projection = sim.Projection(pop1, pop2, sim.FromListConnector(aslist), synapse_type=synapse_type) pop2.record("spikes") sim.run(sources * 20) from_pro = projection.get(["weight", "delay"], "list") self.assertEqual(sources * destinations, len(from_pro)) spikes = pop2.spinnaker_get_data("spikes") self.assertEqual(sources * destinations, len(spikes)) sim.end()
def do_run(): p.setup(timestep=1, min_delay=1, max_delay=15) spiker = p.Population(1, p.SpikeSourceArray(spike_times=[[0]]), label='inputSSA_1') if_pop = p.Population(2, p.IF_cond_exp(), label='pop_1') if_pop.record("spikes") if_pop.record("v") p.Projection(spiker, if_pop, p.OneToOneConnector(), synapse_type=p.StaticSynapse(weight=5.0, delay=1), receptor_type="excitatory", source=None, space=None) p.run(30) all1 = if_pop.get_data(["spikes", "v"]) p.reset() p.run(30) all2 = if_pop.get_data(["spikes", "v"]) p.end() return (all1, all2)
def do_run(self): sim.setup(timestep=1.0) input_pop = sim.Population( 1, sim.SpikeSourceArray(range(0, run_time, 100)), label="input") test_pop = sim.Population( 1, MyModelCurrExp(my_neuron_parameter=-70.0, i_offset=0.0), label="my_model_pop") test_pop.record(['spikes', 'v']) stdp = sim.STDPMechanism( timing_dependence=MyTimingDependence( my_potentiation_parameter=2.0, my_depression_parameter=0.1), weight_dependence=MyWeightDependence( w_min=0.0, w_max=10.0, my_weight_parameter=0.5)) sim.Projection( input_pop, test_pop, sim.OneToOneConnector(), receptor_type='excitatory', synapse_type=sim.StaticSynapse(weight=2.0)) stdp_connection = sim.Projection( input_pop, test_pop, sim.OneToOneConnector(), synapse_type=stdp) sim.run(run_time) weights = stdp_connection.get('weight', 'list') neo = test_pop.get_data('all') sim.end() for _, _, weight in weights: self.assertEqual(weight, 0.5) self.check_results(neo, [201, 402, 603, 804])
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 check_other_connect(self, aslist, header=None, w_index=2, d_index=3, sources=6, destinations=8): _, name = tempfile.mkstemp(".temp") if header: numpy.savetxt(name, aslist, header=header) else: numpy.savetxt(name, aslist) sim.setup(1.0) pop1 = sim.Population(sources, sim.IF_curr_exp(), label="pop1") pop2 = sim.Population(destinations, sim.IF_curr_exp(), label="pop2") synapse_type = sim.StaticSynapse(weight=WEIGHT, delay=DELAY) projection = sim.Projection(pop1, pop2, sim.FromFileConnector(name), synapse_type=synapse_type) sim.run(0) self.check_weights(projection, aslist, w_index, d_index, sources, destinations) sim.end() try: os.unlink(name) except OSError: pass
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 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 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 reset_set_with_v_set(self): sim.setup(1.0) pop = sim.Population(1, sim.IF_curr_exp, {}, label="pop") inp = sim.Population(1, sim.SpikeSourceArray(spike_times=[0]), label="input") sim.Projection(inp, pop, sim.OneToOneConnector(), synapse_type=sim.StaticSynapse(weight=5)) pop.set(i_offset=1.0) pop.set(tau_syn_E=1) pop.initialize(v=-60) pop.record(["v"]) sim.run(5) v1 = pop.spinnaker_get_data('v') try: self.check_from_60(v1) raise AssertionError("Unexpected after 60 voltage") except AssertionError: pass # That should have failed pop.set(tau_syn_E=1) sim.reset() inp.set(spike_times=[100]) sim.run(5) v2 = pop.spinnaker_get_data('v') try: self.check_from_65(v2) except AssertionError: self.known_issue( "https://github.com/SpiNNakerManchester/sPyNNaker/issues/599") sim.end()
def do_run(self): sim.setup(timestep=1.0) model = sim.IF_curr_exp cell_params_input = { 'cm': 0.25, 'i_offset': 1.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 } cell_params_output = { '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 } pre_size = 2 post_size = 3 simtime = 200 pre_pop = sim.Population(pre_size, model(**cell_params_input)) post_pop = sim.Population(post_size, model(**cell_params_output)) wiring = sim.AllToAllConnector() static_synapse = sim.StaticSynapse(weight=2.5, delay=100.0) sim.Projection(pre_pop, post_pop, wiring, receptor_type='excitatory', synapse_type=static_synapse) # record post-pop spikes to check activation post_pop.record(['spikes']) # run simulation sim.run(simtime) # get data neo_post_spikes = post_pop.get_data(['spikes']) # end simulation sim.end() # Check there are spikes length = len(neo_post_spikes.segments[0].spiketrains[0]) self.assertGreater(length, 0)