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(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()
Exemple #3
0
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()
Exemple #4
0
    def __init__(self, dvs_input, sim_t, w_kc2kc=0):

        self.w_kc2kc = w_kc2kc

        self.sim_t = sim_t

        self.pn_neuron_idx = range(0, nb_pn, nb_pn / 5)
        self.kc_neuron_idx = range(0, nb_kc, nb_kc / 10)

        self.spike_source = sim.Population(
            nb_pn, sim.SpikeSourceArray(spike_times=dvs_input), label="DVS")
        self.pns = sim.Population(nb_pn, model(**cell_params), label="PN")
        self.kcs = sim.Population(nb_kc, model(**cell_params), label="KC")
        self.kcs_a = sim.Population(nb_kc, model(**cell_params), label="KC_A")
        self.ens = sim.Population(nb_en, model(**cell_params), label="EN")
        self.ens_a = sim.Population(nb_en, model(**cell_params), label="EN_A")

        self.dvs2pn = sim.Projection(self.spike_source,
                                     self.pns,
                                     sim.OneToOneConnector(),
                                     sim.StaticSynapse(weight=0.3, delay=1.0),
                                     receptor_type='excitatory')
        self.pn2kc = sim.Projection(self.pns,
                                    self.kcs,
                                    sim.FixedTotalNumberConnector(nb_pn2kc *
                                                                  nb_kc),
                                    sim.StaticSynapse(weight=0.3, delay=1.0),
                                    receptor_type='excitatory')
        self.pn2kc_a = sim.Projection(self.pns,
                                      self.kcs_a,
                                      sim.FixedTotalNumberConnector(nb_pn2kc *
                                                                    nb_kc),
                                      sim.StaticSynapse(weight=0.3, delay=1.0),
                                      receptor_type='excitatory')
        self.kc2en = sim.Projection(self.kcs,
                                    self.ens,
                                    sim.AllToAllConnector(),
                                    sim.StaticSynapse(weight=0.15, delay=1.0),
                                    receptor_type='excitatory')
        self.kc_a2en_a = sim.Projection(self.kcs_a,
                                        self.ens_a,
                                        sim.AllToAllConnector(),
                                        sim.StaticSynapse(weight=0.15,
                                                          delay=1.0),
                                        receptor_type='excitatory')
        self.kc_a2kc_a = sim.Projection(self.kcs,
                                        self.kcs_a,
                                        sim.AllToAllConnector(),
                                        sim.StaticSynapse(weight=0.1,
                                                          delay=1.0),
                                        receptor_type='excitatory')

        self.ens.record(['v', 'spikes'])
        self.ens_a.record(['v', 'spikes'])
    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)
Exemple #6
0
    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)
Exemple #7
0
 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()
Exemple #8
0
    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")
Exemple #9
0
    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 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)
Exemple #11
0
    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(self):
        sim.setup(1.0)
        pop = sim.Population(1, sim.IF_curr_exp(i_offset=5.0), label="pop")
        pop.record("spikes")
        pop_2 = sim.Population(1, sim.IF_curr_exp(), label="pop_2")
        proj = sim.Projection(
            pop, pop_2, sim.AllToAllConnector(),
            sim.STDPMechanism(
                timing_dependence=sim.SpikePairRule(),
                weight_dependence=sim.AdditiveWeightDependence(),
                weight=sim.RandomDistribution("uniform", low=0.3, high=0.7)))
        proj_2 = sim.Projection(
            pop, pop_2, sim.OneToOneConnector(),
            sim.STDPMechanism(
                timing_dependence=sim.SpikePairRule(),
                weight_dependence=sim.AdditiveWeightDependence(),
                weight=sim.RandomDistribution("uniform", low=0.3, high=0.7)))
        sim.run(100)
        weights_1_1 = proj.get("weight", "list")
        weights_1_2 = proj_2.get("weight", "list")
        spikes_1 = pop.get_data("spikes").segments[0].spiketrains

        sim.reset()
        sim.run(100)
        weights_2_1 = proj.get("weight", "list")
        weights_2_2 = proj_2.get("weight", "list")
        spikes_2 = pop.get_data("spikes").segments[1].spiketrains
        sim.end()

        assert(numpy.array_equal(weights_1_1, weights_2_1))
        assert(numpy.array_equal(weights_1_2, weights_2_2))
        assert(numpy.array_equal(spikes_1, spikes_2))
