From b069c6a7882f35f42b80dbe99756d472a54636a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-No=C3=ABl=20Grad?= Date: Fri, 26 Mar 2021 17:26:34 +0100 Subject: [PATCH] tests: Apply suggestions from code review Co-authored-by: Alexander Reinauer --- testsuite/python/dawaanr-and-bh-gpu.py | 3 --- testsuite/python/field_test.py | 10 ++++---- testsuite/python/interactions_bonded.py | 4 +-- .../python/interactions_bonded_interface.py | 4 +-- testsuite/python/interactions_dihedral.py | 5 +--- testsuite/python/lb_boundary.py | 10 ++++---- testsuite/python/lb_switch.py | 4 +-- testsuite/python/mmm1d.py | 2 +- testsuite/python/pair_criteria.py | 5 ++-- testsuite/python/rdf.py | 9 +++---- testsuite/python/rotation_per_particle.py | 25 ++++++++----------- testsuite/python/rotational_inertia.py | 7 +++--- 12 files changed, 37 insertions(+), 51 deletions(-) diff --git a/testsuite/python/dawaanr-and-bh-gpu.py b/testsuite/python/dawaanr-and-bh-gpu.py index b5f98a79da7..f14a009fe80 100644 --- a/testsuite/python/dawaanr-and-bh-gpu.py +++ b/testsuite/python/dawaanr-and-bh-gpu.py @@ -92,9 +92,6 @@ def test(self): self.system.actors.add(bh_gpu) self.system.integrator.run(steps=0, recalc_forces=True) - bhgpu_f = [] - bhgpu_t = [] - bhgpu_f = np.copy(self.system.part[:].f) bhgpu_t = np.copy(self.system.part[:].torque_lab) bhgpu_e = self.system.analysis.energy()["total"] diff --git a/testsuite/python/field_test.py b/testsuite/python/field_test.py index 338fa987d08..9daf0197ad2 100644 --- a/testsuite/python/field_test.py +++ b/testsuite/python/field_test.py @@ -14,11 +14,11 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . -from itertools import product import unittest as ut import unittest_decorators as utx import numpy as np +import itertools import espressomd from espressomd import constraints @@ -167,7 +167,7 @@ def test_potential_field(self): with self.assertRaisesRegex(RuntimeError, 'Parameter particle_scales is read-only'): F.particle_scales = {0: 0.0} - for i in product(*map(range, 3 * [10])): + for i in itertools.product(*map(range, 3 * [10])): x = (h * i) f_val = F.call_method("_eval_field", x=x) np.testing.assert_allclose(f_val, self.potential(x), rtol=1e-3) @@ -194,7 +194,7 @@ def test_electric_potential_field(self): self.system.constraints.add(F) - for i in product(*map(range, 3 * [10])): + for i in itertools.product(*map(range, 3 * [10])): x = (h * i) f_val = F.call_method("_eval_field", x=x) np.testing.assert_allclose(f_val, self.potential(x), rtol=1e-3) @@ -226,7 +226,7 @@ def test_force_field(self): with self.assertRaisesRegex(RuntimeError, 'Parameter particle_scales is read-only'): F.particle_scales = {0: 0.0} - for i in product(*map(range, 3 * [10])): + for i in itertools.product(*map(range, 3 * [10])): x = (h * i) f_val = np.array(F.call_method("_eval_field", x=x)) np.testing.assert_allclose(f_val, self.force(x)) @@ -252,7 +252,7 @@ def test_flow_field(self): with self.assertRaisesRegex(RuntimeError, 'Parameter gamma is read-only'): F.gamma = 2.0 - for i in product(*map(range, 3 * [10])): + for i in itertools.product(*map(range, 3 * [10])): x = (h * i) f_val = np.array(F.call_method("_eval_field", x=x)) np.testing.assert_allclose(f_val, self.force(x)) diff --git a/testsuite/python/interactions_bonded.py b/testsuite/python/interactions_bonded.py index 23768756101..3a78e0dfe76 100644 --- a/testsuite/python/interactions_bonded.py +++ b/testsuite/python/interactions_bonded.py @@ -41,8 +41,8 @@ def setUp(self): self.system.cell_system.skin = 0.4 self.system.time_step = .2 - self.system.part.add(id=0, pos=self.start_pos, type=0) - self.system.part.add(id=1, pos=self.start_pos, type=0) + self.system.part.add(pos=self.start_pos, type=0) + self.system.part.add(pos=self.start_pos, type=0) def tearDown(self): self.system.part.clear() diff --git a/testsuite/python/interactions_bonded_interface.py b/testsuite/python/interactions_bonded_interface.py index b9d3cbb89c0..8f95a9868bd 100644 --- a/testsuite/python/interactions_bonded_interface.py +++ b/testsuite/python/interactions_bonded_interface.py @@ -26,8 +26,8 @@ class ParticleProperties(ut.TestCase): system = espressomd.System(box_l=[20.0, 20.0, 20.0]) - # Particle id to work on - system.part.add(id=17, pos=(0, 0, 0)) + # Particle to work on + system.part.add(pos=(0, 0, 0)) def bondsMatch(self, inType, outBond, inParams, outParams, msg_long): """Check, if the bond type set and gotten back as well as the bond diff --git a/testsuite/python/interactions_dihedral.py b/testsuite/python/interactions_dihedral.py index 5470cde2352..6a93f1dd17b 100644 --- a/testsuite/python/interactions_dihedral.py +++ b/testsuite/python/interactions_dihedral.py @@ -92,10 +92,7 @@ def setUp(self): self.system.cell_system.skin = 0.4 self.system.time_step = .1 - self.system.part.add(pos=self.start_pos, type=0) - self.system.part.add(pos=self.start_pos, type=0) - self.system.part.add(pos=self.start_pos, type=0) - self.system.part.add(pos=self.start_pos, type=0) + self.system.part.add(pos=4 * [self.start_pos], type=4 * [0]) def tearDown(self): self.system.part.clear() diff --git a/testsuite/python/lb_boundary.py b/testsuite/python/lb_boundary.py index 4e259a16c62..3c8439613e3 100644 --- a/testsuite/python/lb_boundary.py +++ b/testsuite/python/lb_boundary.py @@ -20,7 +20,7 @@ import espressomd.lb import espressomd.shapes import espressomd.lbboundaries -from itertools import product +import itertools class LBBoundariesBase: @@ -79,17 +79,17 @@ def test_clear(self): def check_boundary_flags(self, boundarynumbers): rng = range(20) - for i in product(range(0, 5), rng, rng): + for i in itertools.product(range(0, 5), rng, rng): self.assertEqual(self.lbf[i].boundary, boundarynumbers[0]) - for i in product(range(5, 15), rng, rng): + for i in itertools.product(range(5, 15), rng, rng): self.assertEqual(self.lbf[i].boundary, boundarynumbers[1]) - for i in product(range(15, 20), rng, rng): + for i in itertools.product(range(15, 20), rng, rng): self.assertEqual(self.lbf[i].boundary, boundarynumbers[2]) self.system.lbboundaries.clear() - for i in product(rng, rng, rng): + for i in itertools.product(rng, rng, rng): self.assertEqual(self.lbf[i].boundary, 0) def test_boundary_flags(self): diff --git a/testsuite/python/lb_switch.py b/testsuite/python/lb_switch.py index 4c160222fbc..1238d2623f5 100644 --- a/testsuite/python/lb_switch.py +++ b/testsuite/python/lb_switch.py @@ -19,7 +19,7 @@ import numpy as np import espressomd import espressomd.lb -from itertools import product +import itertools @utx.skipIfMissingFeatures(["EXTERNAL_FORCES"]) @@ -67,7 +67,7 @@ def switch_test(self, GPU=False): system.actors.add(lb_fluid_2) system.thermostat.set_lb(LB_fluid=lb_fluid_2, gamma=friction_2) - for pid in product(range(5), range(5), range(5)): + for pid in itertools.product(range(5), repeat=3): np.testing.assert_allclose( np.copy(lb_fluid_2[pid].velocity), np.zeros((3,))) diff --git a/testsuite/python/mmm1d.py b/testsuite/python/mmm1d.py index 2d6d4e4e6cc..45a6e529795 100644 --- a/testsuite/python/mmm1d.py +++ b/testsuite/python/mmm1d.py @@ -68,7 +68,7 @@ def test_energy(self): def test_with_analytical_result(self, prefactor=1.0, accuracy=1e-4): self.system.part.clear() p = self.system.part.add(pos=[0, 0, 0], q=1) - _ = self.system.part.add(pos=[0, 0, 1], q=1) + self.system.part.add(pos=[0, 0, 1], q=1) self.system.integrator.run(steps=0) f_measured = p.f diff --git a/testsuite/python/pair_criteria.py b/testsuite/python/pair_criteria.py index 0303ad1a2bf..86dd14dfd07 100644 --- a/testsuite/python/pair_criteria.py +++ b/testsuite/python/pair_criteria.py @@ -33,9 +33,8 @@ class PairCriteria(ut.TestCase): es.bonded_inter.add(f1) f2 = FeneBond(k=1, d_r_max=0.05) es.bonded_inter.add(f2) - es.part.add(pos=(0, 0, 0)) - es.part.add(pos=(0.91, 0, 0)) - p1, p2 = es.part[:] + p1 = es.part.add(pos=(0, 0, 0)) + p2 = es.part.add(pos=(0.91, 0, 0)) epsilon = 1E-8 def test_distance_crit_periodic(self): diff --git a/testsuite/python/rdf.py b/testsuite/python/rdf.py index 9048537236d..e2f43b2a6dc 100644 --- a/testsuite/python/rdf.py +++ b/testsuite/python/rdf.py @@ -107,12 +107,9 @@ def test_mixed(self): def test_rdf_interface(self): # test setters and getters s = self.s - s.part.add(pos=[0, 0, 0], type=0) - s.part.add(pos=[0, 0, 0], type=1) - s.part.add(pos=[0, 0, 0], type=0) - s.part.add(pos=[0, 0, 0], type=1) - pids1 = [s.part[:].id[0]] - pids2 = [s.part[:].id[1]] + s.part.add(pos=4 * [(0, 0, 0)], type=[0, 1, 0, 1]) + pids1 = s.part[:].id[0::2] + pids2 = s.part[:].id[1::2] observable = espressomd.observables.RDF(ids1=pids1, ids2=pids2, min_r=1, max_r=2, n_r_bins=3) # check pids diff --git a/testsuite/python/rotation_per_particle.py b/testsuite/python/rotation_per_particle.py index b58e52db9bd..5f92060921e 100644 --- a/testsuite/python/rotation_per_particle.py +++ b/testsuite/python/rotation_per_particle.py @@ -20,6 +20,7 @@ import unittest_decorators as utx import espressomd import numpy as np +import itertools @utx.skipIfMissingFeatures("ROTATION") @@ -36,17 +37,15 @@ def test_langevin(self): thermalized""" s = self.s s.thermostat.set_langevin(gamma=1, kT=1, seed=42) - for x in (False, True): - for y in (False, True): - for z in (False, True): - s.part.clear() - p = s.part.add(pos=(0, 0, 0), rotation=(x, y, z), - quat=(1, 0, 0, 0), omega_body=(0, 0, 0), - torque_lab=(0, 0, 0)) - s.integrator.run(500) - self.validate(p, x, 0) - self.validate(p, y, 1) - self.validate(p, z, 2) + for rot_x, rot_y, rot_z in itertools.product((False, True), repeat=3): + p = s.part.add(pos=(0, 0, 0), rotation=(rot_x, rot_y, rot_z), + quat=(1, 0, 0, 0), omega_body=(0, 0, 0), + torque_lab=(0, 0, 0)) + s.integrator.run(500) + self.validate(p, rot_x, 0) + self.validate(p, rot_y, 1) + self.validate(p, rot_z, 2) + s.part.clear() def validate(self, p, rotate, coord): if rotate: @@ -72,9 +71,7 @@ def test_axes_changes(self): rot[direction] = 1 p.rotation = rot - s.integrator.run(30) - - s.integrator.run(100) + s.integrator.run(130) # Check other axes: for axis in [1, 0, 0], [0, 1, 0], [0, 0, 1]: diff --git a/testsuite/python/rotational_inertia.py b/testsuite/python/rotational_inertia.py index b09e8fc6b8c..f68784f5ad5 100644 --- a/testsuite/python/rotational_inertia.py +++ b/testsuite/python/rotational_inertia.py @@ -54,11 +54,10 @@ def test_stability(self): tol = 4E-3 # Anisotropic inertial moment. Stable axes correspond to J[1] and J[2]. - # The unstable axis corresponds to J[0]. These values relation is J[1] - # < J[0] < J[2]. - J = np.array([5, 0.5, 18.5]) + # The unstable axis corresponds to J[0]. These values relation is + # J[1] < J[0] < J[2]. + p.rinertia = [5, 0.5, 18.5] - p.rinertia = J[:] # Validation of J[1] stability # ---------------------------- self.system.time_step = 0.0006