Skip to content

Commit

Permalink
Merge pull request nest#807 from hakonsbm/test_connect_all_mpirun
Browse files Browse the repository at this point in the history
Run tests in test_connect_all_patterns.py with mpirun
  • Loading branch information
heplesser authored Oct 30, 2017
2 parents 37c9069 + 8e9ccf1 commit 04726d9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
56 changes: 36 additions & 20 deletions pynest/nest/tests/test_connect_all_patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,47 @@
# You should have received a copy of the GNU General Public License
# along with NEST. If not, see <http://www.gnu.org/licenses/>.

import numpy as np
import os
import subprocess as sp
import unittest
import nest

from . import test_connect_helpers as hf
HAVE_MPI = nest.sli_func("statusdict/have_mpi ::")

from .test_connect_parameters import TestParams
from .test_connect_one_to_one import TestOneToOne
from .test_connect_all_to_all import TestAllToAll
from .test_connect_fixed_indegree import TestFixedInDegree
from .test_connect_fixed_outdegree import TestFixedOutDegree
from .test_connect_fixed_total_number import TestFixedTotalNumber
from .test_connect_pairwise_bernoulli import TestPairwiseBernoulli

nest.set_verbosity("M_WARNING")
class TestConnectAllPatterns(unittest.TestCase):

@unittest.skipIf(not HAVE_MPI, 'NEST was compiled without MPI')
def testWithMPI(self):
# Check that we can import mpi4py
try:
from mpi4py import MPI
except ImportError:
raise unittest.SkipTest("mpi4py required")
directory = os.path.dirname(os.path.realpath(__file__))
scripts = ["test_connect_all_to_all.py",
"test_connect_one_to_one.py",
"test_connect_fixed_indegree.py",
"test_connect_fixed_outdegree.py",
"test_connect_fixed_total_number.py",
"test_connect_pairwise_bernoulli.py"
]
failing_tests = []
for script in scripts:
test_script = os.path.join(directory, script)
command = nest.sli_func("mpirun", 2, "nosetests",
test_script)
command = command.split()
process = sp.Popen(command, stdout=sp.PIPE, stderr=sp.PIPE)
stdout, stderr = process.communicate()
retcode = process.returncode
if retcode != 0:
failing_tests.append(script)
self.assertTrue(not failing_tests, 'The following tests failed when ' +
'executing with "mpirun -np 2 nosetests [script]": ' +
", ".join(failing_tests))


if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestAllToAll)
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(TestOneToOne))
suite.addTest(
unittest.TestLoader().loadTestsFromTestCase(TestFixedInDegree))
suite.addTest(
unittest.TestLoader().loadTestsFromTestCase(TestFixedOutDegree))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
TestFixedTotalNumber))
suite.addTest(unittest.TestLoader().loadTestsFromTestCase(
TestPairwiseBernoulli))
suite = unittest.TestLoader().loadTestsFromTestCase(TestConnectAllPatterns)
unittest.TextTestRunner(verbosity=2).run(suite)
4 changes: 2 additions & 2 deletions pynest/nest/tests/test_connect_one_to_one.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def testSymmetricFlag(self):
M1 = hf.get_connectivity_matrix(self.pop1, self.pop2)
M2 = hf.get_connectivity_matrix(self.pop2, self.pop1)
# test that connections were created in both directions
hf.mpi_assert(M1, np.transpose(M2), self)
hf.mpi_assert(M1, np.transpose(hf.gather_data(M2)), self)
# test that no other connections were created
hf.mpi_assert(M1-np.identity(self.N), np.zeros_like(M1), self)
hf.mpi_assert(M1, np.zeros_like(M1) + np.identity(self.N), self)

def testInputArray(self):
syn_params = {}
Expand Down

0 comments on commit 04726d9

Please sign in to comment.