コード例 #1
0
def test_set_synaptic_parameters_fully_connected(sim):
    sim.setup()
    mpi_rank = sim.rank()
    p1 = sim.Population(4, sim.IF_cond_exp())
    p2 = sim.Population(2, sim.IF_cond_exp())
    syn = sim.TsodyksMarkramSynapse(U=0.5, weight=0.123, delay=0.1)
    prj = sim.Projection(p1, p2, sim.AllToAllConnector(), syn)

    expected = numpy.array([
        (0.0, 0.0, 0.123, 0.1, 0.5),
        (0.0, 1.0, 0.123, 0.1, 0.5),
        (1.0, 0.0, 0.123, 0.1, 0.5),
        (1.0, 1.0, 0.123, 0.1, 0.5),
        (2.0, 0.0, 0.123, 0.1, 0.5),
        (2.0, 1.0, 0.123, 0.1, 0.5),
        (3.0, 0.0, 0.123, 0.1, 0.5),
        (3.0, 1.0, 0.123, 0.1, 0.5),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_almost_equal(actual[ind], expected, 1e-16)

    positional_weights = numpy.array([[0, 1], [2, 3], [4, 5], [6, 7]],
                                     dtype=float)
    prj.set(weight=positional_weights)
    expected = positional_weights
    actual = prj.get('weight', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
    prj.set(U=u_list)
    expected = numpy.array([[0.9, 0.8], [0.7, 0.6], [0.5, 0.4], [0.3, 0.2]])
    actual = prj.get('U', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    f_delay = lambda d: 0.5 + d
    prj.set(delay=f_delay)
    expected = numpy.array([[0.5, 1.5], [1.5, 0.5], [2.5, 1.5], [3.5, 2.5]])
    actual = prj.get('delay', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    # final sanity check
    expected = numpy.array([
        (0.0, 0.0, 0.0, 0.5, 0.9),
        (0.0, 1.0, 1.0, 1.5, 0.8),
        (1.0, 0.0, 2.0, 1.5, 0.7),
        (1.0, 1.0, 3.0, 0.5, 0.6),
        (2.0, 0.0, 4.0, 2.5, 0.5),
        (2.0, 1.0, 5.0, 1.5, 0.4),
        (3.0, 0.0, 6.0, 3.5, 0.3),
        (3.0, 1.0, 7.0, 2.5, 0.2),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_equal(actual[ind], expected)
コード例 #2
0
def test_set_synaptic_parameters_fully_connected(sim):
    sim.setup()
    mpi_rank = sim.rank()
    p1 = sim.Population(4, sim.IF_cond_exp())
    p2 = sim.Population(2, sim.IF_cond_exp())
    syn = sim.TsodyksMarkramSynapse(U=0.5, weight=0.123, delay=0.1)
    prj = sim.Projection(p1, p2, sim.AllToAllConnector(), syn)

    expected = numpy.array([
        (0.0, 0.0, 0.123, 0.1, 0.5),
        (0.0, 1.0, 0.123, 0.1, 0.5),
        (1.0, 0.0, 0.123, 0.1, 0.5),
        (1.0, 1.0, 0.123, 0.1, 0.5),
        (2.0, 0.0, 0.123, 0.1, 0.5),
        (2.0, 1.0, 0.123, 0.1, 0.5),
        (3.0, 0.0, 0.123, 0.1, 0.5),
        (3.0, 1.0, 0.123, 0.1, 0.5),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_almost_equal(actual[ind], expected, 1e-16)

    positional_weights = numpy.array([[0, 1], [2, 3], [4, 5], [6, 7]], dtype=float)
    prj.set(weight=positional_weights)
    expected = positional_weights
    actual = prj.get('weight', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2]
    prj.set(U=u_list)
    expected = numpy.array([[0.9, 0.8], [0.7, 0.6], [0.5, 0.4], [0.3, 0.2]])
    actual = prj.get('U', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    f_delay = lambda d: 0.5+d
    prj.set(delay=f_delay)
    expected = numpy.array([[0.5, 1.5], [1.5, 0.5], [2.5, 1.5], [3.5, 2.5]])
    actual = prj.get('delay', format='array')
    if mpi_rank == 0:
        assert_arrays_equal(actual, expected)

    # final sanity check
    expected = numpy.array([
        (0.0, 0.0, 0.0, 0.5, 0.9),
        (0.0, 1.0, 1.0, 1.5, 0.8),
        (1.0, 0.0, 2.0, 1.5, 0.7),
        (1.0, 1.0, 3.0, 0.5, 0.6),
        (2.0, 0.0, 4.0, 2.5, 0.5),
        (2.0, 1.0, 5.0, 1.5, 0.4),
        (3.0, 0.0, 6.0, 3.5, 0.3),
        (3.0, 1.0, 7.0, 2.5, 0.2),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_equal(actual[ind], expected)
コード例 #3
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_columnwise_iteration_with_random_array_parallel_safe_with_mask():
    random.mpi_rank=0; random.num_processes=2
    input = random.RandomDistribution(rng=MockRNG(parallel_safe=True))
    copy_input = random.RandomDistribution(rng=MockRNG(parallel_safe=True))
    m = LazyArray(input, shape=(4,3))
    mask = numpy.array([False, False, True])
    cols = [col for col in m.by_column(mask=mask)]
    assert_equal(len(cols), 1)
    assert_arrays_almost_equal(cols[0], copy_input.next(12, mask_local=False)[8:], 1e-15)
コード例 #4
0
ファイル: test_connectors.py プロジェクト: antolikjan/PyNN
def all_to_all_static_no_self(sim):
    sim.setup()
    p = sim.Population(5, sim.IF_cond_exp())
    synapse_type = sim.StaticSynapse(weight=RandomDistribution('gamma', k=2.0, theta=0.5), delay="0.2+0.3*d")
    prj = sim.Projection(p, p, sim.AllToAllConnector(allow_self_connections=False), synapse_type)
    weights = prj.get('weight', format='array', gather=False)
    print(weights)
    delays = prj.get('delay', format='list', gather=False)
    i, j, d = numpy.array(delays).T
    assert_arrays_almost_equal(d, 0.2 + 0.3 * abs(i - j), 1e-9)
    assert_equal(d.size, p.size * (p.size - 1))
    sim.end()
コード例 #5
0
ファイル: test_connectors.py プロジェクト: lbbaker/PyNN
def all_to_all_static_no_self(sim):
    sim.setup()
    p = sim.Population(5, sim.IF_cond_exp())
    synapse_type = sim.StaticSynapse(weight=RandomDistribution('gamma', k=2.0, theta=0.5), delay="0.2+0.3*d")
    prj = sim.Projection(p, p, sim.AllToAllConnector(allow_self_connections=False), synapse_type)
    weights = prj.get('weight', format='array', gather=False)
    print(weights)
    delays = prj.get('delay', format='list', gather=False)
    i, j, d = numpy.array(delays).T
    assert_arrays_almost_equal(d, 0.2 + 0.3 * abs(i - j), 1e-9)
    assert_equal(d.size, p.size * (p.size - 1))
    sim.end()
コード例 #6
0
ファイル: test_core.py プロジェクト: agravier/pynn
def test_columnwise_iteration_with_random_array_parallel_safe_with_mask():
    random.mpi_rank = 0
    random.num_processes = 2
    input = random.RandomDistribution(rng=MockRNG(parallel_safe=True))
    copy_input = random.RandomDistribution(rng=MockRNG(parallel_safe=True))
    m = LazyArray(input, shape=(4, 3))
    mask = numpy.array([False, False, True])
    cols = [col for col in m.by_column(mask=mask)]
    assert_equal(len(cols), 1)
    assert_arrays_almost_equal(cols[0],
                               copy_input.next(12, mask_local=False)[8:],
                               1e-15)
コード例 #7
0
def ticket195(sim):
    """
    Check that the `connect()` function works correctly with single IDs (see
    http://neuralensemble.org/trac/PyNN/ticket/195)
    """
    sim.setup(timestep=0.01)
    pre = sim.Population(10, sim.SpikeSourceArray, cellparams={'spike_times':range(1,10)})
    post = sim.Population(10, sim.IF_cond_exp)
    sim.connect(pre[0], post[0], weight=0.01, delay=0.1, p=1)
    post.record()
    sim.run(100.0)
    assert_arrays_almost_equal(post.getSpikes(), numpy.array([[0.0, 13.4]]), 0.5)
コード例 #8
0
def ticket195(sim):
    """
    Check that the `connect()` function works correctly with single IDs (see
    http://neuralensemble.org/trac/PyNN/ticket/195)
    """
    init_logging(None, debug=True)
    sim.setup(timestep=0.01)
    pre = sim.Population(10, sim.SpikeSourceArray(spike_times=range(1,10)))
    post = sim.Population(10, sim.IF_cond_exp())
    #sim.connect(pre[0], post[0], weight=0.01, delay=0.1, p=1)
    sim.connect(pre[0:1], post[0:1], weight=0.01, delay=0.1, p=1)
    #prj = sim.Projection(pre, post, sim.FromListConnector([(0, 0, 0.01, 0.1)]))
    post.record(['spikes', 'v'])
    sim.run(100.0)
    assert_arrays_almost_equal(post.get_data().segments[0].spiketrains[0], numpy.array([13.4])*pq.ms, 0.5)
コード例 #9
0
ファイル: scenarios.py プロジェクト: animesh/scripts
def test_reset(sim):
    """
    Run the same simulation n times without recreating the network,
    and check the results are the same each time.
    """
    repeats = 3
    sim.setup()
    p = sim.Population(1, sim.IF_cond_exp, {"i_offset": 0.1})
    p.record_v()
    
    data = []
    for i in range(repeats):
        sim.run(10.0)
        data.append(p.get_v())
        sim.reset()
        
    sim.end()

    for rec in data:
        assert_arrays_almost_equal(rec, data[0], 1e-12)
コード例 #10
0
ファイル: test_recording.py プロジェクト: costypetrisor/PyNN
def issue259(sim):
    """
    A test that retrieving data with "clear=True" gives correct spike trains.
    """
    sim.setup(timestep=0.05, spike_precision="off_grid")
    p = sim.Population(1, sim.SpikeSourceArray(spike_times=[0.075, 10.025, 12.34, 1000.025]))
    p.record('spikes')
    sim.run(10.0)
    spiketrains0 = p.get_data('spikes', clear=True).segments[0].spiketrains
    print(spiketrains0[0])
    sim.run(10.0)
    spiketrains1 = p.get_data('spikes', clear=True).segments[0].spiketrains
    print(spiketrains1[0])
    sim.run(10.0)
    spiketrains2 = p.get_data('spikes', clear=True).segments[0].spiketrains
    print(spiketrains2[0])
    sim.end()

    assert_arrays_almost_equal(spiketrains0[0], numpy.array([0.075])*pq.ms, 1e-17)
    assert_arrays_almost_equal(spiketrains1[0], numpy.array([10.025, 12.34])*pq.ms, 1e-14)
    assert_equal(spiketrains2[0].size, 0)
コード例 #11
0
def test_reset(sim):
    """
    Run the same simulation n times without recreating the network,
    and check the results are the same each time.
    """
    repeats = 3
    dt      = 1
    sim.setup(timestep=dt, min_delay=dt)
    p = sim.Population(1, sim.IF_curr_exp(i_offset=0.1))
    p.record('v')

    for i in range(repeats):
        sim.run(10.0)
        sim.reset()
    data = p.get_data(clear=False)
    sim.end()

    assert len(data.segments) == repeats
    for segment in data.segments[1:]:
        assert_arrays_almost_equal(segment.analogsignalarrays[0],
                                   data.segments[0].analogsignalarrays[0], 1e-11)
コード例 #12
0
def test_reset(sim):
    """
    Run the same simulation n times without recreating the network,
    and check the results are the same each time.
    """
    repeats = 3
    dt      = 1
    sim.setup(timestep=dt, min_delay=dt)
    p = sim.Population(1, sim.IF_curr_exp, {"i_offset": 0.1})
    p.record_v()
    
    data = []
    for i in range(repeats):
        sim.run(10.0)
        data.append(p.get_v())
        sim.reset()
        
    sim.end()

    for rec in data:
        assert_arrays_almost_equal(rec, data[0], 1e-11)
コード例 #13
0
def test_reset_with_clear(sim):
    """
    Run the same simulation n times without recreating the network,
    and check the results are the same each time.
    """
    repeats = 3
    dt      = 1
    sim.setup(timestep=dt, min_delay=dt)
    p = sim.Population(1, sim.IF_curr_exp(i_offset=0.1))
    p.record('v')

    data = []
    for i in range(repeats):
        sim.run(10.0)
        data.append(p.get_data(clear=True))
        sim.reset()

    sim.end()

    for rec in data:
        assert len(rec.segments) == 1
        assert_arrays_almost_equal(rec.segments[0].analogsignalarrays[0],
                                   data[0].segments[0].analogsignalarrays[0], 1e-11)
コード例 #14
0
def issue259(sim):
    """
    A test that retrieving data with "clear=True" gives correct spike trains.
    """
    sim.setup(timestep=0.05, spike_precision="off_grid")
    p = sim.Population(
        1, sim.SpikeSourceArray(spike_times=[0.075, 10.025, 12.34, 1000.025]))
    p.record('spikes')
    sim.run(10.0)
    spiketrains0 = p.get_data('spikes', clear=True).segments[0].spiketrains
    print(spiketrains0[0])
    sim.run(10.0)
    spiketrains1 = p.get_data('spikes', clear=True).segments[0].spiketrains
    print(spiketrains1[0])
    sim.run(10.0)
    spiketrains2 = p.get_data('spikes', clear=True).segments[0].spiketrains
    print(spiketrains2[0])
    sim.end()

    assert_arrays_almost_equal(spiketrains0[0],
                               numpy.array([0.075]) * pq.ms, 1e-17)
    assert_arrays_almost_equal(spiketrains1[0],
                               numpy.array([10.025, 12.34]) * pq.ms, 1e-14)
    assert_equal(spiketrains2[0].size, 0)
コード例 #15
0
def test_set_synaptic_parameters_multiply_connected(sim):
    sim.setup()
    mpi_rank = sim.rank()
    p1 = sim.Population(4, sim.IF_cond_exp())
    p2 = sim.Population(2, sim.IF_cond_exp())
    syn = sim.TsodyksMarkramSynapse(U=0.5, weight=0.123, delay=0.1)
    prj = sim.Projection(p1, p2, sim.FromListConnector([(0, 0), (1, 0), (3, 0), (1, 1), (1, 0), (2, 1)]), syn)

    expected = numpy.array([
        (0.0, 0.0, 0.123, 0.1, 0.5),
        (1.0, 0.0, 0.123, 0.1, 0.5),
        (1.0, 0.0, 0.123, 0.1, 0.5),
        (1.0, 1.0, 0.123, 0.1, 0.5),
        (2.0, 1.0, 0.123, 0.1, 0.5),
        (3.0, 0.0, 0.123, 0.1, 0.5),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_almost_equal(actual[ind], expected, 1e-16)

    positional_weights = numpy.array([[0, nan], [2, 3], [nan, 5], [6, nan]], dtype=float)
    prj.set(weight=positional_weights)
    expected = numpy.array([
        (0.0, 0.0, 0.0),
        (1.0, 0.0, 2.0),
        (1.0, 0.0, 2.0),
        (1.0, 1.0, 3.0),
        (2.0, 1.0, 5.0),
        (3.0, 0.0, 6.0),
    ])
    actual = numpy.array(prj.get('weight', format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_almost_equal(actual[ind], expected, 1e-16)

    # postponing implementation of this functionality until after 0.8.0
    # u_list = [0.9, 0.8, 0.7, 0.6, 0.5, 0.4]
    # prj.set(U=u_list)
    # expected = numpy.array([
    #     (0.0, 0.0, 0.9),
    #     (1.0, 0.0, 0.8),
    #     (1.0, 0.0, 0.7),
    #     (1.0, 1.0, 0.6),
    #     (2.0, 1.0, 0.5),
    #     (3.0, 0.0, 0.4),
    # ])
    # actual = numpy.array(prj.get('U', format='list'))
    # if mpi_rank == 0:
    #     ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
    #     assert_arrays_almost_equal(actual[ind], expected, 1e-16)

    f_delay = lambda d: 0.5+d
    prj.set(delay=f_delay)
    expected = numpy.array([
        (0.0, 0.0, 0.5),
        (1.0, 0.0, 1.5),
        (1.0, 0.0, 1.5),
        (1.0, 1.0, 0.5),
        (2.0, 1.0, 1.5),
        (3.0, 0.0, 3.5),
    ])
    actual = numpy.array(prj.get('delay', format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_arrays_almost_equal(actual[ind], expected, 1e-16)

    # final sanity check
    expected = numpy.array([
        (0.0, 0.0, 0.0, 0.5, 0.5),
        (1.0, 0.0, 2.0, 1.5, 0.5),
        (1.0, 0.0, 2.0, 1.5, 0.5),
        (1.0, 1.0, 3.0, 0.5, 0.5),
        (2.0, 1.0, 5.0, 1.5, 0.5),
        (3.0, 0.0, 6.0, 3.5, 0.5),
    ])
    actual = numpy.array(prj.get(['weight', 'delay', 'U'], format='list'))
    if mpi_rank == 0:
        ind = numpy.lexsort((actual[:, 1], actual[:, 0]))
        assert_array_equal(actual[ind], expected)