|
| 1 | +# improve support for NumPy 2 |
| 2 | +# https://github.com/espressomd/espresso/pull/4992 |
| 3 | +# https://github.com/espressomd/espresso/pull/5034 |
| 4 | +--- a/testsuite/python/thermostats_common.py |
| 5 | ++++ b/testsuite/python/thermostats_common.py |
| 6 | +@@ -19,2 +19,3 @@ |
| 7 | + import numpy as np |
| 8 | ++import scipy.integrate |
| 9 | + |
| 10 | +@@ -28,3 +29,3 @@ |
| 11 | + x = np.linspace(x1, x2, 1000) |
| 12 | +- return np.trapz(np.exp(-x**2 / (2. * kT)), x) / np.sqrt(2. * np.pi * kT) |
| 13 | ++ return scipy.integrate.trapezoid(np.exp(-x**2 / (2. * kT)), x=x) / np.sqrt(2. * np.pi * kT) |
| 14 | + |
| 15 | +--- a/testsuite/python/widom_insertion.py |
| 16 | ++++ b/testsuite/python/widom_insertion.py |
| 17 | +@@ -24,2 +24,3 @@ |
| 18 | + import numpy as np |
| 19 | ++import scipy.integrate |
| 20 | + import espressomd |
| 21 | +@@ -52,3 +53,3 @@ |
| 22 | + # coordinates |
| 23 | +- integrateUpToCutOff = 4 * np.pi * np.trapz( |
| 24 | ++ integrateUpToCutOff = 4 * np.pi * scipy.integrate.trapezoid( |
| 25 | + radius**2 * np.exp(-tests_common.lj_potential(radius, |
| 26 | +diff --git a/testsuite/python/brownian_dynamics.py b/testsuite/python/brownian_dynamics.py |
| 27 | +index 223340e15..f99d94018 100644 |
| 28 | +--- a/testsuite/python/brownian_dynamics.py |
| 29 | ++++ b/testsuite/python/brownian_dynamics.py |
| 30 | +@@ -161,5 +161,5 @@ class BrownianThermostat(ut.TestCase): |
| 31 | + system.integrator.run(3) |
| 32 | + np.testing.assert_allclose( |
| 33 | +- part.omega_lab, [0, 0, 1.3 / 1.5], atol=1e-14) |
| 34 | ++ np.copy(part.omega_lab), [0, 0, 1.3 / 1.5], atol=1e-14) |
| 35 | + |
| 36 | + # noise only |
| 37 | +@@ -168,5 +168,5 @@ class BrownianThermostat(ut.TestCase): |
| 38 | + kT=1, gamma=1, gamma_rotation=1.5, act_on_virtual=False, seed=41) |
| 39 | + system.integrator.run(3) |
| 40 | +- self.assertGreater(np.linalg.norm(part.omega_lab), 0.) |
| 41 | ++ self.assertGreater(np.linalg.norm(np.copy(part.omega_lab)), 0.) |
| 42 | + |
| 43 | + |
| 44 | +diff --git a/testsuite/python/lees_edwards.py b/testsuite/python/lees_edwards.py |
| 45 | +index 002340bd2..4539f1af5 100644 |
| 46 | +--- a/testsuite/python/lees_edwards.py |
| 47 | ++++ b/testsuite/python/lees_edwards.py |
| 48 | +@@ -397,5 +397,5 @@ class LeesEdwards(ut.TestCase): |
| 49 | + a=k_non_bonded / 2, n=-2, cutoff=r_cut) |
| 50 | + system.integrator.run(0) |
| 51 | +- r_12 = system.distance_vec(p1, p2) |
| 52 | ++ r_12 = np.copy(system.distance_vec(p1, p2)) |
| 53 | + |
| 54 | + np.testing.assert_allclose( |
| 55 | +@@ -405,5 +405,5 @@ class LeesEdwards(ut.TestCase): |
| 56 | + np.testing.assert_allclose( |
| 57 | + np.copy(system.analysis.pressure_tensor()["non_bonded"]), |
| 58 | +- np.outer(r_12, p2.f) / system.volume()) |
| 59 | ++ np.outer(r_12, np.copy(p2.f)) / system.volume()) |
| 60 | + |
| 61 | + np.testing.assert_almost_equal( |
| 62 | +@@ -438,5 +438,5 @@ class LeesEdwards(ut.TestCase): |
| 63 | + shear_direction="x", shear_plane_normal="y", protocol=lin_protocol) |
| 64 | + # Test position and velocity of VS with Le shift |
| 65 | +- old_p3_pos = p3.pos |
| 66 | ++ old_p3_pos = np.copy(p3.pos) |
| 67 | + expected_p3_pos = old_p3_pos - \ |
| 68 | + np.array((get_lin_pos_offset(system.time, **params_lin), 0, 0)) |
| 69 | +@@ -444,5 +444,5 @@ class LeesEdwards(ut.TestCase): |
| 70 | + np.testing.assert_allclose(np.copy(p3.pos_folded), expected_p3_pos) |
| 71 | + np.testing.assert_allclose( |
| 72 | +- p3.v, p1.v + np.array((params_lin["shear_velocity"], 0, 0))) |
| 73 | ++ np.copy(p3.v), np.copy(p1.v) + np.array((params_lin["shear_velocity"], 0, 0))) |
| 74 | + |
| 75 | + # Check distances |
| 76 | +diff --git a/testsuite/python/test_checkpoint.py b/testsuite/python/test_checkpoint.py |
| 77 | +index f295cec44..4b30aaefb 100644 |
| 78 | +--- a/testsuite/python/test_checkpoint.py |
| 79 | ++++ b/testsuite/python/test_checkpoint.py |
| 80 | +@@ -217,12 +217,12 @@ class CheckpointTest(ut.TestCase): |
| 81 | + np.testing.assert_allclose(np.copy(p3.ext_torque), [0.3, 0.5, 0.7]) |
| 82 | + if espressomd.has_features('ROTATIONAL_INERTIA'): |
| 83 | +- np.testing.assert_allclose(p3.rinertia, [2., 3., 4.]) |
| 84 | ++ np.testing.assert_allclose(np.copy(p3.rinertia), [2., 3., 4.]) |
| 85 | + if espressomd.has_features('THERMOSTAT_PER_PARTICLE'): |
| 86 | + gamma = 2. |
| 87 | + if espressomd.has_features('PARTICLE_ANISOTROPY'): |
| 88 | + gamma = np.array([2., 3., 4.]) |
| 89 | +- np.testing.assert_allclose(p4.gamma, gamma) |
| 90 | ++ np.testing.assert_allclose(np.copy(p4.gamma), gamma) |
| 91 | + if espressomd.has_features('ROTATION'): |
| 92 | +- np.testing.assert_allclose(p3.gamma_rot, 2. * gamma) |
| 93 | ++ np.testing.assert_allclose(np.copy(p3.gamma_rot), 2. * gamma) |
| 94 | + if espressomd.has_features('ENGINE'): |
| 95 | + self.assertEqual(p3.swimming, {"f_swim": 0.03, "mode": "N/A", |
| 96 | +@@ -237,9 +237,11 @@ class CheckpointTest(ut.TestCase): |
| 97 | + q_ind = ([1, 2, 3, 0],) # convert from scalar-first to scalar-last |
| 98 | + vs_id, vs_dist, vs_quat = p2.vs_relative |
| 99 | +- d = p2.pos - p1.pos |
| 100 | ++ d = np.copy(p2.pos - p1.pos) |
| 101 | ++ vs_quat = np.copy(vs_quat) |
| 102 | ++ p_quat = np.copy(p1.quat) |
| 103 | + theta = np.arccos(d[2] / np.linalg.norm(d)) |
| 104 | + assert abs(theta - 3. * np.pi / 4.) < 1e-8 |
| 105 | + q = np.array([0., 0., np.sin(theta / 2.), -np.cos(theta / 2.)]) |
| 106 | +- r = R.from_quat(p1.quat[q_ind]) * R.from_quat(vs_quat[q_ind]) |
| 107 | ++ r = R.from_quat(p_quat[q_ind]) * R.from_quat(vs_quat[q_ind]) |
| 108 | + self.assertEqual(vs_id, p1.id) |
| 109 | + np.testing.assert_allclose(vs_dist, np.sqrt(2.)) |
| 110 | +@@ -500,5 +502,5 @@ class CheckpointTest(ut.TestCase): |
| 111 | + self.assertEqual(p_virt.vs_relative[1], np.sqrt(2.)) |
| 112 | + np.testing.assert_allclose( |
| 113 | +- p_real.vs_relative[2], [1., 0., 0., 0.], atol=1e-10) |
| 114 | ++ np.copy(p_real.vs_relative[2]), [1., 0., 0., 0.], atol=1e-10) |
| 115 | + |
| 116 | + def test_mean_variance_calculator(self): |
| 117 | +@@ -785,6 +787,6 @@ class CheckpointTest(ut.TestCase): |
| 118 | + p2 = system.part.add(pos=[system.box_l[0] - 1., 1.6, 0.], type=6) |
| 119 | + system.integrator.run(0, recalc_forces=True) |
| 120 | +- np.testing.assert_allclose(p1.f, [0., 1e8, 0.], atol=1e-3) |
| 121 | +- np.testing.assert_allclose(p2.f, [0., 1e8, 0.], atol=1e-3) |
| 122 | ++ np.testing.assert_allclose(np.copy(p1.f), [0., 1e8, 0.], atol=1e-3) |
| 123 | ++ np.testing.assert_allclose(np.copy(p2.f), [0., 1e8, 0.], atol=1e-3) |
| 124 | + p1.remove() |
| 125 | + p2.remove() |
0 commit comments