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

Replaced numpy.testing.assert_almost_equal to numpy.testing.assert_allclose #4438

Merged
merged 20 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 2 additions & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ Chronological list of authors
- Lawson Woods
- Johannes Stöckelmaier
- Jenna M. Swarthout Goddard
2024
- Aditya Keshari

External code
-------------
Expand Down
5 changes: 5 additions & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -3336,3 +3336,8 @@ Testsuite

11/12/07 naveen
* prepared for release outside lab

24/02/23 aditya292002
* "updated tests that used assert_almost_equal(..., decimal={N}) with equivalent assert_allclose(..., rtol=0, atol=1.5e-{N}) (issue modernize testing code #3743, PR Replaced numpy.testing.assert_almost_equal to numpy.testing.assert_allclose #4438)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add information to the top of the file under 2.8.0.

  • add your handle after ??/??/?? IAlibay, HeetVekariya, marinegor, lilyminium
  • add the text under "Changes"


/workspaces/mdanalysis/package/CHANGELOG
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this line!

7 changes: 3 additions & 4 deletions testsuite/MDAnalysisTests/analysis/test_align.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from numpy.testing import (
assert_equal,
assert_array_equal,
assert_array_almost_equal,
assert_allclose,
)

Expand Down Expand Up @@ -318,7 +317,7 @@ def test_AlignTraj_custom_weights(self, universe, reference, tmpdir):
x_weights = align.AlignTraj(universe, reference,
filename=outfile, weights=weights).run()

assert_array_almost_equal(x.results.rmsd, x_weights.results.rmsd)
assert_allclose(x.results.rmsd, x_weights.results.rmsd, rtol=0, atol=1.5e-7)

def test_AlignTraj_custom_mass_weights(self, universe, reference, tmpdir):
outfile = str(tmpdir.join('align_test.dcd'))
Expand Down Expand Up @@ -393,8 +392,8 @@ def test_alignto_partial_universe(self, universe, reference):
segB_free.translate(segB_bound.centroid() - segB_free.centroid())

align.alignto(u_free, u_bound, select=selection)
assert_array_almost_equal(segB_bound.positions, segB_free.positions,
decimal=3)
assert_allclose(segB_bound.positions, segB_free.positions,
rtol=0, atol=1.5e-7)


def _get_aligned_average_positions(ref_files, ref, select="all", **kwargs):
Expand Down
9 changes: 4 additions & 5 deletions testsuite/MDAnalysisTests/analysis/test_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from numpy.testing import (
assert_equal,
assert_array_equal,
assert_array_almost_equal,
assert_allclose,
)
import numpy as np
Expand Down Expand Up @@ -305,7 +304,7 @@ def test_hard_cut_method(self, universe):
0.48543689, 0.45631068, 0.46601942, 0.47572816, 0.51456311,
0.45631068, 0.37864078, 0.42718447]
assert len(ca.results.timeseries) == len(expected)
assert_array_almost_equal(ca.results.timeseries[:, 1], expected)
assert_allclose(ca.results.timeseries[:, 1], expected, rtol=0, atol=1.5e-7)

def test_radius_cut_method(self, universe):
acidic = universe.select_atoms(self.sel_acidic)
Expand Down Expand Up @@ -365,7 +364,7 @@ def test_distance_box(self, pbc, expected):
r = contacts.Contacts(u, select=(sel_acidic, sel_basic),
refgroup=(acidic, basic), radius=6.0, pbc=pbc)
r.run()
assert_array_almost_equal(r.results.timeseries[:, 1], expected)
assert_allclose(r.results.timeseries[:, 1], expected,rtol=0, atol=1.5e-7)

def test_warn_deprecated_attr(self, universe):
"""Test for warning message emitted on using deprecated `timeseries`
Expand Down Expand Up @@ -401,7 +400,7 @@ def test_q1q2():
0.93097184, 0.93006358, 0.93188011, 0.93278837, 0.93006358,
0.92915531, 0.92824705, 0.92733878, 0.92643052, 0.93188011,
0.93006358, 0.9346049, 0.93188011]
assert_array_almost_equal(q1q2.results.timeseries[:, 1], q1_expected)
assert_allclose(q1q2.results.timeseries[:, 1], q1_expected, rtol=0, atol=1.5e-7)

q2_expected = [0.94649446, 0.94926199, 0.95295203, 0.95110701, 0.94833948,
0.95479705, 0.94926199, 0.9501845, 0.94926199, 0.95387454,
Expand All @@ -423,4 +422,4 @@ def test_q1q2():
0.97140221, 0.97601476, 0.97693727, 0.98154982, 0.98431734,
0.97601476, 0.9797048, 0.98154982, 0.98062731, 0.98431734,
0.98616236, 0.9898524, 1.]
assert_array_almost_equal(q1q2.results.timeseries[:, 2], q2_expected)
assert_allclose(q1q2.results.timeseries[:, 2], q2_expected, rtol=0, atol=1.5e-7)
8 changes: 4 additions & 4 deletions testsuite/MDAnalysisTests/analysis/test_encore.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import platform

import pytest
from numpy.testing import assert_equal, assert_almost_equal, assert_allclose
from numpy.testing import assert_equal, assert_allclose

from MDAnalysisTests.datafiles import DCD, DCD2, PSF, TPR, XTC
from MDAnalysisTests import block_import
Expand Down Expand Up @@ -412,8 +412,8 @@ def test_ces_error_estimation(self, ens1):

assert_allclose(average, expected_average, rtol=0, atol=1.5e-1,
err_msg="Unexpected average value for bootstrapped samples in Clustering Ensemble similarity")
assert_almost_equal(stdev, expected_stdev, decimal=0,
err_msg="Unexpected standard daviation for bootstrapped samples in Clustering Ensemble similarity")
assert_allclose(stdev, expected_stdev, rtol=0, atol=1.5,
err_msg="Unexpected standard deviation for bootstrapped samples in Clustering Ensemble similarity")

def test_ces_error_estimation_ensemble_bootstrap(self, ens1):
# Error estimation using a method that does not take a distance
Expand Down Expand Up @@ -822,7 +822,7 @@ def test_dimensionality_reduction_three_ensembles_two_identical(self,
encore.reduce_dimensionality([ens1, ens2, ens1])
coordinates_ens1 = coordinates[:,np.where(details["ensemble_membership"]==1)]
coordinates_ens3 = coordinates[:,np.where(details["ensemble_membership"]==3)]
assert_almost_equal(coordinates_ens1, coordinates_ens3, decimal=0,
assert_allclose(coordinates_ens1, coordinates_ens3, rtol=0, atol=1.5,
err_msg="Unexpected result in dimensionality reduction: {0}".format(coordinates))


Expand Down
Loading