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

build against NPY2 #3894

Merged
merged 30 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
75ebb33
build against NPY2
njzjz Jun 24, 2024
308e6e4
replace np.int_t with np.int64_t
njzjz Jun 25, 2024
1e5829b
replace `np.float_` with `np.float64`
njzjz Jun 25, 2024
bc1c73e
replace simps with simpson
njzjz Jun 25, 2024
862c454
replace long with np.int64_t
njzjz Jun 25, 2024
f002973
fix copy=False
njzjz Jun 25, 2024
669169a
fix simpson
njzjz Jun 25, 2024
9f4b730
asarray
njzjz Jun 25, 2024
33f0d52
RankWarning
njzjz Jun 25, 2024
a65192f
pre-commit auto-fixes
pre-commit-ci[bot] Jun 25, 2024
f171fe4
ImportError
njzjz Jun 25, 2024
a411c4b
replace np.lib.pad with np.pad
njzjz Jun 25, 2024
d1a4c80
Merge remote-tracking branch 'origin/master' into build-npy2
njzjz Aug 5, 2024
dc1d719
enable NPY201
njzjz Aug 5, 2024
b272664
skip several tests related to scipy, chgnet, and phonopy
njzjz Aug 5, 2024
c979ff8
pre-commit auto-fixes
pre-commit-ci[bot] Aug 5, 2024
2e0940c
skip more tests
njzjz Aug 5, 2024
23e62f1
make warning assertion more robust
njzjz Aug 5, 2024
dbd0289
pre-commit auto-fixes
pre-commit-ci[bot] Aug 5, 2024
88a496d
fix test_properties
njzjz Aug 6, 2024
d6b1307
pre-commit auto-fixes
pre-commit-ci[bot] Aug 6, 2024
062fd55
Revert "enable NPY201"
njzjz Aug 6, 2024
16f3cf4
rename vars for readability
janosh Aug 6, 2024
3c4695e
fix test_get_parchg with comment to explain assert inversion
janosh Aug 6, 2024
f0865f0
don't depend on numpy RC in build-system.requires
janosh Aug 6, 2024
17b325f
disable assert altogether
janosh Aug 6, 2024
1dfc9e4
bump optional dep pin abinit = ["netcdf4>=1.7.1"]
janosh Aug 8, 2024
33d521c
Merge branch 'master' into build-npy2
njzjz Aug 8, 2024
9daedbb
merge
njzjz Aug 8, 2024
ddef216
remove delvewheel
njzjz Aug 8, 2024
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
12 changes: 7 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
[build-system]
requires = [
"Cython>=0.29.23",
# pin NumPy version used in the build
"oldest-supported-numpy",
# Building against NPY2 will support both NPY1 and NPY2
# https://numpy.org/devdocs/dev/depending_on_numpy.html#build-time-dependency
"numpy>=2.0.1",
"setuptools>=65.0.0",
]
build-backend = "setuptools.build_meta"
Expand Down Expand Up @@ -59,8 +60,8 @@ dependencies = [
"matplotlib>=3.8",
"monty>=2024.7.29",
"networkx>=2.2",
"numpy>=1.25.0 ; platform_system != 'Windows'",
"numpy>=1.25.0,<2.0 ; platform_system == 'Windows'",
# NumPy documentation suggests pinning the current major version as the C API is used
# https://numpy.org/devdocs/dev/depending_on_numpy.html#runtime-dependency-version-ranges
"palettable>=3.3.3",
"pandas>=2",
"plotly>=4.5.0",
Expand All @@ -73,6 +74,7 @@ dependencies = [
"tabulate>=0.9",
"tqdm>=4.60",
"uncertainties>=3.1.4",
'numpy>=1.25.0,<3.0',
]
version = "2024.7.18"

Expand All @@ -88,7 +90,7 @@ ase = ["ase>=3.23.0"]
# don't depend on tblite above 3.11 since unsupported https://github.com/tblite/tblite/issues/175
tblite = ["tblite[ase]>=0.3.0; python_version<'3.12'"]
vis = ["vtk>=6.0.0"]
abinit = ["netcdf4>=1.6.5"]
abinit = ["netcdf4>=1.7.1"]
mlp = ["chgnet>=0.3.8", "matgl>=1.1.1"]
electronic_structure = ["fdint>=2.0.2"]
ci = ["pytest-cov>=4", "pytest-split>=0.8", "pytest>=8"]
Expand Down
9 changes: 7 additions & 2 deletions src/pymatgen/analysis/eos.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
import numpy as np
from scipy.optimize import leastsq, minimize

try:
from numpy.exceptions import RankWarning # NPY2
except ImportError:
from numpy import RankWarning # NPY1

from pymatgen.core.units import FloatWithUnit
from pymatgen.util.plotting import add_fig_kwargs, get_ax_fig, pretty_plot

Expand Down Expand Up @@ -420,7 +425,7 @@ def fit(self, min_ndata_factor=3, max_poly_order_factor=5, min_poly_order=2):
min_poly_order (int): minimum order of the polynomial to be
considered for fitting.
"""
warnings.simplefilter("ignore", np.RankWarning)
warnings.simplefilter("ignore", RankWarning)

def get_rms(x, y):
return np.sqrt(np.sum((np.array(x) - np.array(y)) ** 2) / len(x))
Expand Down Expand Up @@ -490,7 +495,7 @@ def get_rms(x, y):
norm += weight
coeffs = np.array(val[0])
# pad the coefficient array with zeros
coeffs = np.lib.pad(coeffs, (0, max(fit_poly_order - len(coeffs), 0)), "constant")
coeffs = np.pad(coeffs, (0, max(fit_poly_order - len(coeffs), 0)), "constant")
weighted_avg_coeffs += weight * coeffs

# normalization
Expand Down
13 changes: 7 additions & 6 deletions src/pymatgen/optimization/linear_assignment.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ class LinearAssignment:
"""

def __init__(self, costs, epsilon=1e-13):
self.orig_c = np.array(costs, dtype=np.float_, copy=False, order="C")
# https://numpy.org/devdocs/numpy_2_0_migration_guide.html#adapting-to-changes-in-the-copy-keyword
Copy link
Contributor

Choose a reason for hiding this comment

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

@janosh This doesn't look like something we should keep inside the code (it's pretty easy to find)? What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

