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

Add support for numpy 2 #2421

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

Add support for numpy 2 #2421

wants to merge 12 commits into from

Conversation

Ericgig
Copy link
Member

@Ericgig Ericgig commented May 8, 2024

Description
Add support for the up comming numpy v2:

  • Allows qutip to be compiled with numpy 2, and pass tests.
  • Test that binaries compiled with numpy 2 are compatible with numpy 1 at runtime.

I did not update the requirement yet, it must be installed in --no-build-isolation.
When it's officially released, we will need to update pyproject.toml and setup.cfg, and possibly add test for np2 on windows and mac.

Here are the changes that affect us:

  • np.array(.., copy=False) no longer mean copy only if needed. copy=None was added for that.
  • np.trapz was replaced by np.trapezoid. Since there are no overlaps, I opted to use scipy.integrate.trapezoid instead.
  • np.array(1, np.int32) * 2**33 will enforce the integer type and overflow.
  • Py_intptr_t from python.h is no longer available through numpy cython interface.

@coveralls
Copy link

coveralls commented May 8, 2024

Coverage Status

coverage: 86.283% (+0.02%) from 86.267%
when pulling 6c53741 on Ericgig:misc.np2
into 4acc9f1 on qutip:master.

Copy link
Contributor

@hodgestar hodgestar left a comment

Choose a reason for hiding this comment

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

Woot for starting to get things ready for numpy 2. Did a quick review of the changes so far. Most look good.

qutip/core/data/make.py Outdated Show resolved Hide resolved
@@ -108,7 +108,7 @@ def clebsch(j1, j2, j3, m1, m2, m3):
C = np.sqrt((2.0 * j3 + 1.0)*_to_long(c_factor))

s_factors = np.zeros(((vmax + 1 - vmin), (int(j1 + j2 + j3))), np.int32)
sign = (-1) ** (vmin + j2 + m2)
sign = int((-1) ** (vmin + j2 + m2))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did this need to be wrapped with int?

Copy link
Member Author

Choose a reason for hiding this comment

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

clebsch is computed using large integer over 32 and sometime 64 bits.
If the sign is a 0d numpy array it overflow.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah. Perhaps add a comment above this line with that explanation?

qutip/utilities.py Outdated Show resolved Hide resolved
@hodgestar
Copy link
Contributor

Numpy is maintaining a list of project versions that support numpy 2 -- numpy/numpy#26191. They're waiting of downstream packages to be ready before release. We could add ourselves there if we liked.

Copy link
Contributor

@eendebakpt eendebakpt left a comment

Choose a reason for hiding this comment

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

Numpy 2.0 is scheduled to be released June 6th (see numpy/numpy#24300 (comment))

os: ubuntu-latest
python-version: "3.12"
scipy-requirement: ""
numpy-requirement: "==2.0.0rc1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
numpy-requirement: "==2.0.0rc1"
numpy-requirement: "==2.0.0rc2"

There is a new release candidate available

os: ubuntu-latest
python-version: "3.10"
scipy-requirement: ""
numpy-requirement: "==2.0.0rc1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
numpy-requirement: "==2.0.0rc1"
numpy-requirement: "==2.0.0rc2"

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.

None yet

4 participants