Skip to content

Commit 5de77b8

Browse files
committed
Port test for spatial connections to recorders.
1 parent f856ce4 commit 5de77b8

File tree

3 files changed

+82
-79
lines changed

3 files changed

+82
-79
lines changed

testsuite/mpitests/topo_mpi_test_free_layer_to_sd_target_driven.sli

Lines changed: 0 additions & 77 deletions
This file was deleted.

testsuite/pytests/sli2py_mpi/test_spatial_connections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
- Free and grid layers
3131
- Different spatial connection rules
3232
33-
Connections to recorders are handled in a separate test, as they do not work
34-
with fixed_indegree and there is no elegant way of filtering that case out.
33+
Connections to recorders are handled in a separate test, as they only work with
34+
the pairwise-bernoulli-on-source connection rule.
3535
"""
3636

3737

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# test_spatial_connections.py
4+
#
5+
# This file is part of NEST.
6+
#
7+
# Copyright (C) 2004 The NEST Initiative
8+
#
9+
# NEST is free software: you can redistribute it and/or modify
10+
# it under the terms of the GNU General Public License as published by
11+
# the Free Software Foundation, either version 2 of the License, or
12+
# (at your option) any later version.
13+
#
14+
# NEST is distributed in the hope that it will be useful,
15+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
# GNU General Public License for more details.
18+
#
19+
# You should have received a copy of the GNU General Public License
20+
# along with NEST. If not, see <http://www.gnu.org/licenses/>.
21+
22+
import pytest
23+
from mpi_test_wrapper import MPITestAssertEqual
24+
25+
"""
26+
Confirm that spatial connections to a generator are created consistently for fixed VP.
27+
28+
This test is parameterized over free and grid layers. Only pairwise-bernoulli-on-source
29+
is suitable as probabilistic connection rule when connecting to a device.
30+
"""
31+
32+
33+
# We cannot use nest or numpy outside the test function itself, so we need to create
34+
# the free positions with basic Python commands.
35+
@pytest.mark.skipif_incompatible_mpi
36+
@pytest.mark.skipif_missing_threads
37+
@pytest.mark.parametrize(
38+
"geometry",
39+
[
40+
("free", {"pos": [(x, y) for x in range(-2, 3) for y in range(-2, 3)], "extent": [6, 6], "edge_wrap": True}),
41+
("grid", {"shape": [5, 5], "extent": [6, 6], "edge_wrap": True}),
42+
],
43+
)
44+
@MPITestAssertEqual([1, 2, 4], debug=False)
45+
def test_spatial_connections(geometry):
46+
"""
47+
Confirm that spatial connections are created consistently for fixed VP.
48+
49+
The test is performed on connection data written to OTHER_LABEL.
50+
"""
51+
52+
import nest
53+
import numpy as np
54+
import pandas as pd
55+
56+
nest.ResetKernel()
57+
nest.total_num_virtual_procs = 4
58+
59+
kind, specs = geometry
60+
if kind == "free":
61+
pos = nest.spatial.free(**specs)
62+
else:
63+
assert kind == "grid"
64+
pos = nest.spatial.grid(**specs)
65+
source_layer = nest.Create("parrot_neuron", positions=pos)
66+
target_layer = nest.Create("spike_recorder", positions=pos)
67+
68+
nest.Connect(
69+
source_layer,
70+
target_layer,
71+
{"rule": "pairwise_bernoulli", "p": 0.5, "use_on_source": True, "mask": {"circular": {"radius": 2.5}}},
72+
{
73+
"weight": nest.spatial_distributions.gaussian(10 * nest.spatial.distance, std=2),
74+
"delay": 0.1 + 0.2 * nest.spatial.distance,
75+
},
76+
)
77+
78+
conns = nest.GetConnections()
79+
df = pd.DataFrame.from_dict(conns.get(["source", "target", "weight", "delay"]))
80+
df.to_csv(OTHER_LABEL.format(nest.num_processes, nest.Rank()), index=False, sep="\t") # noqa: F821

0 commit comments

Comments
 (0)