From 83ff02fa8d9d5ddb2065638afc8b3f85d81cb908 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 23 Dec 2022 13:18:02 +0100 Subject: [PATCH 1/2] tests: Modernize test case with subtests --- testsuite/python/virtual_sites_relative.py | 42 +++++++++++++--------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/testsuite/python/virtual_sites_relative.py b/testsuite/python/virtual_sites_relative.py index 271058ce495..0b5ead8cae6 100644 --- a/testsuite/python/virtual_sites_relative.py +++ b/testsuite/python/virtual_sites_relative.py @@ -32,6 +32,8 @@ class VirtualSites(ut.TestCase): def setUp(self): self.system.box_l = [10.0, 10.0, 10.0] + self.system.cell_system.set_regular_decomposition( + use_verlet_lists=True) def tearDown(self): self.system.part.clear() @@ -266,10 +268,7 @@ def run_test_lj(self): # Setup system.box_l = [l, l, l] system.min_global_cut = 0.501 - system.part.clear() - system.time_step = 0.01 - system.thermostat.turn_off() # Dumbbells consist of 2 virtual lj spheres + central particle # w/o interactions. For n spheres, n/2 dumbbells. @@ -300,8 +299,12 @@ def run_test_lj(self): # Remove overlap system.integrator.set_steepest_descent( f_max=0, gamma=0.1, max_displacement=0.1) - while system.analysis.energy()["total"] > 10 * n: + n_loops = 0 + n_max = 10 + while system.analysis.energy()["total"] > 10 * n and n_loops < n_max: system.integrator.run(20) + n_loops += 1 + assert n_loops < n_max, "Steepest descent didn't converge" # Integrate system.integrator.set_vv() for i in range(10): @@ -312,7 +315,7 @@ def run_test_lj(self): # Constant energy to get rid of thermostat forces in the # verification system.integrator.run(2) - # Check the virtual sites config,pos and vel of the lj spheres + # Check the virtual sites config, pos and vel of the lj spheres for j in range(int(n / 2)): self.verify_vs(system.part.by_id(3 * j + 1)) self.verify_vs(system.part.by_id(3 * j + 2)) @@ -323,26 +326,33 @@ def run_test_lj(self): tests_common.verify_lj_forces(system, 1E-10, 3 * np.arange(n // 2)) # Test applying changes - enegry_pre_change = system.analysis.energy()['total'] + energy_pre_change = system.analysis.energy()['total'] pressure_pre_change = system.analysis.pressure()['total'] p0 = system.part.by_id(0) p0.pos = p0.pos + (2.2, -1.4, 4.2) - enegry_post_change = system.analysis.energy()['total'] + energy_post_change = system.analysis.energy()['total'] pressure_post_change = system.analysis.pressure()['total'] - self.assertNotAlmostEqual(enegry_pre_change, enegry_post_change) + self.assertNotAlmostEqual(energy_pre_change, energy_post_change) self.assertNotAlmostEqual(pressure_pre_change, pressure_post_change) def test_lj(self): """Run LJ fluid test for different cell systems.""" - system = self.system - system.cell_system.skin = 0.4 - system.cell_system.set_n_square(use_verlet_lists=True) - self.run_test_lj() - system.cell_system.set_regular_decomposition(use_verlet_lists=True) - self.run_test_lj() - system.cell_system.set_regular_decomposition(use_verlet_lists=False) - self.run_test_lj() + self.system.cell_system.skin = 0.4 + with self.subTest(msg='N-square cell system with Verlet lists'): + self.system.cell_system.set_n_square(use_verlet_lists=True) + self.run_test_lj() + self.tearDown() + with self.subTest(msg='regular decomposition cell system with Verlet lists'): + self.system.cell_system.set_regular_decomposition( + use_verlet_lists=True) + self.run_test_lj() + self.tearDown() + with self.subTest(msg='regular decomposition cell system without Verlet lists'): + self.system.cell_system.set_regular_decomposition( + use_verlet_lists=False) + self.run_test_lj() + self.tearDown() @utx.skipIfMissingFeatures("EXTERNAL_FORCES") def test_zz_pressure_tensor(self): From 514e3955d6ae0d4fac4896855b6226946b14ce94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 23 Dec 2022 13:20:23 +0100 Subject: [PATCH 2/2] tests: Add diagnostics to flaky test case --- testsuite/python/virtual_sites_relative.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/testsuite/python/virtual_sites_relative.py b/testsuite/python/virtual_sites_relative.py index 0b5ead8cae6..81b377f5742 100644 --- a/testsuite/python/virtual_sites_relative.py +++ b/testsuite/python/virtual_sites_relative.py @@ -22,6 +22,8 @@ import espressomd.virtual_sites import numpy as np import tests_common +import time +import sys @utx.skipIfMissingFeatures(["VIRTUAL_SITES_RELATIVE", "LENNARD_JONES"]) @@ -31,6 +33,7 @@ class VirtualSites(ut.TestCase): np.random.seed(42) def setUp(self): + print(f"setUp({time.ctime()})", end=" ", file=sys.stderr, flush=True) self.system.box_l = [10.0, 10.0, 10.0] self.system.cell_system.set_regular_decomposition( use_verlet_lists=True) @@ -41,6 +44,8 @@ def tearDown(self): self.system.integrator.set_vv() self.system.non_bonded_inter[0, 0].lennard_jones.deactivate() self.system.virtual_sites = espressomd.virtual_sites.VirtualSitesOff() + print(f"tearDown({time.ctime()})", end=" ", file=sys.stderr, + flush=True) def multiply_quaternions(self, a, b): return np.array(