Support numpy >= 2.4 and relax the numpy requirement to <3 - #101
Merged
Conversation
Two changes are needed to work with numpy 2.4, both backward compatible down to numpy 1.x: 1. PyACECalculator/PyACEEnsembleCalculator filled the ASE results dict via np.float64(energy.reshape(-1,)). numpy 2.4 expired the 'conversion of ndim > 0 arrays to scalars' deprecation (present since numpy 1.25), so the scalar constructor now returns a shape-(1,) array instead of collapsing it to a scalar, and atoms.get_potential_energy() leaked a 1-element array of the total energy. Scalar results now go through float(), which behaves identically on every numpy version, and per-atom arrays through astype(np.float64), which also keeps energies_dev/forces_dev arrays for single-atom structures on older numpy. 2. pyace.radial used np.trapz, which numpy 2.0 kept only as a deprecated alias of np.trapezoid and numpy 2.4 removed. The module now picks whichever of the two exists. A regression assertion in tests/test_PyACECalculator.py guards the scalar energy output. Verified by building the package and running tests/test_PyACECalculator.py against numpy 1.26.4, 2.3.5 and 2.4.6. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015Ui6Drmop9gZXo1fgn8yVg
3 tasks
Bring in the CI fixes that landed after this branch was cut, so the pipeline can run at all. Both jobs on this PR failed in "Test with python-ace with tensorpotential" for reasons unrelated to this branch: collection aborted on a missing maxvolpy, so no test ran. Master fixed that in 3bfa4df (install lib/maxvolpy explicitly, since `pip install .` builds a wheel and never runs setup.py's InstallMaxVolPyLocalPackage hook) and d63466f (UnitCellFilter moved to ase.filters). Merge is clean. Both sides touch tests/test_PyACECalculator.py in different tests - the scalar-energy assertion in test_setup here, UnitCellFilter in test_relaxation from master - and both survived. Independently verified this branch's premises against numpy 1.26.4, 2.3.5, 2.4.6 and 2.5.2: * np.float64(energy.reshape(-1,)) returns a float64 scalar (with a DeprecationWarning) up to 2.3.5 but a shape-(1,) ndarray from 2.4.6 on, so get_potential_energy() did leak an array, as described. * ACECalculator::energy is `DOUBLE_TYPE energy`, a plain double, so np.array() of it is 0-d and float() on it is exact and unwarned on all four versions. * Dropping the .reshape(-1,) is load-bearing, not cosmetic: float() on a shape-(1,) array still warns up to 2.3.5 and raises TypeError("only 0-dimensional arrays can be converted to Python scalars") from 2.4.6 on. Keeping the reshape would have crashed. * np.trapz is present up to 2.3.5 and gone from 2.4.6; np.trapezoid covers 2.x. The shim picks correctly on each. * np.float64(energies_dev) collapsed a 1-atom array to a scalar on older numpy, so .astype(np.float64) is the more consistent fix, as the PR argues. For the 4-atom structure in test_calculator.py both spellings give shape (4,), so that assertion is unaffected. Caveat worth recording: a green run here does NOT exercise numpy 2.x. TensorPotential pins numpy<=1.26.4 and is installed first, and pip does not upgrade an already-satisfied requirement, so both jobs still resolve numpy 1.26.4 whether the pin here reads <=1.26.4 or <3. CI can only show this change does not regress numpy 1.26.4; the 2.4 support it claims rests on local verification. Testing that in CI needs TensorPotential's own cap raised first. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
srmnitc
added a commit
to pmrv/python-ace
that referenced
this pull request
Sep 4, 2026
Bring in master and drop this branch's now-redundant copies of the two CI fixes, leaving the pandas bound as its only net change. This branch (15 Jul) found both CI problems before ICAMS#104 did and carried its own fixes for them, so master and this branch fixed the same two things independently and both files conflicted: * .github/workflows/test.yml - both add an "Install maxvolpy" step. Resolved to master's: it installs `Cython scipy` rather than only `cython`, and spells out why --no-build-isolation is needed. * tests/test_PyACECalculator.py - both wrap the UnitCellFilter import. Identical logic, only comment placement differed; resolved to master's. Both files are now byte-identical to master, so the net diff against master is the single setup.py line this PR is actually about. Verified the pandas audit rather than assuming it: * No use of APIs dropped in pandas 2/3 - no applymap, iteritems, delim_whitespace, .ix, get_values or lookup anywhere. Every `.append(` hit is a plain list; preparedata.py:706 appends to a list and then calls pd.concat, which is the modern pattern. * The `>=2` floor holds. paralleldataexecutor.py:68 looked like a DataFrame.map (pandas 2.1+) risk given the `batch_df` name, but the call is guarded by `isinstance(batch_df, pd.Series)` and DataFrames take the `.apply(..., axis=1)` branch, so nothing needs 2.1. * No chained assignment on DataFrames; writes go through df[col] = or df.loc[mask, col] =. The inplace=True calls that do exist (drop, dropna, reset_index) are on owned frames, not slices. * All 12 pickled frames in the repo load under pandas 3.0.5 / numpy 2.5.2, not just the exmpl_df cited in the PR. Nine of them are pyace.preparedata.DataFrameWithMetadata, a pd.DataFrame subclass with _metadata and a _constructor override - the part most exposed to pandas 3 - and they rebuild with the metadata attribute intact and object dtypes preserved. index.map(str), Series.map(len), df[col] =, df.loc[mask, col] = and pd.concat all run clean on the loaded frames with no CoW warnings. Caveat: a green run here does not exercise pandas 3, for two independent reasons. pandas 3.0 requires Python >= 3.11 and this matrix is 3.9/3.10, so it cannot be installed at all; and TensorPotential pins pandas<=2.0 and is installed first, so both jobs resolve pandas 2.0.0 whichever bound this file carries. CI can only show no regression against pandas 2.0.0. Same shape of gap as ICAMS#101 has for numpy. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two changes are needed to work with numpy 2.4, both backward compatible down to numpy 1.x:
PyACECalculator/PyACEEnsembleCalculator filled the ASE results dict via np.float64(energy.reshape(-1,)). numpy 2.4 expired the 'conversion of ndim > 0 arrays to scalars' deprecation (present since numpy 1.25), so the scalar constructor now returns a shape-(1,) array instead of collapsing it to a scalar, and atoms.get_potential_energy() leaked a 1-element array of the total energy. Scalar results now go through float(), which behaves identically on every numpy version, and per-atom arrays through astype(np.float64), which also keeps energies_dev/forces_dev arrays for single-atom structures on older numpy.
pyace.radial used np.trapz, which numpy 2.0 kept only as a deprecated alias of np.trapezoid and numpy 2.4 removed. The module now picks whichever of the two exists.
A regression assertion in tests/test_PyACECalculator.py guards the scalar energy output. Verified by building the package and running tests/test_PyACECalculator.py against numpy 1.26.4, 2.3.5 and 2.4.6.
Claude-Session: https://claude.ai/code/session_015Ui6Drmop9gZXo1fgn8yVg
Pull Request Template
Thank you for contributing to our project! Please review the checklist and fill out the details below.
Description of Changes
Checklist
License Agreement
By submitting this pull request, I agree that:
Thank you for your contribution!