Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 0 additions & 57 deletions testsuite/mpitests/test_fixed_indegree.sli

This file was deleted.

37 changes: 37 additions & 0 deletions testsuite/pytests/sli2py_mpi/mpi_test_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,3 +355,40 @@ class MPITestAssertCompletes(MPITestWrapper):

def assert_correct_results(self, tmpdirpath):
pass


class MPITestAssertEqualSums(MPITestWrapper):
"""
Assert that data summed across VPs is equal independent of number of MPI ranks.

Applies to other data only.
"""

def assert_correct_results(self, tmpdirpath):
self.collect_results(tmpdirpath)

all_res = []
if self._spike:
raise NotImplementedError("MPITestAssertEqualSum does not support SPIKE data.")

if self._multi:
raise NotImplementedError("MPITestAssertEqualSum does not support MULTI data.")

assert self._other, "No data collected"

# For each number of procs, combine across ranks or VPs (depends on what test has written) and
# sort by all columns so that if results for different proc numbers are equal up to a permutation
# of rows, the sorted frames will compare equal

# next(iter(...)) returns the first value in the _other dictionary
# [0] then picks the first DataFrame from that list
# columns need to be converted to list() to be passed to sort_values()
all_res.append([pd.concat(others, ignore_index=True).sum(axis=0) for others in self._other.values()])

assert all_res, "No test data collected"

for res in all_res:
assert len(res) == len(self._procs_lst), "Could not collect data for all procs"

for r in res[1:]:
pd.testing.assert_series_equal(res[0], r)
42 changes: 42 additions & 0 deletions testsuite/pytests/sli2py_mpi/test_fixed_indegree.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
#
# test_fixed_indegree.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# NEST is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.


import pytest
from mpi_test_wrapper import MPITestAssertEqualSums


@pytest.mark.skipif_incompatible_mpi
@MPITestAssertEqualSums([1, 2, 4])
def test_fixed_indegree():
"""
Confirm that correct number of connections is created independent of number of local nodes.
"""

import nest

nrns = nest.Create("parrot_neuron", n=5)
nest.Connect(nrns, nrns, {"rule": "fixed_indegree", "indegree": 2})

# Write data to minimal CSV file
with open(OTHER_LABEL.format(nest.num_processes, nest.Rank()), "w") as of: # noqa: F821
of.write("n_conn\n")
of.write(f"{nest.num_connections}\n")
Loading