Ejemplo n.º 1
0
def test_csa_block_connector():
    MockSimulator.setup()
    try:
        # This creates a block of size (2, 5) with a probability of 0.5; then
        # within the block an individual connection has a probability of 0.3
        connector = CSAConnector(
            csa.block(2, 5) * csa.random(0.5) * csa.random(0.3))
        weight = 1.0
        delay = 2.0
        mock_synapse_info = MockSynapseInfo(MockPopulation(10, "pre"),
                                            MockPopulation(10, "post"), weight,
                                            delay)
        connector.set_projection_information(1000.0, mock_synapse_info)
        pre_vertex_slice = Slice(0, 10)
        post_vertex_slice = Slice(0, 10)
        block = connector.create_synaptic_block([pre_vertex_slice], 0,
                                                [post_vertex_slice], 0,
                                                pre_vertex_slice,
                                                post_vertex_slice, 0,
                                                mock_synapse_info)
        assert (len(block) >= 0)
        assert (all(item["weight"] == 1.0 for item in block))
        assert (all(item["delay"] == 2.0 for item in block))
    except TypeError:
        raise SkipTest("https://github.com/INCF/csa/issues/17")
    except RuntimeError:
        if sys.version_info >= (3, 7):
            raise SkipTest("https://github.com/INCF/csa/issues/16")
        raise
Ejemplo n.º 2
0
def test_csa_block_connector():
    MockSimulator.setup()
    # This creates a block of size (2, 5) with a probability of 0.5; then
    # within the block an individual connection has a probability of 0.3
    connector = CSAConnector(
        csa.block(2, 5) * csa.random(0.5) * csa.random(0.3))
    connector.set_projection_information(
        MockPopulation(10, "pre"), MockPopulation(10, "post"),
        MockRNG(), 1000.0)
    pre_vertex_slice = Slice(0, 10)
    post_vertex_slice = Slice(0, 10)
    block = connector.create_synaptic_block(
        1.0, 2.0, [pre_vertex_slice], 0, [post_vertex_slice], 0,
        pre_vertex_slice, post_vertex_slice, 0)
    assert(len(block) >= 0)
    assert(all(item["weight"] == 1.0 for item in block))
    assert(all(item["delay"] == 2.0 for item in block))
Ejemplo n.º 3
0
def test_csa_block_connector():
    unittest_setup()
    try:
        # This creates a block of size (2, 5) with a probability of 0.5; then
        # within the block an individual connection has a probability of 0.3
        connector = CSAConnector(
            csa.block(2, 5) * csa.random(0.5) * csa.random(0.3))
        weight = 1.0
        delay = 2.0
        mock_synapse_info = SynapseInformation(
            connector=None,
            pre_population=MockPopulation(10, "Pre"),
            post_population=MockPopulation(10, "Post"),
            prepop_is_view=False,
            postpop_is_view=False,
            rng=None,
            synapse_dynamics=None,
            synapse_type=None,
            receptor_type=None,
            is_virtual_machine=False,
            synapse_type_from_dynamics=False,
            weights=weight,
            delays=delay)

        connector.set_projection_information(mock_synapse_info)
        pre_vertex_slice = Slice(0, 10)
        post_vertex_slice = Slice(0, 10)
        block = connector.create_synaptic_block([pre_vertex_slice], 0,
                                                [post_vertex_slice], 0,
                                                pre_vertex_slice,
                                                post_vertex_slice, 0,
                                                mock_synapse_info)
        assert (len(block) >= 0)
        assert (all(item["weight"] == 1.0 for item in block))
        assert (all(item["delay"] == 2.0 for item in block))
    except TypeError as e:
        raise SkipTest("https://github.com/INCF/csa/issues/17") from e
    except RuntimeError as e:
        if sys.version_info >= (3, 7):
            raise SkipTest("https://github.com/INCF/csa/issues/16") from e
        raise e
