Skip to content

Commit

Permalink
Merge branch 'python' into listfix
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] authored Jun 23, 2021
2 parents f4c13e4 + 96f2718 commit ed9d67a
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 33 deletions.
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Jonas Landsgesell
Jon Halverson
Joost de Graaf
Josh Berryman
Julian Hoßbach
Julius Herb
Kai Grass
Kai Kratzer
Expand Down Expand Up @@ -102,6 +103,7 @@ Nils Binz
Nishchay Suri
Oleg V. Rud
Owen A. Hickey-Moriarty
Pablo Miguel Blanco Andrés
Pascal Hebbeker
Patrick Diggins
Patrick Kreissl
Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/polymer.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,10 @@ def setup_diamond_polymer(system=None, bond=None, MPC=0,
no_bonds, 1, bool, "no_bonds must be one bool")
if not no_bonds and not isinstance(bond, BondedInteraction):
raise TypeError(
"bond argument must be an instance of espressomd.interaction.BondedInteraction")
"bond argument must be an instance of espressomd.interactions.BondedInteraction")
if not isinstance(system, System):
raise TypeError(
"System argument must be an instance of an espressomd System")
"System argument must be an instance of espressomd.system.System")

check_type_or_throw_except(
MPC, 1, int, "MPC must be one int")
Expand Down
6 changes: 4 additions & 2 deletions src/python/espressomd/system.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ IF COLLISION_DETECTION == 1:

setable_properties = ["box_l", "min_global_cut", "periodicity", "time",
"time_step", "force_cap", "max_oif_objects"]
checkpointable_properties = ["max_oif_objects"]

if VIRTUAL_SITES:
setable_properties.append("_active_virtual_sites_handle")
checkpointable_properties.append("_active_virtual_sites_handle")


cdef bool _system_created = False
Expand Down Expand Up @@ -102,7 +104,7 @@ cdef class _Globals:
handle_errors("Error while assigning system periodicity")

def __get__(self):
periodicity = np.empty(3, dtype=np.bool)
periodicity = np.empty(3, dtype=type(True))
for i in range(3):
periodicity[i] = box_geo.periodic(i)
return array_locked(periodicity)
Expand Down Expand Up @@ -206,7 +208,7 @@ cdef class System:
odict = collections.OrderedDict()
odict['_globals'] = System.__getattribute__(self, "_globals")
odict['integrator'] = System.__getattribute__(self, "integrator")
for property_ in setable_properties:
for property_ in checkpointable_properties:
odict[property_] = System.__getattribute__(self, property_)
odict['non_bonded_inter'] = System.__getattribute__(
self, "non_bonded_inter")
Expand Down
2 changes: 1 addition & 1 deletion testsuite/python/lb.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def test_bool_operations_on_node(self):
nodes = [self.lbf[i, j, k] for i, j, k in itertools.product(x, y, z)]
nodes.remove(self.lbf[0, 0, 0])
assert all(self.lbf[0, 0, 0] != node for node in nodes)
# test __hash()__ intecept to indetify nodes based oon index rather
# test __hash()__ intercept to identify nodes based on index rather
# than name. set() constructor runs hash()
subset1, subset2 = nodes[:-10], nodes[-10:]
assert len(set(subset1 + subset1)) == len(subset1)
Expand Down
62 changes: 34 additions & 28 deletions testsuite/python/lb_slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,96 +24,102 @@ class LBSliceTest(ut.TestCase):

"""This simple test first writes random numbers and then reads them
to same slices of LB nodes and compares if the results are the same,
shape and value wise.
shape-wise and value-wise.
"""

system = espressomd.System(box_l=[10.0, 10.0, 10.0])
system.time_step = .01
system.cell_system.skin = 0.1
np.random.seed(seed=42)
lb_fluid = espressomd.lb.LBFluid(
agrid=1.0, dens=1., visc=1., tau=0.01)
system.actors.add(lb_fluid)

@classmethod
def setUpClass(cls):
cls.lb_fluid = espressomd.lb.LBFluid(
agrid=1.0, dens=1., visc=1., tau=0.01)
cls.system.actors.add(cls.lb_fluid)

def test_slicing(self):
lb_fluid = self.lb_fluid

# array locked
array = self.lb_fluid[1:-1:2, 5, 3:6:2].velocity
array = lb_fluid[1:-1:2, 5, 3:6:2].velocity
with self.assertRaisesRegex(ValueError, "ESPResSo array properties return non-writable arrays"):
array[0, 0, 0, 1] = 5.

# velocity on test slice [:-1, :-1, -1]
input_vel = np.random.rand(9, 9, 9, 3)
self.lb_fluid[:-1, :-1, :-1].velocity = input_vel
output_vel = self.lb_fluid[:-1, :-1, :-1].velocity
lb_fluid[:-1, :-1, :-1].velocity = input_vel
output_vel = lb_fluid[:-1, :-1, :-1].velocity
np.testing.assert_array_almost_equal(input_vel, np.copy(output_vel))