Exemple #13
0
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
Exemple #14
0
    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():
    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
    }

    populations = list()
    projections = list()

    populations.append(
        p.Population(sources, p.IF_curr_exp, cell_params_lif, label='pop_1'))

    populations.append(
        p.Population(targets, p.IF_curr_exp, cell_params_lif, label='pop_2'))

    connectors = p.AllToAllConnector()
    synapse_type = p.StaticSynapse(weight=weight_to_spike, delay=delay)
    projections.append(
        p.Projection(populations[0],
                     populations[1],
                     connectors,
                     synapse_type=synapse_type))

    # before
    pre_delays_array = projections[0].get(attribute_names=["delay"],
                                          format="nparray")
    pre_delays_list = projections[0].get(attribute_names=["delay"],
                                         format="list")
    pre_weights_array = projections[0].get(attribute_names=["weight"],
                                           format="array")
    pre_weights_list = projections[0].get(attribute_names=["weight"],
                                          format="list")

    p.run(100)

    # after
    post_delays_array = projections[0].get(attribute_names=["delay"],
                                           format="nparray")
    post_delays_list = projections[0].get(attribute_names=["delay"],
                                          format="list")
    post_weights_array = projections[0].get(attribute_names=["weight"],
                                            format="array")
    post_weights_list = projections[0].get(attribute_names=["weight"],
                                           format="list")

    p.end()

    return (pre_delays_array, pre_delays_list, pre_weights_array,
            pre_weights_list, post_delays_array, post_delays_list,
            post_weights_array, post_weights_list)
    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)
def do_run():
    p.setup(timestep=1.0)
    cellparams = {"spike_times": [0]}
    input_pop = p.Population(1, p.SpikeSourceArray(**cellparams),
                             label="input")
    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}
    pop = p.Population(2, p.IF_curr_exp(**cell_params_lif),
                       label="pop")

    connections = list()
    connections.append(p.Projection(input_pop, pop,
                                    p.AllToAllConnector(),
                                    p.StaticSynapse(weight=[0.3, 1.0],
                                                    delay=[1, 17])))
    connections.append(p.Projection(input_pop, pop,
                                    p.AllToAllConnector(),
                                    p.StaticSynapse(weight=[0.3, 1.0],
                                                    delay=[2, 15])))
    connections.append(p.Projection(input_pop, pop,
                                    p.AllToAllConnector(),
                                    p.StaticSynapse(weight=[0.7, 0.3],
                                                    delay=[3, 33])))

    pre_weights = list()
    pre_delays = list()
    for connection in connections:
        pre_weights.append(connection.get('weight', 'list'))
        pre_delays.append(connection.get('delay', 'list'))

    p.run(100)

    post_weights = list()
    post_delays = list()
    for connection in connections:
        post_weights.append(connection.get('weight', 'list'))
        post_delays.append(connection.get('delay', 'list'))

    p.end()

    return (pre_weights, pre_delays, post_weights, post_delays)
 def check_other_connect(self, sources, destinations):
     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=5, delay=1)
     projection = sim.Projection(
         pop1, pop2, sim.AllToAllConnector(), synapse_type=synapse_type)
     sim.run(1)
     self.check_weights(projection, sources, destinations)
     sim.end()
Exemple #19
0
 def add_pop(self, x, y, n_neurons, input):
     pop = sim.Population(n_neurons,
                          sim.IF_curr_exp(),
                          label="pop_{}_{}".format(x, y))
     pop.add_placement_constraint(x=x, y=y)
     sim.Projection(input,
                    pop,
                    sim.AllToAllConnector(),
                    synapse_type=sim.StaticSynapse(weight=5, delay=1))
     pop.record("all")
     return pop
 def using_population_views(self):
     sim.setup(timestep=1.0)
     input = sim.Population(4, sim.SpikeSourceArray([0]), label="input")
     pop = sim.Population(4, sim.IF_curr_exp(), label="pop")
     conn = sim.Projection(input[1:3], pop[2:4], sim.AllToAllConnector(),
                           sim.StaticSynapse(weight=0.5, delay=2))
     sim.run(1)
     weights = conn.get(['weight', 'delay'], 'list')
     sim.end()
     target = [(1, 2, 0.5, 2.), (1, 3, 0.5, 2.), (2, 2, 0.5, 2.),
               (2, 3, 0.5, 2.)]
     self.assertEqual(weights.tolist(), target)
def run_forever_not_recorded():
    sim.setup(1.0)
    stim = sim.Population(1, sim.SpikeSourcePoisson(rate=10.0))
    pop = sim.Population(255, sim.IF_curr_exp(tau_syn_E=1.0), label="pop")
    sim.Projection(
        stim, pop, sim.AllToAllConnector(), sim.StaticSynapse(weight=20.0))
    conn = DatabaseConnection(
        start_resume_callback_function=start_callback,
        stop_pause_callback_function=stop_callback, local_port=None)
    SpynnakerExternalDevicePluginManager.add_database_socket_address(
        conn.local_ip_address, conn.local_port, None)
    sim.external_devices.run_forever()
    sim.end()
 def get_before_run(self):
     sim.setup(1.0)
     pop1 = sim.Population(3, sim.IF_curr_exp(), label="pop1")
     pop2 = sim.Population(3, sim.IF_curr_exp(), label="pop2")
     synapse_type = sim.StaticSynapse(weight=5, delay=1)
     projection = sim.Projection(
         pop1, pop2, sim.AllToAllConnector(),
         synapse_type=synapse_type)
     weights = projection.get(["weight"], "list")
     sim.run(0)
     length = len(weights)
     self.assertEqual(9, length)
     sim.end()
