Skip to content

Commit 4943a04

Browse files
committed
Fix handling of OTHER data if some ranks have no data or if there are no connections on a rank
1 parent 5000aa8 commit 4943a04

File tree

3 files changed

+60
-6
lines changed

3 files changed

+60
-6
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: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,17 @@ def _collect_result_by_label(self, tmpdirpath, label):
227227
except StopIteration:
228228
return None # no data for this label
229229

230-
return {
231-
n_procs: [pd.read_csv(f, sep="\t", comment="#") for f in tmpdirpath.glob(label.format(n_procs, "*"))]
232-
for n_procs in self._procs_lst
233-
}
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
234241

235242
def collect_results(self, tmpdirpath):
236243
"""
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_all_to_all.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)