with self.assertRaisesRegex(ValueError, r"Input-dimensions of velocity array \(9, 9, 9, 2\) does not match slice dimensions \(9, 9, 9, 3\)"):
self.lb_fluid[:-1, :-1, :-1].velocity = input_vel[:, :, :, :2]
lb_fluid[:-1, :-1, :-1].velocity = input_vel[:, :, :, :2]

# velocity broadcast
self.lb_fluid[:, :, 0].velocity = [1, 2, 3]
lb_fluid[:, :, 0].velocity = [1, 2, 3]
np.testing.assert_array_almost_equal(
np.copy(self.lb_fluid[:, :, 0].velocity), 10 * [10 * [[[1, 2, 3]]]])
np.copy(lb_fluid[:, :, 0].velocity), 10 * [10 * [[[1, 2, 3]]]])

# density on test slice [1:-1:2, 5, 3:6:2]
input_dens = np.random.rand(4, 1, 2)
self.lb_fluid[1:-1:2, 5, 3:6:2].density = input_dens
output_dens = self.lb_fluid[1:-1:2, 5, 3:6:2].density
lb_fluid[1:-1:2, 5, 3:6:2].density = input_dens
output_dens = lb_fluid[1:-1:2, 5, 3:6:2].density
np.testing.assert_array_almost_equal(input_dens, np.copy(output_dens))

# density broadcast
self.lb_fluid[:, :, 0].density = 1.2
lb_fluid[:, :, 0].density = 1.2
np.testing.assert_array_almost_equal(
np.copy(self.lb_fluid[:, :, 0].density), 1.2)
np.copy(lb_fluid[:, :, 0].density), 1.2)

# population on test slice [:, :, :]
input_pop = np.random.rand(10, 10, 10, 19)
self.lb_fluid[:, :, :].population = input_pop
output_pop = self.lb_fluid[:, :, :].population
lb_fluid[:, :, :].population = input_pop
output_pop = lb_fluid[:, :, :].population
np.testing.assert_array_almost_equal(input_pop, np.copy(output_pop))

with self.assertRaisesRegex(ValueError, r"Input-dimensions of population array \(10, 10, 10, 5\) does not match slice dimensions \(10, 10, 10, 19\)"):
self.lb_fluid[:, :, :].population = input_pop[:, :, :, :5]
lb_fluid[:, :, :].population = input_pop[:, :, :, :5]

# pressure tensor on test slice [3, 6, 2:5]
output_pressure_shape = self.lb_fluid[3, 6, 2:5].pressure_tensor.shape
output_pressure_shape = lb_fluid[3, 6, 2:5].pressure_tensor.shape
should_pressure_shape = (1, 1, 3, 3, 3)
np.testing.assert_array_almost_equal(
output_pressure_shape, should_pressure_shape)

