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

distopia 0.3.0 compatibility changes #4734

Open
wants to merge 35 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2ee12e5
start of docs
hmacdope Oct 15, 2024
9bf0cf7
improve distopia stup
hmacdope Oct 15, 2024
f8d1295
add backend conditionals
hmacdope Oct 15, 2024
badc778
fix wrong backend
hmacdope Oct 15, 2024
e97317b
shims
hmacdope Oct 15, 2024
e0ce653
working except for dihedrals
hmacdope Oct 15, 2024
63162df
move to 0.3.0
hmacdope Oct 16, 2024
0ec2057
bump ci
hmacdope Oct 16, 2024
2392101
bump ci
hmacdope Oct 17, 2024
2cb04d2
Update package/MDAnalysis/lib/distances.py
hmacdope Oct 21, 2024
e4b8a10
Merge remote-tracking branch 'upstream/develop' into distopia_0.3.0_c…
hmacdope Oct 21, 2024
517c676
fix versioning
hmacdope Oct 21, 2024
36de301
add version checking
hmacdope Oct 21, 2024
b49b028
remove erroneous triclinic note
hmacdope Oct 21, 2024
d895d99
remove unnesecary import
hmacdope Oct 21, 2024
5733a74
add explanatory notes
hmacdope Oct 21, 2024
36c010a
change tests in line with discussion
hmacdope Oct 21, 2024
763b493
changelog
hmacdope Oct 21, 2024
10356f7
Apply suggestions from code review
hmacdope Oct 23, 2024
3b0024a
add more tests
hmacdope Oct 23, 2024
9c149ec
improve docs
hmacdope Oct 23, 2024
8cae6f8
improve docs again
hmacdope Oct 23, 2024
50efeb9
hmmm
hmacdope Oct 24, 2024
2c070b7
Merge branch 'develop' into distopia_0.3.0_compat
orbeckst Dec 10, 2024
d4b9e9d
add type for calc_bond_distance_ortho()
orbeckst Dec 10, 2024
2621552
just stuff answers back in if we used a buffer
hmacdope Dec 31, 2024
154d389
Merge branch 'distopia_0.3.0_compat' of github.com:hmacdope/mdanalysi…
hmacdope Dec 31, 2024
c75dce2
add cram for distance array also
hmacdope Dec 31, 2024
02a3d93
fix changelogs
hmacdope Dec 31, 2024
07f1438
Merge remote-tracking branch 'upstream/develop' into distopia_0.3.0_c…
hmacdope Jan 2, 2025
9101d81
black
hmacdope Jan 2, 2025
447beac
imporve mock test
hmacdope Jan 2, 2025
0a60016
fix typo
hmacdope Jan 2, 2025
730cee9
add debug printing
hmacdope Jan 2, 2025
a865a46
Merge branch 'develop' into distopia_0.3.0_compat
orbeckst Jan 6, 2025
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: 1 addition & 1 deletion .github/actions/setup-deps/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ inputs:
dask:
default: 'dask'
distopia:
default: 'distopia>=0.2.0'
default: 'distopia>=0.3.0'
h5py:
default: 'h5py>=2.10'
hole2:
Expand Down
79 changes: 69 additions & 10 deletions package/MDAnalysis/lib/_distopia.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,15 @@
else:
HAS_DISTOPIA = True

from .c_distances import (
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
calc_bond_distance_triclinic as _calc_bond_distance_triclinic_serial,
)

import warnings
import numpy as np


