Skip to content

Commit

Permalink
Fix nightly NumPy cron job, add numpy 1.25-dev0 fixes (#3977)
Browse files Browse the repository at this point in the history
* Fix cron jobs against nightly wheels
* Address incompatibilities with NumPy 1.25 changes in streamlines and streamlines_3d
  • Loading branch information
IAlibay committed Jan 4, 2023
1 parent b732e98 commit 75b0337
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ omit =
*/legacy/*
*/due.py
concurrency = thread, multiprocessing
parallel = True
parallel = true

[report]
exclude_lines =
Expand Down
32 changes: 19 additions & 13 deletions .github/workflows/gh-ci-cron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,32 @@ jobs:
- name: setup_miniconda
uses: conda-incubator/setup-miniconda@v2
with:
python-version: 3.9
auto-update-conda: true
channel-priority: flexible
python-version: "3.10"
miniforge-variant: Mambaforge
miniforge-version: latest
channel-priority: strict
channels: conda-forge, bioconda
mamba-version: "*"
add-pip-as-python-dependency: true
architecture: x64

- name: install_dev_versions
run: |
pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy
- name: install_other_deps
- name: install_deps
uses: ./.github/actions/setup-deps
with:
mamba: true
numpy: ""
scipy: ""
full-deps: true

# overwrite installs by picking up nightly wheels
- name: nightly_wheels
run: |
pip install --pre -U -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy numpy h5py matplotlib
- name: list_deps
run: |
mamba list
pip list
# Intentionally going with setup.py builds so we can build with latest
- name: build_srcs
uses: ./.github/actions/build-src
with:
Expand All @@ -64,7 +70,7 @@ jobs:

- name: run_tests
run: |
pytest -n $numprocs testsuite/MDAnalysisTests --disable-pytest-warnings --durations=50
pytest -n $numprocs testsuite/MDAnalysisTests --durations=50 -W error::FutureWarning
# Issue #3442
Expand Down
5 changes: 4 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
12/21/22 IAlibay
01/04/23 IAlibay

* 2.4.2

Fixes
* np.histogramdd calls in :class:`DensityAnalysis` now pass the `density`
argument rather than the NumPy 1.24 removed `normed` (PR #3976)
* visualization.streamlines_3D and visualization.streamlines no longer
rely on the scalar return of an numpy array elementwise comparison which
is no longer supported as of NumPy 1.25 (PR #3977)


12/17/22 IAlibay
Expand Down
4 changes: 2 additions & 2 deletions package/MDAnalysis/visualization/streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def produce_list_centroids_this_frame(list_indices_in_polygon):
list_centroids_this_frame = []
for indices in list_indices_in_polygon:
if not indices[0].size > 0: # if there are no particles of interest in this particular square
list_centroids_this_frame.append('empty')
list_centroids_this_frame.append(None)
else:
current_coordinate_array_in_square = relevant_particle_coordinate_array_xy[indices]
current_square_indices_centroid = np.average(current_coordinate_array_in_square, axis=0)
Expand All @@ -201,7 +201,7 @@ def produce_list_centroids_this_frame(list_indices_in_polygon):
xy_deltas_to_write = []
for square_1_centroid, square_2_centroid in zip(list_centroids_this_frame_using_indices_from_last_frame,
list_previous_frame_centroids):
if square_1_centroid == 'empty' or square_2_centroid == 'empty':
if square_1_centroid is None or square_2_centroid is None:
xy_deltas_to_write.append([0, 0])
else:
xy_deltas_to_write.append(np.subtract(square_1_centroid, square_2_centroid).tolist())
Expand Down
8 changes: 5 additions & 3 deletions package/MDAnalysis/visualization/streamlines_3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@

import MDAnalysis

def determine_container_limits(topology_file_path, trajectory_file_path, buffer_value):

def determine_container_limits(topology_file_path, trajectory_file_path,
buffer_value):
"""Calculate the extent of the atom coordinates + buffer.
A function for the parent process which should take the input trajectory
Expand Down Expand Up @@ -281,15 +283,15 @@ def update_dictionary_point_in_cube_start_frame(array_simulation_particle_coordi
axis=0)
cube['centroid_of_particles_first_frame'] = centroid_particles_in_cube
else: # empty cube
cube['centroid_of_particles_first_frame'] = 'empty'
cube['centroid_of_particles_first_frame'] = None
cube_counter += 1

def update_dictionary_end_frame(array_simulation_particle_coordinates, dictionary_cube_data_this_core):
"""Update the cube dictionary objects again as appropriate for the second and final frame."""
cube_counter = 0
for key, cube in dictionary_cube_data_this_core.items():
# if there were no particles in the cube in the first frame, then set dx,dy,dz each to 0
if cube['centroid_of_particles_first_frame'] == 'empty':
if cube['centroid_of_particles_first_frame'] is None:
cube['dx'] = 0
cube['dy'] = 0
cube['dz'] = 0
Expand Down
24 changes: 24 additions & 0 deletions testsuite/MDAnalysisTests/visualization/test_streamlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
#
import numpy as np
from numpy.testing import assert_allclose
import MDAnalysis
from MDAnalysis.visualization import (streamlines,
streamlines_3D)
Expand Down Expand Up @@ -83,6 +84,29 @@ def test_streamplot_2D(membrane_xtc, univ, tmpdir):
with open(plot_outpath, 'rb'):
pass


def test_streamplot_2D_zero_return(membrane_xtc, univ, tmpdir):
# simple roundtrip test to ensure that
# zeroed arrays are returned by the 2D streamplot
# code when called with an empty selection
u1, v1, avg, std = streamlines.generate_streamlines(topology_file_path=Martini_membrane_gro,
trajectory_file_path=membrane_xtc,
grid_spacing=20,
MDA_selection='name POX',
start_frame=1,
end_frame=2,
xmin=univ.atoms.positions[...,0].min(),
xmax=univ.atoms.positions[...,0].max(),
ymin=univ.atoms.positions[...,1].min(),
ymax=univ.atoms.positions[...,1].max(),
maximum_delta_magnitude=2.0,
num_cores=1)
assert_allclose(u1, np.zeros((5, 5)))
assert_allclose(v1, np.zeros((5, 5)))
assert avg == approx(0.0)
assert std == approx(0.0)


def test_streamplot_3D(membrane_xtc, univ, tmpdir):
# because mayavi is too heavy of a dependency
# for a roundtrip plotting test, simply
Expand Down

0 comments on commit 75b0337

Please sign in to comment.