Ejemplo n.º 4
0
def do_run(plot):

    runtime = 3000
    p.setup(timestep=1.0, min_delay=1.0, max_delay=144.0)
    nNeurons = 200  # number of neurons in each population
    p.set_number_of_neurons_per_core(p.IF_curr_exp, nNeurons / 10)

    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()

    weight_to_spike = 2.0
    delay = 10

    # connection list in a loop for first population
    loopConnections = []
    for i in range(0, nNeurons):
        singleConnection = ((i, (i + 1) % nNeurons))
        loopConnections.append(singleConnection)

    # injection list to set the chain going
    injectionConnection = [(0, 0)]
    spikeArray = {'spike_times': [[0]]}

    # list of populations
    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'))
    populations.append(
        p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif),
                     label='pop_3'))
    populations.append(
        p.Population(nNeurons, p.IF_curr_exp(**cell_params_lif),
                     label='pop_4'))
    populations.append(
        p.Population(1,
                     p.SpikeSourceArray(**spikeArray),
                     label='inputSpikes_1'))

    # Loop connector: we can just pass in the list we made earlier
    CSA_loop_connector = p.CSAConnector(loopConnections)

    # random connector: each connection has a probability of 0.05
    CSA_random_connector = p.CSAConnector(csa.random(0.05))

    # one-to-one connector: do I really need to explain?
    CSA_onetoone_connector = p.CSAConnector(csa.oneToOne)

    # This creates a block of size (5,10) with a probability of 0.05; then
    # within the block an individual connection has a probability of 0.3
    csa_block_random = csa.block(15, 10) * csa.random(0.05) * csa.random(0.3)
    CSA_randomblock_connector = p.CSAConnector(csa_block_random)

    # list of projections using the connectors above
    projections.append(
        p.Projection(populations[0], populations[0], CSA_loop_connector,
                     p.StaticSynapse(weight=weight_to_spike, delay=delay)))
    projections.append(
        p.Projection(populations[0], populations[1], CSA_random_connector,
                     p.StaticSynapse(weight=weight_to_spike, delay=delay)))
    projections.append(
        p.Projection(populations[1], populations[2], CSA_onetoone_connector,
                     p.StaticSynapse(weight=weight_to_spike, delay=delay)))
    projections.append(
        p.Projection(populations[2], populations[3], CSA_randomblock_connector,
                     p.StaticSynapse(weight=weight_to_spike, delay=delay)))
    projections.append(
        p.Projection(populations[4], populations[0],
                     p.FromListConnector(injectionConnection),
                     p.StaticSynapse(weight=weight_to_spike, delay=1)))

    populations[0].record(['v', 'spikes'])
    populations[1].record(['v', 'spikes'])
    populations[2].record(['v', 'spikes'])
    populations[3].record(['v', 'spikes'])

    p.run(runtime)

    # get data (could be done as one, but can be done bit by bit as well)
    v = populations[0].spinnaker_get_data('v')
    v2 = populations[1].spinnaker_get_data('v')
    v3 = populations[2].spinnaker_get_data('v')
    v4 = populations[3].spinnaker_get_data('v')
    spikes = populations[0].spinnaker_get_data('spikes')
    spikes2 = populations[1].spinnaker_get_data('spikes')
    spikes3 = populations[2].spinnaker_get_data('spikes')
    spikes4 = populations[3].spinnaker_get_data('spikes')

    if plot:
        # Use the show functionality of CSA to display connection sets
        CSA_loop_connector.show_connection_set()
        CSA_random_connector.show_connection_set()
        CSA_onetoone_connector.show_connection_set()
        CSA_randomblock_connector.show_connection_set()

        # Now plot some spikes
        pylab.figure()
        pylab.plot([i[1] for i in spikes], [i[0] for i in spikes], "r.")
        pylab.xlabel('Time/ms')
        pylab.ylabel('spikes')
        pylab.title('spikes: population 1')

        pylab.show()

        pylab.figure()
        pylab.plot([i[1] for i in spikes3], [i[0] for i in spikes3], "g.")
        pylab.plot([i[1] for i in spikes4], [i[0] for i in spikes4], "r.")
        pylab.plot([i[1] for i in spikes2], [i[0] for i in spikes2], "b.")
        pylab.xlabel('Time/ms')
        pylab.ylabel('spikes')
        pylab.title('spikes: populations 2, 3, 4')

        pylab.show()

    p.end()

    return v, v2, v3, v4, spikes, spikes2, spikes3, spikes4