def calc_bond_distance_ortho(
coords1, coords2: np.ndarray, box: np.ndarray, results: np.ndarray
orbeckst marked this conversation as resolved.
Show resolved Hide resolved
) -> None:
distopia.calc_bonds_ortho_float(
distopia.calc_bonds_ortho(

Check warning on line 47 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L47

Added line #L47 was not covered by tests
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords1, coords2, box[:3], results=results
)
# upcast is currently required, change for 3.0, see #3927
Expand All @@ -55,7 +53,7 @@
def calc_bond_distance(
coords1: np.ndarray, coords2: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_bonds_no_box_float(
distopia.calc_bonds_no_box(

Check warning on line 56 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L56

Added line #L56 was not covered by tests
coords1, coords2, results=results
)
# upcast is currently required, change for 3.0, see #3927
Expand All @@ -64,8 +62,69 @@
def calc_bond_distance_triclinic(
coords1: np.ndarray, coords2: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
# redirect to serial backend
warnings.warn(
"distopia does not support triclinic boxes, using serial backend instead."
)
_calc_bond_distance_triclinic_serial(coords1, coords2, box, results)
distopia.calc_bonds_triclinic(coords1, coords2, box, results=results)

Check warning on line 65 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L65

Added line #L65 was not covered by tests


def calc_angle(
Copy link
Member

Choose a reason for hiding this comment

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

Has @RMeli lint lib? If so, could you run black on this file @hmacdope ?

coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_angles_no_box(coords1, coords2, coords3, results=results)

Check warning on line 71 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L71

Added line #L71 was not covered by tests

def calc_angle_ortho(
coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_angles_ortho(coords1, coords2, coords3, box[:3], results=results)

Check warning on line 76 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L76

Added line #L76 was not covered by tests


def calc_angle_triclinic(
coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:

distopia.calc_angles_triclinic(coords1, coords2, coords3, box, results=results)

Check warning on line 83 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L83

Added line #L83 was not covered by tests


def calc_dihedral(
coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, coords4: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_dihedrals_no_box(coords1, coords2, coords3, coords4, results=results)

Check warning on line 89 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L89

Added line #L89 was not covered by tests

def calc_dihedral_ortho(
coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, coords4: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_dihedrals_ortho(coords1, coords2, coords3, coords4, box[:3], results=results)

Check warning on line 94 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L94

Added line #L94 was not covered by tests

def calc_dihedral_triclinic(
coords1: np.ndarray, coords2: np.ndarray, coords3: np.ndarray, coords4: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_dihedrals_triclinic(coords1, coords2, coords3, coords4, box, results=results)

Check warning on line 99 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L99

Added line #L99 was not covered by tests

def calc_distance_array(
coords1: np.ndarray, coords2: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_distance_array_no_box(coords1, coords2, results=results)

Check warning on line 104 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L104

Added line #L104 was not covered by tests

def calc_distance_array_ortho(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords1: np.ndarray, coords2: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_distance_array_ortho(coords1, coords2, box[:3], results=results)

Check warning on line 109 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L109

Added line #L109 was not covered by tests

def calc_distance_array_triclinic(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords1: np.ndarray, coords2: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_distance_array_triclinic(coords1, coords2, box, results=results)

Check warning on line 114 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L114

Added line #L114 was not covered by tests
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

def calc_self_distance_array(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_self_distance_array_no_box(coords, results=results)

Check warning on line 119 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L119

Added line #L119 was not covered by tests
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

def calc_self_distance_array_ortho(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_self_distance_array_ortho(coords, box[:3], results=results)

Check warning on line 124 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L124

Added line #L124 was not covered by tests

def calc_self_distance_array_triclinic(
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
coords: np.ndarray, box: np.ndarray, results: np.ndarray
) -> None:
distopia.calc_self_distance_array_triclinic(coords, box, results=results)

Check warning on line 129 in package/MDAnalysis/lib/_distopia.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/_distopia.py#L129

Added line #L129 was not covered by tests

56 changes: 43 additions & 13 deletions package/MDAnalysis/lib/distances.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,22 @@
you wish to use is covered by distopia. For more information see the
`distopia documentation`_.

.. Table:: Functions available using the `distopia`_ backend.
:align: center

+-------------------------------------+-----------------------------------+
| Functions | Notes |
+=====================================+===================================+
| MDAnalysis.lib.distances.calc_bonds | Doesn't support triclinic boxes |
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
+-------------------------------------+-----------------------------------+
.. table:: Functions available using the `distopia`_ backend.
:align: center

+-----------------------------------------------+
| Functions |
+===============================================+
| MDAnalysis.lib.distances.calc_bonds |
+-----------------------------------------------+
| MDAnalysis.lib.distances.calc_angles |
+-----------------------------------------------+
| MDAnalysis.lib.distances.calc_dihedrals |
+-----------------------------------------------+
| MDAnalysis.lib.distances.distance_array |
+-----------------------------------------------+
| MDAnalysis.lib.distances.self_distance_array |
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
+-----------------------------------------------+

If `distopia`_ is installed, the functions in this table will accept the key
'distopia' for the `backend` keyword argument. If the distopia backend is
Expand All @@ -83,7 +91,7 @@

.. Note::
Due to the use of Instruction Set Architecture (`ISA`_) specific SIMD
intrinsics in distopia via `VCL2`_, the precision of your results may
intrinsics in distopia via `HWY`_, the precision of your results may
depend on the ISA available on your machine. However, in all tested cases
distopia satisfied the accuracy thresholds used to the functions in this
module. Please document any issues you encounter with distopia's accuracy
Expand All @@ -92,7 +100,7 @@
.. _distopia: https://github.com/MDAnalysis/distopia
.. _distopia documentation: https://www.mdanalysis.org/distopia
.. _ISA: https://en.wikipedia.org/wiki/Instruction_set_architecture
.. _VCL2: https://github.com/vectorclass/version2
.. _HWY: https://github.com/google/highway
.. _relevant distopia issue: https://github.com/MDAnalysis/mdanalysis/issues/3915

.. versionadded:: 0.13.0
Expand All @@ -101,6 +109,8 @@
:class:`~MDAnalysis.core.groups.AtomGroup` or an :class:`np.ndarray`
.. versionchanged:: 2.5.0
Interface to the `distopia`_ package added.
.. versionchanged:: 2.7.0
hmacdope marked this conversation as resolved.
Show resolved Hide resolved
Distopia support greatly expanded.
hmacdope marked this conversation as resolved.
Show resolved Hide resolved

Functions
---------
Expand Down Expand Up @@ -303,6 +313,11 @@
distances = _check_result_array(result, (refnum, confnum))
if len(distances) == 0:
return distances

hmacdope marked this conversation as resolved.
Show resolved Hide resolved
if backend == 'distopia':
distances = distances.astype(np.float32)
box = np.asarray(box).astype(np.float32) if box is not None else None

Check warning on line 319 in package/MDAnalysis/lib/distances.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/distances.py#L318-L319

Added lines #L318 - L319 were not covered by tests

if box is not None:
boxtype, box = check_box(box)
if boxtype == 'ortho':
Expand All @@ -318,6 +333,9 @@
args=(reference, configuration, distances),
backend=backend)

if backend == 'distopia':
Copy link
Member

Choose a reason for hiding this comment

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

Not for this PR, but you do this pattern enough that I wonder if life might be easier if you moved this into a decorator (or even just straight up into check_coords?

distances = distances.astype(np.float64)

Check warning on line 337 in package/MDAnalysis/lib/distances.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/distances.py#L337

Added line #L337 was not covered by tests

return distances


Expand Down Expand Up @@ -1484,13 +1502,14 @@
"""
numatom = coords1.shape[0]
bondlengths = _check_result_array(result, (numatom,))
if backend == 'distopia':
bondlengths = bondlengths.astype(np.float32)
box = np.asarray(box).astype(np.float32) if box is not None else None

Check warning on line 1507 in package/MDAnalysis/lib/distances.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/distances.py#L1506-L1507

Added lines #L1506 - L1507 were not covered by tests

if numatom > 0:
if box is not None:
boxtype, box = check_box(box)
if boxtype == "ortho":
if backend == 'distopia':
bondlengths = bondlengths.astype(np.float32)
_run(
"calc_bond_distance_ortho",
args=(coords1, coords2, box, bondlengths),
Expand Down Expand Up @@ -1598,6 +1617,10 @@
numatom = coords1.shape[0]
angles = _check_result_array(result, (numatom,))

if backend == 'distopia':
angles = angles.astype(np.float32)
box = np.asarray(box).astype(np.float32) if box is not None else None

Check warning on line 1622 in package/MDAnalysis/lib/distances.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/distances.py#L1621-L1622

Added lines #L1621 - L1622 were not covered by tests

if numatom > 0:
if box is not None:
boxtype, box = check_box(box)
Expand All @@ -1614,6 +1637,8 @@
args=(coords1, coords2, coords3, angles),
backend=backend)

if backend == 'distopia':
angles = angles.astype(np.float64)

Check warning on line 1641 in package/MDAnalysis/lib/distances.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/distances.py#L1641

Added line #L1641 was not covered by tests
return angles


Expand Down Expand Up @@ -1716,6 +1741,10 @@
numatom = coords1.shape[0]
dihedrals = _check_result_array(result, (numatom,))

if backend == 'distopia':
dihedrals = dihedrals.astype(np.float32)
box = np.asarray(box).astype(np.float32) if box is not None else None

Check warning on line 1746 in package/MDAnalysis/lib/distances.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/distances.py#L1745-L1746

Added lines #L1745 - L1746 were not covered by tests

if numatom > 0:
if box is not None:
boxtype, box = check_box(box)
Expand All @@ -1731,7 +1760,8 @@
_run("calc_dihedral",
args=(coords1, coords2, coords3, coords4, dihedrals),
backend=backend)

if backend == 'distopia':
dihedrals = dihedrals.astype(np.float64)

Check warning on line 1764 in package/MDAnalysis/lib/distances.py

View check run for this annotation

Codecov / codecov/patch

package/MDAnalysis/lib/distances.py#L1764

Added line #L1764 was not covered by tests
return dihedrals


Expand Down
Loading
Loading