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

Nexus: Initial NumPy 2 support #5215

Merged
merged 3 commits into from
Nov 26, 2024
Merged

Nexus: Initial NumPy 2 support #5215

merged 3 commits into from
Nov 26, 2024

Conversation

prckent
Copy link
Contributor

@prckent prckent commented Nov 9, 2024

Proposed changes

This PR is sufficient to have all the nexus tests pass with numpy2 (tested with 2.1.2). Unchanged behavior with 1.26.4 was also verified.

This PR does need some discussion on the preferred way forward and likely needs some reworking. Docs also need updating in a subsequent PR, plus we should have at least a nightly test configuration with numpy2 etc.

There are two classes of update:

  1. Updates to type aliases. Trivial.
  2. numpy2 changes some printing of numeric scalars to include their type information. This breaks k-point printing among other similar operations in the existing tests. I enabled a legacy printing option as an ugly workaround for PySCF and pwscf. (https://numpy.org/doc/stable/reference/generated/numpy.set_printoptions.html#numpy-set-printoptions). However any code that does not have test coverage and that does printing could be affected. "Sometime" a better solution will be needed.

Note I missed seeing the official suggested pattern for testing numpy version (
https://numpy.org/doc/stable/numpy_2_0_migration_guide.html#writing-numpy-version-dependent-code ), which could be used to replace the ugly string manipulation I put in a few spots ahead of set_printoptions(legacy="1.25")

I looked at this because as noted in #5050 , numpy was out in June and users will likely hit it before long.

What type(s) of changes does this code introduce?

  • New feature
  • Build related changes
  • Testing changes (e.g. new unit/integration/performance tests)

Does this introduce a breaking change?

  • No

What systems has this change been tested on?

sulfur, nightly gcc 14.2 configuration.

Checklist

  • Yes. This PR is up to date with current the current state of 'develop'
  • NA. Code added or changed in the PR has been clang-formatted
  • NA. This PR adds tests to cover any new code, or to catch a bug that is being fixed
  • No. Documentation has been added (if appropriate)

@prckent prckent added the nexus label Nov 9, 2024
@prckent prckent changed the title [WIP] Nexus: prototype numpy2 support [WIP] Nexus: prototype NumPy 2 support Nov 9, 2024
@jtkrogel
Copy link
Contributor

I think we might be able to consolidate the changes (and make them generally available) by introducing a single function:

def portable_numpy(np):
    if np.lib.NumpyVersion(np.__version__) >= '2.0.0b1':
        np.set_printoptions(legacy="1.25")
        np.string_ = np.bytes_
        np.float_  = np.float64
    #end if
#end def portable_numpy

For most of Nexus, this could be placed in versions.py and then called at the top of any affected file like this:

from versions import portable_numpy
import numpy as np
portable_numpy(np)

The function would have to be duplicated (for independence) in testing.py and called there also.

If I'm right, this approach would not require any changes to the body text in Nexus files and also be portable across numpy versions.

@prckent prckent changed the title [WIP] Nexus: prototype NumPy 2 support Nexus: Initial NumPy 2 support Nov 25, 2024
@prckent
Copy link
Contributor Author

prckent commented Nov 25, 2024

Thanks for the cleaner suggestion. I reset my original changes and added your function to testing.py... which surprisingly turned out to already be enough due to the wide usage of the testing module.

I removed the [WIP] since this is hopefully enough for now.

@ye-luo
Copy link
Contributor

ye-luo commented Nov 26, 2024

Test this please

@ye-luo ye-luo merged commit aa5614d into QMCPACK:develop Nov 26, 2024
38 of 39 checks passed
@prckent prckent deleted the nxnumpy2 branch November 26, 2024 21:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants