Skip to content

Commit 7c8209d

Browse files
authored
Merge pull request #3447 from heplesser/mpitest_error_reporting
Handle CalledProcessError better
2 parents 09b349c + 197833b commit 7c8209d

File tree

3 files changed

+83
-12
lines changed

3 files changed

+83
-12
lines changed

pynest/nest/lib/hl_api_types.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,8 +868,13 @@ def get(self, keys=None, output=""):
868868
# This avoids problems with invalid SynapseCollections.
869869
# See also #3100.
870870
if self.__len__() == 0 or GetKernelStatus("network_size") == 0:
871-
# Return empty tuple if get is called with an argument
872-
return {} if keys is None else ()
871+
if pandas_output:
872+
return pandas.DataFrame()
873+
elif output == "json":
874+
return to_json({})
875+
else:
876+
# Return empty tuple if get is called with an argument
877+
return {} if keys is None else ()
873878

874879
if keys is None:
875880
cmd = "GetStatus"

testsuite/pytests/sli2py_mpi/mpi_test_wrapper.py

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,12 +183,29 @@ def wrapper(*args, **kwargs):
183183

184184
res = {}
185185
for procs in self._procs_lst:
186-
res[procs] = subprocess.run(
187-
["mpirun", "-np", str(procs), "--oversubscribe", "python", self.RUNNER],
188-
check=True,
189-
cwd=tmpdirpath,
190-
capture_output=self._debug,
191-
)
186+
try:
187+
command = ["mpirun", "-np", str(procs), "--oversubscribe", "python", self.RUNNER]
188+
res[procs] = subprocess.run(
189+
command,
190+
check=True,
191+
cwd=tmpdirpath,
192+
capture_output=True, # always capture, in case an error is thrown
193+
)
194+
except subprocess.CalledProcessError as err:
195+
print("\n")
196+
print("-" * 50)
197+
print(f"Running failed for: {command}")
198+
print(f"tmpdir : {tmpdir.name}")
199+
print("-" * 50)
200+
print("STDOUT")
201+
print("-" * 50)
202+
print(err.stdout.decode("UTF-8"))
203+
print("-" * 50)
204+
print("STDERR")
205+
print("-" * 50)
206+
print(err.stderr.decode("UTF-8"))
207+
print("-" * 50)
208+
raise err
192209

193210
if self._debug:
194211
print("\n\n")
@@ -210,10 +227,17 @@ def _collect_result_by_label(self, tmpdirpath, label):
210227
except StopIteration:
211228
return None # no data for this label
212229

213-
return {
214-
n_procs: [pd.read_csv(f, sep="\t", comment="#") for f in tmpdirpath.glob(label.format(n_procs, "*"))]
215-
for n_procs in self._procs_lst
216-
}
230+
res = {}
231+
for n_procs in self._procs_lst:
232+
data = []
233+
for f in tmpdirpath.glob(label.format(n_procs, "*")):
234+
try:
235+
data.append(pd.read_csv(f, sep="\t", comment="#"))
236+
except pd.errors.EmptyDataError:
237+
pass
238+
res[n_procs] = data
239+
240+
return res
217241

218242
def collect_results(self, tmpdirpath):
219243
"""
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# -*- coding: utf-8 -*-
2+
#
3+
# test_self_get_conns_with_empty_ranks.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 numpy as np
23+
import pandas
24+
import pytest
25+
from mpi_test_wrapper import MPITestAssertEqual
26+
27+
28+
# Parametrization over the number of nodes here only to show hat it works
29+
@MPITestAssertEqual([1, 2, 4], debug=False)
30+
def test_self_get_conns_with_empty_ranks():
31+
"""
32+
Selftest: Confirm that connections can be gathered correctly even if some ranks have no neurons.
33+
"""
34+
35+
import nest
36+
import pandas as pd
37+
38+
nrns = nest.Create("parrot_neuron", n=2)
39+
nest.Connect(nrns, nrns)
40+
41+
conns = nest.GetConnections().get(output="pandas").drop(labels=["target_thread", "port"], axis=1, errors="ignore")
42+
conns.to_csv(OTHER_LABEL.format(nest.num_processes, nest.Rank()), index=False) # noqa: F821

0 commit comments

Comments
 (0)