Skip to content

Support numpy >= 2.4 and relax the numpy requirement to <3#101

Open
pmrv wants to merge 1 commit into
ICAMS:masterfrom
pmrv:numpy-compat-upstream
Open

Support numpy >= 2.4 and relax the numpy requirement to <3#101
pmrv wants to merge 1 commit into
ICAMS:masterfrom
pmrv:numpy-compat-upstream

Conversation

@pmrv

@pmrv pmrv commented Jul 16, 2026

Copy link
Copy Markdown

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.

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

  • Code is well-documented.
  • All tests have been run and passed.
  • Relevant documentation has been updated if necessary.

License Agreement

By submitting this pull request, I agree that:

  • The code submitted in this pull request will be distributed under the Academic Software License (free for academic non-commercial use, not free for commercial use), see LICENSE.md for more details.
  • The copyright for the code, including the submitted code, remains with Ruhr University Bochum. Ruhr University Bochum retains the right to transfer or modify the copyright.

Thank you for your contribution!

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants