Skip to content

Add support for numpy 2+#533

Merged
gtrevisan merged 7 commits intodevfrom
glt/numpy2
Mar 31, 2026
Merged

Add support for numpy 2+#533
gtrevisan merged 7 commits intodevfrom
glt/numpy2

Conversation

@gtrevisan
Copy link
Copy Markdown
Member

@gtrevisan gtrevisan commented Mar 23, 2026

  • unpin numpy to allow v2+,
  • lock deps to use latest numpy 2.4.3,
  • replace numpy.trapz with scipy.integrate.trapezoid,
  • check for numpy issues when importing MDSplus to avoid insecure fallback.

Note

trapz was deprecated in v2.0 and renamed to trapezoid, and eventually dropped in v2.4.

Caution

this will definitely break DIII-D workflows due to their old MDSplus version (7.139.59).
I'll push a fix -- i.e. a newer MDSplus version -- upon merge for my "public installation"...

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the project to be compatible with NumPy 2.x by loosening the NumPy upper bound, refreshing lockfiles to a NumPy 2.4.3 resolution, replacing deprecated numpy.trapz usage, and attempting to prevent an insecure mdsthin fallback when MDSplus fails due to NumPy-related import problems.

Changes:

  • Unpin NumPy (numpy>=1.26.0) and update lockfiles to resolve to NumPy 2.4.3.
  • Replace numpy.trapz with scipy.integrate.trapezoid in code paths that integrate signals.
  • Add logic intended to detect NumPy-related MDSplus import failures and raise instead of falling back to mdsthin.

Reviewed changes

Copilot reviewed 4 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pyproject.toml Removes NumPy <2.0.0 upper bound to allow NumPy 2+.
poetry.lock Updates locked packages to a NumPy 2.4.3 environment (incl. netcdf4 metadata changes).
uv.lock Updates uv lock resolution to NumPy 2.4.3 and removes NumPy <2.0.0 pin.
disruption_py/settings/time_setting.py Replaces np.trapz with scipy.integrate.trapezoid.
disruption_py/machine/cmod/thomson.py Replaces np.trapz and updates SciPy import usage accordingly.
disruption_py/inout/mds.py Adds NumPy-related import failure detection to avoid mdsthin fallback.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@gtrevisan gtrevisan marked this pull request as ready for review March 25, 2026 15:30
Copy link
Copy Markdown
Contributor

@ZanderKeith ZanderKeith left a comment

Choose a reason for hiding this comment

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

Confirmed results for the physics methods are unchanged between numpy 1.26.4, 2.0.2, and 2.4.4.

@gtrevisan gtrevisan requested a review from yumouwei March 31, 2026 15:17
Copy link
Copy Markdown
Contributor

@yumouwei yumouwei left a comment

Choose a reason for hiding this comment

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

I also got the error with MDSplus on omega so I'll wait for your fix.

@gtrevisan
Copy link
Copy Markdown
Member Author

what did you get? maybe this new error while testing out the branch?

raise ImportError("MDSplus vs numpy incompatibility") from e

I've just updated the "public installations", please retry and LMK!

@gtrevisan
Copy link
Copy Markdown
Member Author

I reran all tests on all machines for several numpy versions, and updated MDSplus APIs:

numpy<2 numpy>2,<2.4 numpy>2.4
C-MOD 🟩 🟢 🟩 🟢 🟩 🟢
DIII-D 🟩 🟢 🟩 🟢 🟩 🟢
HBT-EP 🟩 🟢 🟩 🟢 🟩 🟢

where: 🟩 = fast tests, 🟢 = full tests.

@yumouwei
Copy link
Copy Markdown
Contributor

Yes I got the "MDSplus vs numpy incompatibility" error while running pytest and scripts/default.py in my private installation. I'll figure out how to point to your MDSplus installation later.

Can confirm the public installation works without running into the error.

@gtrevisan
Copy link
Copy Markdown
Member Author

it's now based on the $DISPY_DIR as provided in the public snippets. then simply:

export PYTHONPATH="$DISPY_DIR/mdsplus/stable/python:$PYTHONPATH"

please try and test as I've carried out all tests from my part and would probably merge later today.

@yumouwei
Copy link
Copy Markdown
Contributor

I tested using your MDSplus installation with my private dis-py installation and it worked.

@gtrevisan gtrevisan merged commit b712a7e into dev Mar 31, 2026
26 checks passed
@gtrevisan gtrevisan deleted the glt/numpy2 branch March 31, 2026 20:09
@gtrevisan gtrevisan mentioned this pull request Mar 31, 2026
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.

4 participants