Skip to content

Commit 8d43073

Browse files
authored
Fix nightly NumPy cron job, add numpy 1.25-dev0 fixes (#3977)
* Fix cron jobs against nightly wheels * Address incompatibilities with NumPy 1.25 changes in streamlines and streamlines_3d
1 parent d67b4f1 commit 8d43073

File tree

6 files changed

+55
-20
lines changed

6 files changed

+55
-20
lines changed

.coveragerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ omit =
77
*/legacy/*
88
*/due.py
99
concurrency = thread, multiprocessing
10-
parallel = True
10+
parallel = true
1111

1212
[report]
1313
exclude_lines =

.github/workflows/gh-ci-cron.yaml

+19-13
Original file line numberDiff line numberDiff line change
@@ -35,26 +35,32 @@ jobs:
3535
- name: setup_miniconda
3636
uses: conda-incubator/setup-miniconda@v2
3737
with:
38-
python-version: 3.9
39-
auto-update-conda: true
40-
channel-priority: flexible
38+
python-version: "3.10"
39+
miniforge-variant: Mambaforge
40+
miniforge-version: latest
41+
channel-priority: strict
4142
channels: conda-forge, bioconda
42-
mamba-version: "*"
4343
add-pip-as-python-dependency: true
4444
architecture: x64
4545

46-
- name: install_dev_versions
47-
run: |
48-
pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple numpy
49-
pip install -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy
50-
51-
- name: install_other_deps
46+
- name: install_deps
5247
uses: ./.github/actions/setup-deps
5348
with:
5449
mamba: true
55-
numpy: ""
56-
scipy: ""
50+
full-deps: true
5751

52+
# overwrite installs by picking up nightly wheels
53+
- name: nightly_wheels
54+
run: |
55+
pip install --pre -U -i https://pypi.anaconda.org/scipy-wheels-nightly/simple scipy numpy h5py matplotlib
56+
57+
58+
- name: list_deps
59+
run: |
60+
mamba list
61+
pip list
62+
63+
# Intentionally going with setup.py builds so we can build with latest
5864
- name: build_srcs
5965
uses: ./.github/actions/build-src
6066
with:
@@ -64,7 +70,7 @@ jobs:
6470

6571
- name: run_tests
6672
run: |
67-
pytest -n $numprocs testsuite/MDAnalysisTests --disable-pytest-warnings --durations=50
73+
pytest -n $numprocs testsuite/MDAnalysisTests --durations=50 -W error::FutureWarning
6874
6975
7076
# Issue #3442

package/CHANGELOG

+4-1
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ Changes
2929
Deprecations
3030

3131

32-
12/21/22 IAlibay
32+
01/04/23 IAlibay
3333

3434
* 2.4.2
3535

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

4043

4144
12/17/22 IAlibay

package/MDAnalysis/visualization/streamlines.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def produce_list_centroids_this_frame(list_indices_in_polygon):
176176
list_centroids_this_frame = []
177177
for indices in list_indices_in_polygon:
178178
if not indices[0].size > 0: # if there are no particles of interest in this particular square
179-
list_centroids_this_frame.append('empty')
179+
list_centroids_this_frame.append(None)
180180
else:
181181
current_coordinate_array_in_square = relevant_particle_coordinate_array_xy[indices]
182182
current_square_indices_centroid = np.average(current_coordinate_array_in_square, axis=0)
@@ -201,7 +201,7 @@ def produce_list_centroids_this_frame(list_indices_in_polygon):
201201
xy_deltas_to_write = []
202202
for square_1_centroid, square_2_centroid in zip(list_centroids_this_frame_using_indices_from_last_frame,
203203
list_previous_frame_centroids):
204-
if square_1_centroid == 'empty' or square_2_centroid == 'empty':
204+
if square_1_centroid is None or square_2_centroid is None:
205205
xy_deltas_to_write.append([0, 0])
206206
else:
207207
xy_deltas_to_write.append(np.subtract(square_1_centroid, square_2_centroid).tolist())

package/MDAnalysis/visualization/streamlines_3D.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@
6161

6262
import MDAnalysis
6363

64-
def determine_container_limits(topology_file_path, trajectory_file_path, buffer_value):
64+
65+
def determine_container_limits(topology_file_path, trajectory_file_path,
66+
buffer_value):
6567
"""Calculate the extent of the atom coordinates + buffer.
6668
6769
A function for the parent process which should take the input trajectory
@@ -281,15 +283,15 @@ def update_dictionary_point_in_cube_start_frame(array_simulation_particle_coordi
281283
axis=0)
282284
cube['centroid_of_particles_first_frame'] = centroid_particles_in_cube
283285
else: # empty cube
284-
cube['centroid_of_particles_first_frame'] = 'empty'
286+
cube['centroid_of_particles_first_frame'] = None
285287
cube_counter += 1
286288

287289
def update_dictionary_end_frame(array_simulation_particle_coordinates, dictionary_cube_data_this_core):
288290
"""Update the cube dictionary objects again as appropriate for the second and final frame."""
289291
cube_counter = 0
290292
for key, cube in dictionary_cube_data_this_core.items():
291293
# if there were no particles in the cube in the first frame, then set dx,dy,dz each to 0
292-
if cube['centroid_of_particles_first_frame'] == 'empty':
294+
if cube['centroid_of_particles_first_frame'] is None:
293295
cube['dx'] = 0
294296
cube['dy'] = 0
295297
cube['dz'] = 0

testsuite/MDAnalysisTests/visualization/test_streamlines.py

+24
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
2222
#
2323
import numpy as np
24+
from numpy.testing import assert_allclose
2425
import MDAnalysis
2526
from MDAnalysis.visualization import (streamlines,
2627
streamlines_3D)
@@ -83,6 +84,29 @@ def test_streamplot_2D(membrane_xtc, univ, tmpdir):
8384
with open(plot_outpath, 'rb'):
8485
pass
8586

87+
88+
def test_streamplot_2D_zero_return(membrane_xtc, univ, tmpdir):
89+
# simple roundtrip test to ensure that
90+
# zeroed arrays are returned by the 2D streamplot
91+
# code when called with an empty selection
92+
u1, v1, avg, std = streamlines.generate_streamlines(topology_file_path=Martini_membrane_gro,
93+
trajectory_file_path=membrane_xtc,
94+
grid_spacing=20,
95+
MDA_selection='name POX',
96+
start_frame=1,
97+
end_frame=2,
98+
xmin=univ.atoms.positions[...,0].min(),
99+
xmax=univ.atoms.positions[...,0].max(),
100+
ymin=univ.atoms.positions[...,1].min(),
101+
ymax=univ.atoms.positions[...,1].max(),
102+
maximum_delta_magnitude=2.0,
103+
num_cores=1)
104+
assert_allclose(u1, np.zeros((5, 5)))
105+
assert_allclose(v1, np.zeros((5, 5)))
106+
assert avg == approx(0.0)
107+
assert std == approx(0.0)
108+
109+
86110
def test_streamplot_3D(membrane_xtc, univ, tmpdir):
87111
# because mayavi is too heavy of a dependency
88112
# for a roundtrip plotting test, simply

0 commit comments

Comments
 (0)