Skip to content

Commit 68a1038

Browse files
authored
Merge pull request #3434 from heplesser/easier_other
Simplify handling of OTHER labels in new-style mpitests
2 parents 64bf40e + d34daef commit 68a1038

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

testsuite/pytests/sli2py_mpi/mpi_test_wrapper.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
be fixed while the number of MPI processes is varied, but this is not required.
2929
3030
- The process is managed by subclasses of the `MPITestWrapper` base class
31-
- Each test file must contain exactly one test function
31+
- Each test file must contain **exactly one** test function
3232
- The test function must be decorated with a subclass of `MPITestWrapper`
3333
- The wrapper will write a modified version of the test file as `runner.py`
3434
to a temporary directory and mpirun it from there; results are collected
@@ -99,9 +99,14 @@ class MPITestWrapper:
9999
"""
100100

101101
RUNNER = "runner.py"
102+
103+
# Formats for output file names to be written by NEST and by the evaluation function.
104+
# The first placeholder will be filled with the number of processes used.
105+
# SPIKE and MULTI labels are passed to spike recorder/multimeter, which add "-{Rank}.dat" automatically.
106+
# For OTHER, the test function needs to provide the Rank explicitly.
102107
SPIKE_LABEL = "spike-{}"
103108
MULTI_LABEL = "multi-{}"
104-
OTHER_LABEL = "other-{}"
109+
OTHER_LABEL = "other-{}-{}.dat"
105110

106111
RUNNER_TEMPLATE = textwrap.dedent(
107112
"""\
@@ -195,13 +200,18 @@ def wrapper(*args, **kwargs):
195200
return wrapper
196201

197202
def _collect_result_by_label(self, tmpdirpath, label):
203+
# Build complete patterns here including the rank part and ending
204+
if not label.endswith("-{}-{}.dat"):
205+
assert label.endswith("-{}")
206+
label += "-{}.dat"
207+
198208
try:
199-
next(tmpdirpath.glob(f"{label.format('*')}.dat"))
209+
next(tmpdirpath.glob(label.format("*", "*")))
200210
except StopIteration:
201211
return None # no data for this label
202212

203213
return {
204-
n_procs: [pd.read_csv(f, sep="\t", comment="#") for f in tmpdirpath.glob(f"{label.format(n_procs)}-*.dat")]
214+
n_procs: [pd.read_csv(f, sep="\t", comment="#") for f in tmpdirpath.glob(label.format(n_procs, "*"))]
205215
for n_procs in self._procs_lst
206216
}
207217

testsuite/pytests/sli2py_mpi/test_all_to_all.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from mpi_test_wrapper import MPITestAssertEqual
2626

2727

28-
# Parametrization over the number of nodes here only so show hat it works
28+
# Parametrization over the number of nodes here only to show hat it works
2929
@pytest.mark.parametrize("N", [4, 7])
3030
@MPITestAssertEqual([1, 4], debug=False)
3131
def test_all_to_all(N):
@@ -42,4 +42,4 @@ def test_all_to_all(N):
4242
nest.Connect(nrns, nrns, "all_to_all")
4343

4444
conns = nest.GetConnections().get(output="pandas").drop(labels=["target_thread", "port"], axis=1)
45-
conns.to_csv(OTHER_LABEL.format(nest.num_processes) + f"-{nest.Rank()}.dat", index=False) # noqa: F821
45+
conns.to_csv(OTHER_LABEL.format(nest.num_processes, nest.Rank()), index=False) # noqa: F821

testsuite/pytests/sli2py_mpi/test_issue_1957.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_issue_1957():
4444
if pre_conns:
4545
# need to do this here, Disconnect invalidates pre_conns
4646
df = pd.DataFrame.from_dict(pre_conns.get()).drop(labels="target_thread", axis=1)
47-
df.to_csv(OTHER_LABEL.format(nest.num_processes) + f"-{nest.Rank()}.dat", index=False) # noqa: F821
47+
df.to_csv(OTHER_LABEL.format(nest.num_processes, nest.Rank()), index=False) # noqa: F821
4848

4949
nest.Disconnect(nrn, nrn)
5050
nest.Disconnect(nrn, nrn)

testsuite/pytests/sli2py_mpi/test_mini_brunel_ps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ def test_mini_brunel_ps():
100100
nest.Simulate(400)
101101

102102
# Uncomment next line to provoke test failure
103-
# nest.Simulate(200 if -nest.num_processes == 1 else 400)
103+
# nest.Simulate(200 if nest.num_processes == 1 else 400)

0 commit comments

Comments
 (0)