Skip to content

Commit

Permalink
Merge pull request #2336 from KaiSzuttor/checkpoint_test
Browse files Browse the repository at this point in the history
testsuite: fix checkpoint test.
  • Loading branch information
fweik authored Oct 27, 2018
2 parents ff5d134 + 00764c3 commit 068323d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
11 changes: 8 additions & 3 deletions testsuite/python/save_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@
system.part[0].q = 1
system.part[1].q = -1
p3m = espressomd.electrostatics.P3M(
prefactor=1.0, accuracy=0.1, mesh=10, cao=1, alpha=1.0, r_cut=1.0, tune=False)
prefactor=1.0,
accuracy=0.1,
mesh=10,
cao=1,
alpha=1.0,
r_cut=1.0,
tune=False)
system.actors.add(p3m)
obs = espressomd.observables.ParticlePositions(ids=[0, 1])
acc = espressomd.accumulators.MeanVarianceCalculator(obs=obs)
Expand All @@ -56,8 +62,7 @@

if espressomd.has_features(['VIRTUAL_SITES', 'VIRTUAL_SITES_RELATIVE']):
system.virtual_sites = espressomd.virtual_sites.VirtualSitesRelative(
have_velocity=True,
have_quaternion=True)
have_velocity=True, have_quaternion=True)
system.part[1].vs_auto_relate_to(0)
if espressomd.has_features(['LENNARD_JONES']):
system.non_bonded_inter[0, 0].lennard_jones.set_params(
Expand Down
37 changes: 23 additions & 14 deletions testsuite/python/test_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class CheckpointTest(ut.TestCase):
@classmethod
def setUpClass(self):
checkpoint = espressomd.checkpointing.Checkpoint(
checkpoint_id="mycheckpoint", checkpoint_path="@CMAKE_CURRENT_BINARY_DIR@")
checkpoint_id="mycheckpoint",
checkpoint_path="@CMAKE_CURRENT_BINARY_DIR@")
checkpoint.load(0)
if espressomd.has_features('LB'):
self.lbf = system.actors[0]
self.lbf.load_checkpoint("@CMAKE_CURRENT_BINARY_DIR@/lb.cpt", 1)

@ut.skipIf(not espressomd.has_features('LB'), "Skipping test due to missing features.")
@ut.skipIf(not espressomd.has_features('LB'),
"Skipping test due to missing features.")
def test_LB(self):
np.testing.assert_almost_equal(
np.copy(self.lbf[1, 1, 1].velocity), np.array([0.1, 0.2, 0.3]))
Expand All @@ -59,11 +61,13 @@ def test_part(self):
def test_thermostat(self):
self.assertEqual(system.thermostat.get_state()[0]['type'], 'LANGEVIN')
self.assertEqual(system.thermostat.get_state()[0]['kT'], 1.0)
np.testing.assert_array_equal(
system.thermostat.get_state()[0]['gamma'], np.array([2.0, 2.0, 2.0]))
np.testing.assert_array_equal(system.thermostat.get_state()[
0]['gamma'], np.array([2.0, 2.0, 2.0]))

@ut.skipIf(not espressomd.has_features(['LENNARD_JONES']),
"Cannot test for Lennard-Jones checkpointing because feature not compiled in.")
@ut.skipIf(
not espressomd.has_features(
['LENNARD_JONES']),
"Cannot test for Lennard-Jones checkpointing because feature not compiled in.")
def test_non_bonded_inter(self):
state = system.non_bonded_inter[
0, 0].lennard_jones._get_params_from_es_core()
Expand All @@ -75,8 +79,8 @@ def test_non_bonded_inter(self):
1.2, 'cutoff': 2.0, 'offset': 0.0, 'min': 0.0}
self.assertEqual(
len(set(state.items()) & set(reference.items())), len(reference))
self.assertEqual(
len(set(state2.items()) & set(reference2.items())), len(reference2))
self.assertEqual(len(set(state2.items()) & set(
reference2.items())), len(reference2))

def test_bonded_inter(self):
state = system.part[1].bonds[0][0].params
Expand All @@ -87,23 +91,28 @@ def test_bonded_inter(self):
@ut.skipIf(
not espressomd.has_features(
['VIRTUAL_SITES', 'VIRTUAL_SITES_RELATIVE']),
"Cannot test for virtual site checkpointing because feature not compiled in.")
"Cannot test for virtual site checkpointing because feature not compiled in.")
def test_virtual_sites(self):
self.assertEqual(system.part[1].virtual, 1)
self.assertTrue(
isinstance(system.virtual_sites, espressomd.virtual_sites.VirtualSitesRelative))
isinstance(
system.virtual_sites,
espressomd.virtual_sites.VirtualSitesRelative))

def test_mean_variance_calculator(self):
np.testing.assert_array_equal(
acc.get_mean(), np.array([1.0, 1.5, 2.0, 1.0, 1.0, 2.0]))
np.testing.assert_array_equal(
acc.get_variance(), np.array([0., 0.5, 2., 0., 0., 0.]))

@ut.skipIf(not espressomd.has_features(['ELECTROSTATICS']),
"Cannot test for P3M checkpointing because feature not compiled in.")
@ut.skipIf(
not espressomd.has_features(
['ELECTROSTATICS']),
"Cannot test for P3M checkpointing because feature not compiled in.")
def test_p3m(self):
self.assertTrue(
isinstance(system.actors.active_actors[1], espressomd.electrostatics.P3M))
self.assertTrue(any(isinstance(actor, espressomd.electrostatics.P3M)
for actor in system.actors.active_actors))


if __name__ == '__main__':
ut.main()

0 comments on commit 068323d

Please sign in to comment.