with self.assertRaises(NotImplementedError):
self.lb_fluid[3, 6, 2:5].pressure_tensor = np.zeros(
lb_fluid[3, 6, 2:5].pressure_tensor = np.zeros(
should_pressure_shape)

# pressure tensor neq on test slice [3, 6, 2:10]
output_pressure_neq_shape = self.lb_fluid[3:5,
6:7, 2:10].pressure_tensor_neq.shape
output_pressure_neq_shape = lb_fluid[3:5,
6:7,
2:10].pressure_tensor_neq.shape
should_pressure_neq_shape = (2, 1, 8, 3, 3)
np.testing.assert_array_almost_equal(
output_pressure_neq_shape, should_pressure_neq_shape)

with self.assertRaises(NotImplementedError):
self.lb_fluid[3:5, 6:7, 2:10].pressure_tensor_neq = np.zeros(
lb_fluid[3:5, 6:7, 2:10].pressure_tensor_neq = np.zeros(
output_pressure_neq_shape)

# index on test slice [1, 1:5, 6:]
output_index_shape = self.lb_fluid[1, 1:5, 6:].index.shape
output_index_shape = lb_fluid[1, 1:5, 6:].index.shape
should_index_shape = (1, 4, 4, 3)
np.testing.assert_array_almost_equal(
output_index_shape, should_index_shape)

with self.assertRaisesRegex(AttributeError, "attribute 'index' of 'espressomd.lb.LBFluidRoutines' objects is not writable"):
self.lb_fluid[1, 1:5, 6:].index = np.zeros(output_index_shape)
lb_fluid[1, 1:5, 6:].index = np.zeros(output_index_shape)

# boundary on test slice [1:, 1:, 1:]
if espressomd.has_features('LB_BOUNDARIES'):
output_boundary_shape = self.lb_fluid[1:, 1:, 1:].boundary.shape
output_boundary_shape = lb_fluid[1:, 1:, 1:].boundary.shape
should_boundary_shape = (9, 9, 9)
np.testing.assert_array_almost_equal(
output_boundary_shape, should_boundary_shape)

with self.assertRaises(NotImplementedError):
self.lb_fluid[1:, 1:, 1:].boundary = np.zeros(
lb_fluid[1:, 1:, 1:].boundary = np.zeros(
should_boundary_shape)

def test_iterator(self):
Expand All @@ -124,9 +130,9 @@ def test_iterator(self):
(x, y, z) for (
x, y, z) in itertools.product(
i_handle, j_handle, k_handle)]
# arrange node indices using __iter__() enforced converstion
# arrange node indices using __iter__() enforced conversion
iterator_indices = [x.index for x in lbslice_handle]
# check the results correspond pairwise. order implicitly preserved.
# check the results correspond pairwise. order is implicitly preserved.
# uses __eq()__ method form LBFluidRoutines()
assert all([x == y for x, y in zip(
arranged_indices, iterator_indices)])
Expand Down
28 changes: 28 additions & 0 deletions testsuite/python/p3m_tuning_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,10 @@ def test_09_no_errors_p3m_cpu_rescale_mesh(self):
self.assertEqual(tuned_mesh[1], 12)
self.assertEqual(tuned_mesh[2], 16)

# check MD cell reset event
self.system.box_l = self.system.box_l
self.system.periodicity = self.system.periodicity

@utx.skipIfMissingGPU()
@utx.skipIfMissingFeatures("P3M")
def test_09_no_errors_p3m_gpu_rescale_mesh(self):
Expand All @@ -429,6 +433,30 @@ def test_09_no_errors_p3m_gpu_rescale_mesh(self):
self.assertEqual(tuned_mesh[1], 30)
self.assertEqual(tuned_mesh[2], 40)

# check MD cell reset event
self.system.box_l = self.system.box_l
self.system.periodicity = self.system.periodicity

@utx.skipIfMissingFeatures("DP3M")
def test_09_no_errors_dp3m_cpu_rescale_mesh(self):
import espressomd.magnetostatics

self.system.time_step = 0.01
self.add_magnetic_particles()

dp3m_params = {'accuracy': 1e-6, 'mesh': [25, 25, 25], 'cao': 7,
'prefactor': 1.1, 'r_cut': 4.50, 'alpha': 0.8216263}
solver_dp3m = espressomd.magnetostatics.DipolarP3M(
epsilon='metallic', tune=False, **dp3m_params)
try:
self.system.actors.add(solver_dp3m)
except Exception as err:
self.fail('tuning raised Exception("' + str(err) + '")')

# check MD cell reset event
self.system.box_l = self.system.box_l
self.system.periodicity = self.system.periodicity


if __name__ == "__main__":
ut.main()
3 changes: 3 additions & 0 deletions testsuite/python/save_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@
system.box_l = 3 * [np.max(system.box_l)]
system.cell_system.skin = 0.1
system.time_step = 0.01
system.time = 1.5
system.force_cap = 1000.
system.min_global_cut = 2.0
system.max_oif_objects = 5

# create checkpoint folder
idx = "mycheckpoint_@TEST_COMBINATION@_@TEST_BINARY@".replace(".", "__")
Expand Down
8 changes: 8 additions & 0 deletions testsuite/python/scafacos_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ def test_actor_coulomb(self):
{'p3m_cao': '7', 'p3m_r_cut': '1.0',
'p3m_grid': '32', 'p3m_alpha': '2.799269'})

# check MD cell reset event
system.box_l = system.box_l
system.periodicity = system.periodicity

@ut.skipIf(not espressomd.has_features('SCAFACOS_DIPOLES') or
'p2nfft' not in espressomd.scafacos.available_methods(),
'Skipping test: missing ScaFaCoS p2nfft method')
Expand All @@ -122,6 +126,10 @@ def test_actor_dipoles(self):
self.assertEqual(params["method_name"], "p2nfft")
self.assertEqual(params["method_params"], method_params)

# check MD cell reset event
system.box_l = system.box_l
system.periodicity = system.periodicity

def p3m_data(self):
system = self.system

Expand Down
9 changes: 9 additions & 0 deletions testsuite/python/test_checkpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,10 @@ def test_system_variables(self):
self.assertTrue(cell_system_params['use_verlet_list'])
self.assertAlmostEqual(system.cell_system.skin, 0.1, delta=1E-10)
self.assertAlmostEqual(system.time_step, 0.01, delta=1E-10)
self.assertAlmostEqual(system.time, 1.5, delta=1E-10)
self.assertAlmostEqual(system.force_cap, 1000., delta=1E-10)
self.assertAlmostEqual(system.min_global_cut, 2.0, delta=1E-10)
self.assertEqual(system.max_oif_objects, 5)
np.testing.assert_allclose(np.copy(system.box_l), self.ref_box_l)
np.testing.assert_array_equal(
np.copy(system.periodicity), self.ref_periodicity)
Expand Down Expand Up @@ -216,6 +219,12 @@ def test_thermostat_SDM(self):
self.assertEqual(thmst['seed'], 42)
self.assertEqual(thmst['counter'], 0)

def test_integrator(self):
params = system.integrator.get_state()
self.assertAlmostEqual(params['force_cap'], 1000., delta=1E-10)
self.assertAlmostEqual(params['time_step'], 0.01, delta=1E-10)
self.assertAlmostEqual(params['time'], 1.5, delta=1E-10)

@utx.skipIfMissingFeatures('NPT')
@ut.skipIf('INT.NPT' not in modes, 'NPT integrator not in modes')
def test_integrator_NPT(self):
Expand Down

0 comments on commit ed9d67a

Please sign in to comment.