Updates to gmxapi FR15 acceptance test.
authorM. Eric Irrgang <ericirrgang@gmail.com>
Tue, 5 Nov 2019 15:14:45 +0000 (18:14 +0300)
committerPaul Bauer <paul.bauer.q@gmail.com>
Mon, 11 Nov 2019 15:54:12 +0000 (16:54 +0100)
* Let the test be runnable both with and without MPI.
* Improve the logging configuration.
* Update the test fixtures.
* Change the tested parameter edit to one that can be safely modified
  by directly editing the inputrec.

Change-Id: I7847bc47e3e244e82f6fd0d5471a097cdeecfbd5

python_packaging/test/test_fr15.py

index 6fcc72658201c2fd42265cb47c945907bebda535..6ae3b5bcaa24464862bb4c998b54801b11037dd2 100644 (file)
 
 """Test gmxapi functionality described in roadmap.rst."""
 
+import logging
+
 import pytest
 
 import gmxapi as gmx
 from gmxapi.version import has_feature
 
+# Configure the `logging` module before proceeding any further.
+gmx.logger.setLevel(logging.WARNING)
+
+try:
+    from mpi4py import MPI
+    rank_number = MPI.COMM_WORLD.Get_rank()
+except ImportError:
+    rank_number = 0
+    rank_tag = ''
+    MPI = None
+else:
+    rank_tag = 'rank{}:'.format(rank_number)
+
+# Use this formatter to improve the caplog log records.
+formatter = logging.Formatter(rank_tag + '%(name)s:%(levelname)s: %(message)s')
+
+@pytest.mark.usefixtures('cleandir')
 @pytest.mark.skipif(not has_feature('fr15'),
                    reason="Feature level not met.")
-def test_fr15():
+def test_fr15(spc_water_box, caplog):
     """FR15: Simulation input modification.
 
     * *gmx.modify_input produces new (tpr) simulation input in data flow operation*
       (requires interaction with library development)
-    * gmx.make_input dispatches appropriate preprocessing for file or in-memory simulation input.
     """
-    initial_input = gmx.read_tpr([tpr_filename for _ in range(10)])
-    tau_t = list([i/10. for i in range(10)])
-    param_sweep = gmx.modify_input(input=initial_input,
-                                   parameters={
-                                       'tau_t': tau_t
-                                   }
-                                   )
-    md = gmx.mdrun(param_sweep)
-    for tau_expected, tau_actual in zip(tau_t, md.output.params['tau_t'].extract()):
-        assert tau_expected == tau_actual
+    try:
+        from mpi4py import MPI
+        current_rank = MPI.COMM_WORLD.Get_rank()
+        ensemble_size = MPI.COMM_WORLD.Get_size()
+    except ImportError:
+        current_rank = 0
+        ensemble_size = 1
+
+    with caplog.at_level(logging.DEBUG):
+        caplog.handler.setFormatter(formatter)
+        with caplog.at_level(logging.WARNING, 'gmxapi'), \
+                 caplog.at_level(logging.DEBUG, 'gmxapi.mdrun'), \
+                 caplog.at_level(logging.DEBUG, 'gmxapi.modify_input'), \
+                 caplog.at_level(logging.DEBUG, 'gmxapi.read_tpr'), \
+                 caplog.at_level(logging.DEBUG, 'gmxapi.simulation'):
+
+            initial_input = gmx.read_tpr([spc_water_box for _ in range(ensemble_size)])
+            parameters = list([{'ld-seed': i} for i in range(ensemble_size)])
+            param_sweep = gmx.modify_input(input=initial_input,
+                                           parameters=parameters
+                                           )
+            md = gmx.mdrun(param_sweep)
+            # TODO: (#3179) Handle ensembles of size 1 more elegantly.
+            if md.output.ensemble_width > 1:
+                result_list = md.output.parameters['ld-seed'].result()
+            else:
+                result_list = [md.output.parameters['ld-seed'].result()]
+            for expected, actual in zip(parameters, result_list):
+                assert expected['ld-seed'] == actual