Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ARM architectures #4708

Merged
merged 6 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
tests: Decrease sensitivity to rounding errors
Expressions involving multiple multiplications can lead to rounding
errors in the order of 1.5 machine precision, triggering assertions
on architectures that don't support double extended precision, or
when fast-math mode is enabled.
  • Loading branch information
jngrad committed Apr 17, 2023
commit 18aeab318cbf2df7450d8c2e5e3634802345454c
2 changes: 1 addition & 1 deletion src/core/reaction_methods/tests/ReactionAlgorithm_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ReactionAlgorithm : public ReactionMethods::ReactionAlgorithm {
// Check the base class for all Monte Carlo algorithms.
BOOST_FIXTURE_TEST_CASE(ReactionAlgorithm_test, ParticleFactory) {
using ReactionMethods::SingleReaction;
auto constexpr tol = 100. * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
auto const comm = boost::mpi::communicator();

// check acceptance rate
Expand Down
4 changes: 2 additions & 2 deletions src/core/reaction_methods/tests/SingleReaction_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
// and the configurational move probability for a given system state.
BOOST_AUTO_TEST_CASE(SingleReaction_test) {
using namespace ReactionMethods;
constexpr double tol = 100 * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();

// create a reaction A -> 3 B + 4 C
int const type_A = 0;
Expand Down Expand Up @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(SingleReaction_test) {
std::unordered_map<int, int>{{type_A, i}, {type_B, j}, {type_C, k}};
auto const val = calculate_factorial_expression(reaction, p_numbers);
auto const ref = g(i, -1) * g(j, 3) * g(k, 4);
BOOST_CHECK_CLOSE(val, ref, 5 * tol);
BOOST_CHECK_CLOSE(val, ref, 5. * tol);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

BOOST_AUTO_TEST_CASE(factorial_Ni0_divided_by_factorial_Ni0_plus_nu_i_test) {
using namespace ReactionMethods;
constexpr double tol = 100. * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();

auto const reaction_ensemble_combinations = [](int N, int nu) {
return (N + nu < 0) ? 0. : std::tgamma(N + 1) / std::tgamma(N + nu + 1);
Expand Down
2 changes: 1 addition & 1 deletion src/core/unit_tests/EspressoSystemStandAlone_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ static auto copy_particle_to_head_node(boost::mpi::communicator const &comm,
}

BOOST_FIXTURE_TEST_CASE(espresso_system_stand_alone, ParticleFactory) {
constexpr auto tol = 100. * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
auto const comm = boost::mpi::communicator();
auto const rank = comm.rank();
auto const n_nodes = comm.size();
Expand Down
2 changes: 1 addition & 1 deletion src/core/unit_tests/Verlet_list_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ auto const propagators =
BOOST_DATA_TEST_CASE_F(ParticleFactory, verlet_list_update,
bdata::make(node_grids) * bdata::make(propagators),
node_grid, integration_helper) {
constexpr auto tol = 100. * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
auto const comm = boost::mpi::communicator();
auto const rank = comm.rank();

Expand Down
2 changes: 1 addition & 1 deletion src/core/unit_tests/p3m_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ BOOST_AUTO_TEST_CASE(calc_meshift_true) {
#if defined(P3M) || defined(DP3M)
BOOST_AUTO_TEST_CASE(analytic_cotangent_sum) {
auto constexpr kernel = p3m_analytic_cotangent_sum;
auto constexpr tol = 100. * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();

// check only trivial cases
for (auto const cao : {1, 2, 3, 4, 5, 6, 7}) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/unit_tests/periodic_fold_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(with_image_count) {
BOOST_CHECK(res.first >= 0.);
BOOST_CHECK(res.first <= box);
BOOST_CHECK(std::abs(res.first - x + res.second * box) <=
std::numeric_limits<double>::epsilon());
4. * std::numeric_limits<double>::epsilon());
}

/* Corner right */
Expand All @@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(with_image_count) {
BOOST_CHECK(res.first >= 0.);
BOOST_CHECK(res.first < box);
BOOST_CHECK(std::abs(res.first - x + res.second * box) <=
std::numeric_limits<double>::epsilon());
4. * std::numeric_limits<double>::epsilon());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/unit_tests/specfunc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <cmath>
#include <limits>

constexpr auto eps = 100. * std::numeric_limits<double>::epsilon();
auto constexpr eps = 8. * 100. * std::numeric_limits<double>::epsilon();

BOOST_AUTO_TEST_CASE(hurwitz_zeta_function) {
constexpr auto max_bits = 54.0;
Expand Down
2 changes: 1 addition & 1 deletion src/core/unit_tests/thermostats_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

// multiply by 100 because BOOST_CHECK_CLOSE takes a percentage tolerance,
// and by 6 to account for error accumulation in thermostat functions
constexpr auto tol = 6 * 100 * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
jngrad marked this conversation as resolved.
Show resolved Hide resolved

Particle particle_factory() {
Particle p{};
Expand Down
2 changes: 1 addition & 1 deletion src/particle_observables/tests/algorithms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(algorithms_integer) {
}

BOOST_AUTO_TEST_CASE(algorithms_double) {
auto constexpr tol = 100 * std::numeric_limits<double>::epsilon();
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
std::vector<double> const values{1., 2., 3., 4.};
{
auto const res = WeightedAverage<Testing::Identity, Testing::One>()(values);
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/unit_tests/Ellipsoid_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

BOOST_AUTO_TEST_CASE(dist_function) {
// multiply by 100 because BOOST_REQUIRE_CLOSE takes a percentage tolerance
auto constexpr tol = std::numeric_limits<double>::epsilon() * 100;
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
double const semiaxes[3] = {3.1, 2.2, 1.3};

Shapes::Ellipsoid e;
Expand Down
2 changes: 1 addition & 1 deletion src/shapes/unit_tests/Sphere_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void check_distance_function(Shapes::Sphere &s) {
Utils::Vector3d vec;
double dist;
// multiply by 100 because BOOST_REQUIRE_CLOSE takes a percentage tolerance
auto const tol = std::numeric_limits<double>::epsilon() * 100;
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();

s.rad() = 1.0;
pos = {0., 0., 0.};
Expand Down
5 changes: 3 additions & 2 deletions src/utils/tests/Vector_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ BOOST_AUTO_TEST_CASE(test_norm2) {
}

BOOST_AUTO_TEST_CASE(normalize) {
Utils::Vector3d v{1, 2, 3};
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
Utils::Vector3d v{1., 2., 3.};
v.normalize();

BOOST_CHECK((v.norm2() - 1.0) <= std::numeric_limits<double>::epsilon());
BOOST_CHECK_CLOSE(v.norm2(), 1.0, tol);
}

BOOST_AUTO_TEST_CASE(comparison_operators) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/tests/interpolation_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ BOOST_AUTO_TEST_CASE(sum_of_weights_odd) {
}

BOOST_AUTO_TEST_CASE(nearest_point) {
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
std::array<int, 3> nmp;
double weight;
auto save_ind = [&nmp, &weight](const std::array<int, 3> &ind, double w) {
Expand All @@ -145,7 +146,7 @@ BOOST_AUTO_TEST_CASE(nearest_point) {
bspline_3d<1>({.1, .2, .3}, save_ind, {0.5, 0.5, 0.5}, {});

BOOST_CHECK((std::array<int, 3>{{0, 0, 1}} == nmp));
BOOST_CHECK_CLOSE(weight, 1., 100. * std::numeric_limits<double>::epsilon());
BOOST_CHECK_CLOSE(weight, 1., tol);
}

BOOST_AUTO_TEST_CASE(interpolation_points_3) {
Expand Down
5 changes: 3 additions & 2 deletions src/utils/tests/matrix_vector_product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ static constexpr std::array<std::array<int, 3>, 3> matrix{
{{{1, 2, 9}}, {{8, 41, 6}}, {{31, 15, 99}}}};

BOOST_AUTO_TEST_CASE(inner_product) {
auto constexpr tol = 8. * 100. * std::numeric_limits<double>::epsilon();
const std::array<double, 3> vector{{0.5, 1.25, 3.1}};
auto const result = Utils::matrix_vector_product<double, 3, matrix>(vector);
for (int i = 0; i < 3; ++i) {
BOOST_CHECK_CLOSE(result[i], boost::inner_product(matrix[i], vector, 0.0),
100. * std::numeric_limits<double>::epsilon());
auto const ref = boost::inner_product(matrix[i], vector, 0.0);
BOOST_CHECK_CLOSE(result[i], ref, tol);
}
}
2 changes: 1 addition & 1 deletion src/utils/tests/vec_rotate_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(rotation) {
auto const is = Utils::vec_rotate(k, t, v);
auto const rel_diff = (expected - is).norm() / expected.norm();

BOOST_CHECK(rel_diff < std::numeric_limits<double>::epsilon());
BOOST_CHECK(rel_diff < 8. * std::numeric_limits<double>::epsilon());
}

BOOST_AUTO_TEST_CASE(angle_between) {
Expand Down
15 changes: 10 additions & 5 deletions testsuite/python/analyze_chains.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,20 @@ def test_observables_no_pbc(self):
core_re = self.system.analysis.calc_re(chain_start=0,
number_of_chains=num_poly,
chain_length=num_mono)
np.testing.assert_allclose(core_re, self.calc_re(num_poly, num_mono))
np.testing.assert_allclose(core_re, self.calc_re(num_poly, num_mono),
atol=1e-8)
# compare calc_rg()
core_rg = self.system.analysis.calc_rg(chain_start=0,
number_of_chains=num_poly,
chain_length=num_mono)
np.testing.assert_allclose(core_rg, self.calc_rg(num_poly, num_mono))
np.testing.assert_allclose(core_rg, self.calc_rg(num_poly, num_mono),
atol=1e-8)
# compare calc_rh()
core_rh = self.system.analysis.calc_rh(chain_start=0,
number_of_chains=num_poly,
chain_length=num_mono)
np.testing.assert_allclose(core_rh, self.calc_rh(num_poly, num_mono))
np.testing.assert_allclose(core_rh, self.calc_rh(num_poly, num_mono),
atol=1e-8)

def test_observables_lebc(self):
lin_protocol = espressomd.lees_edwards.LinearShear(
Expand Down Expand Up @@ -171,7 +174,8 @@ def test_observables_lebc(self):
core_re = self.system.analysis.calc_re(chain_start=0,
number_of_chains=num_poly,
chain_length=num_mono)
np.testing.assert_allclose(core_re, self.calc_re(num_poly, num_mono))
np.testing.assert_allclose(core_re, self.calc_re(num_poly, num_mono),
atol=1e-8)
# compare calc_rg()
core_rg = self.system.analysis.calc_rg(chain_start=0,
number_of_chains=num_poly,
Expand All @@ -182,7 +186,8 @@ def test_observables_lebc(self):
core_rh = self.system.analysis.calc_rh(chain_start=0,
number_of_chains=num_poly,
chain_length=num_mono)
np.testing.assert_allclose(core_rh, self.calc_rh(num_poly, num_mono))
np.testing.assert_allclose(core_rh, self.calc_rh(num_poly, num_mono),
atol=1e-8)

def test_exceptions(self):
num_poly = 2
Expand Down
2 changes: 1 addition & 1 deletion testsuite/python/integrator_npt_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def test_compressibility(self):
compressibility = np.var(Vs) / np.average(Vs)

self.assertAlmostEqual(avp, p_ext, delta=0.02)
self.assertAlmostEqual(compressibility, 0.32, delta=0.025)
self.assertAlmostEqual(compressibility, 0.32, delta=0.05)


if __name__ == "__main__":
Expand Down