Exemple #23
0
    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)
Exemple #24
0
def run_network(timestep, steps_per_timestep):
    p.setup(timestep, max_delay=1.0)
    pre = p.Population(1, p.SpikeSourceArray(range(0, 100, 10)))
    post = p.Population(1, p.IF_cond_exp(), additional_parameters={
        "n_steps_per_timestep": steps_per_timestep})
    post.record(["v", "spikes"])
    p.Projection(pre, post, p.AllToAllConnector(),
                 p.StaticSynapse(weight=0.13))
    p.run(100)
    v = post.get_data("v").segments[0].filter(name='v')[0]
    spikes = post.get_data("spikes").segments[0].spiketrains
    p.end()
    return v, spikes
 def using_static_synapse_singles(self):
     sim.setup(timestep=1.0)
     input = sim.Population(2, sim.SpikeSourceArray([0]), label="input")
     pop = sim.Population(2, sim.IF_curr_exp(), label="pop")
     conn = sim.Projection(input, pop, sim.AllToAllConnector(),
                           sim.StaticSynapse(weight=0.7, delay=3))
     sim.run(1)
     weights = conn.get(['weight', 'delay'], 'list')
     sim.end()
     target = [(0, 0, 0.7, 3), (0, 1, 3, 33), (1, 0, 0.4, 12),
               (1, 1, 0.5, 21)]
     for i in range(2):
         for j in range(2):
             self.assertAlmostEqual(weights[i][j], target[i][j], places=3)
Exemple #26
0
    def projection_with_reset(self):
        p.setup(1.0)

        inp = p.Population(1, p.IF_curr_exp(), label="input")
        layer = p.Population(1, p.IF_curr_exp(), label="layer")
        output = p.Population(1, p.IF_curr_exp(), label="output")

        p.Projection(inp, layer, p.AllToAllConnector(),
                     p.StaticSynapse(weight=5, delay=2))

        p.run(100)

        layer_to_output = p.Projection(layer, output, p.AllToAllConnector(),
                                       p.StaticSynapse(weight=4, delay=10))

        p.reset()

        p.run(100)

        weights_delays_out = layer_to_output.get(["weight", "delay"], "list")

        p.end()

        assert weights_delays_out[0][2] == 4.0
Exemple #27
0
def create_edge():
    if projection_type == "all_to_all" and isinstance(
            nodes[edge["output"]["id"]], pynn.Population):
        assert (edge['projection_target']['kind'] == 'static'
                )  # only support static connectivity for now
        target = edge['projection_target']['effect']
        projection = pynn.Projection(nodes[edge["input"]["id"]],
                                     nodes[edge["output"]["id"]],
                                     method=pynn.AllToAllConnector(),
                                     target=target)
        weight = edge["projection_type"]["weight"]
        if edge['projection_target']['effect'] == 'inhibitory' and weight > 0:
            weight = weight * -1
        projection.setWeights(weight)
    else:
        print "not yet supported"
Exemple #28
0
def structural_eliminate_to_empty():
    p.setup(1.0)
    stim = p.Population(9, p.SpikeSourceArray(range(10)), label="stim")

    # These populations should experience elimination
    pop = p.Population(9, p.IF_curr_exp(), label="pop")

    # Make a full list

    # Elimination with random selection (0 probability formation)
    proj = p.Projection(
        stim, pop, p.AllToAllConnector(),
        p.StructuralMechanismStatic(
            partner_selection=p.RandomSelection(),
            formation=p.DistanceDependentFormation([3, 3], 0.0),
            elimination=p.RandomByWeightElimination(4.0, 1.0, 1.0),
            f_rew=1000,
            initial_weight=4.0,
            initial_delay=3.0,
            s_max=9,
            seed=0,
            weight=0.0,
            delay=1.0))

    pop.record("rewiring")

    p.run(1000)

    # Get the final connections
    conns = list(proj.get(["weight", "delay"], "list"))

    rewiring = pop.get_data("rewiring")
    formation_events = rewiring.segments[0].events[0]
    elimination_events = rewiring.segments[0].events[1]

    num_forms = len(formation_events.times)
    num_elims = len(elimination_events.times)

    first_elim = elimination_events.labels[0]

    p.end()

    # These should have no connections since all should be eliminated
    assert (len(conns) == 0)
    assert (num_elims == 81)
    assert (num_forms == 0)
    assert (first_elim == "7_5_elimination")
 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, MyFullNeuron(), label="my_full_neuron")
     test_pop.record(['spikes', 'v'])
     sim.Projection(input_pop,
                    test_pop,
                    sim.AllToAllConnector(),
                    receptor_type='excitatory',
                    synapse_type=sim.StaticSynapse(weight=2.0))
     sim.run(run_time)
     neo = test_pop.get_data('all')
     sim.end()
     self.check_results(neo, [501])
Exemple #30
0
    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()