i'm generally in favor of linking relevant docs. even if easy to find, people might not think to look for them. but no strong opinion in this case

Copy link
Contributor

Choose a reason for hiding this comment

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

This one looks more like a "disposable" migration guide which we would only do once :)

self.orig_c = np.asarray(costs, dtype=np.float64, order="C")
self.nx, self.ny = self.orig_c.shape
self.n = self.ny

Expand All @@ -63,7 +64,7 @@ class LinearAssignment:
if self.nx == self.ny:
self.c = self.orig_c
else:
self.c = np.zeros((self.n, self.n), dtype=np.float_)
self.c = np.zeros((self.n, self.n), dtype=np.float64)
self.c[:self.nx] = self.orig_c

# initialize solution vectors
Expand All @@ -76,15 +77,15 @@ class LinearAssignment:

@cython.boundscheck(False)
@cython.wraparound(False)
cdef np.float_t compute(int size, np.float_t[:, :] c, np.int_t[:] x, np.int_t[:] y, np.float_t eps) nogil:
cdef np.float_t compute(int size, np.float_t[:, :] c, np.int64_t[:] x, np.int64_t[:] y, np.float_t eps) nogil:

# augment
cdef int i, j, k, i1, j1, f, f0, cnt, low, up, z, last, nrr
cdef int n = size
cdef bint b
cdef np.int_t * col = <np.int_t *> malloc(n * sizeof(np.int_t))
cdef np.int_t * fre = <np.int_t *> malloc(n * sizeof(np.int_t))
cdef np.int_t * pred = <np.int_t *> malloc(n * sizeof(np.int_t))
cdef np.int64_t * col = <np.int64_t *> malloc(n * sizeof(np.int64_t))
cdef np.int64_t * fre = <np.int64_t *> malloc(n * sizeof(np.int64_t))
cdef np.int64_t * pred = <np.int64_t *> malloc(n * sizeof(np.int64_t))
cdef np.float_t * v = <np.float_t *> malloc(n * sizeof(np.float_t))
cdef np.float_t * d = <np.float_t *> malloc(n * sizeof(np.float_t))
cdef np.float_t h, m, u1, u2, cost
Expand Down
Loading