feat(deps): support numpy >= 2.0 (#247)#301
Merged
Merged
Conversation
Replaces numpy 1.x APIs removed/changed in numpy 2.0 and lifts the `numpy = "<2"` pixi pin (a clean break — numpy < 2 is no longer supported). Source changes: - np.core.numeric/multiarray.* -> public np.* (cross/dot/concatenate/ array_equal/allclose) in unit_aware_array.py (np.core is private in 2.0) - np.row_stack removed -> it aliased np.vstack, already handled; dropped the now-duplicate handler - __array__(self) -> __array__(self, dtype=None, copy=None) in the 4 array-view classes (numpy 2.0 calls __array__ with dtype/copy keywords) - 2-D np.cross -> explicit z-component (numpy 2.0 removed the 2-D cross) in the triangle shape-quality path - np.double -> np.float64 (51 occurrences, 8 files; cosmetic, valid in 1.x too) Env: - pixi.toml numpy pin "<2" -> ">=2"; pixi.lock re-solved to numpy 2.5.0. - PETSc is already 3.25 and the conda-petsc floor is >=3.21 (numpy-2 builds), so no PETSc version bump is required. Source edits verified under numpy 1.26 (build clean, imports, units/array/swarm tests green). numpy-2 environment validated by CI (conda-petsc, which ships numpy-2 petsc4py builds); local amr custom-petsc4py users rebuild their bindings. Underworld development team with AI support from Claude Code
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request updates Underworld3 to support NumPy >= 2.0 by removing reliance on private NumPy internals, adapting to NumPy 2’s updated array protocol, and updating environment pins/locks accordingly.
Changes:
- Replaced removed/private NumPy 1.x APIs (e.g.
np.core.*,np.double, 2Dnp.cross) with NumPy 2–compatible equivalents. - Updated several array-view classes’
__array__signatures to accept NumPy 2’sdtype/copykeywords. - Lifted the
numpy <2environment pin tonumpy >=2and re-solvedpixi.lock(NumPy 2.5.0).
Reviewed changes
Copilot reviewed 14 out of 25 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/underworld3/visualisation/visualisation.py | Switch array casting from np.double to np.float64. |
| src/underworld3/utilities/unit_aware_array.py | Replace private np.core.* calls with public NumPy APIs; remove row_stack handler. |
| src/underworld3/swarm.py | Update __array__ protocol and float dtype allocations for NumPy 2. |
| src/underworld3/meshing/smoothing.py | Replace np.double with np.float64 in numeric allocations/casts. |
| src/underworld3/function/unit_conversion.py | Update dtype documentation and conversions to np.float64. |
| src/underworld3/function/pure_sympy_evaluator.py | Ensure evaluated coordinate arrays use np.float64. |
| src/underworld3/function/functions_unit_system.py | Normalize coordinate arrays to np.float64 for evaluation paths. |
| src/underworld3/function/_function.pyx | Update Cython-side float64 handling and dtype checks for NumPy 2. |
| src/underworld3/discretisation/discretisation_mesh.py | Replace removed 2D np.cross usage with explicit z-component formula. |
| src/underworld3/discretisation/discretisation_mesh_variables.py | Update float dtype allocations and __array__ protocol for mesh array views. |
| pixi.toml | Lift NumPy pin to >=2. |
| pixi.lock | Lockfile refresh to NumPy 2.5.0 and updated dependency set. |
| Expt_Grains/Particle_numbers.txt | New data file added (appears to be a generated artifact). |
| docs/developer/design/FREESLIP_DYNAMIC_TOPOGRAPHY_FREESURFACE.md | Add large free-surface design/method note. |
| docs/blog/free-surface-without-advecting-it.md | Add draft blog post related to the free-surface method note. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
1443
to
1445
| # Compute cross product using numpy's default behavior | ||
| result = np.core.numeric.cross(np.asarray(a), np.asarray(b), *args, **kwargs) | ||
| result = np.cross(np.asarray(a), np.asarray(b), *args, **kwargs) | ||
|
|
Comment on lines
+1
to
+5
| 0 0 | ||
| 1 0 | ||
| 2 0 | ||
| 3 0 | ||
| 4 0 |
Comment on lines
+1
to
+7
| # A free surface you never advect | ||
|
|
||
| *Draft blog post — Underworld development team. Status: held pending a possible | ||
| method paper (the scheme is plausibly novel; see the | ||
| [method note](../developer/design/FREESLIP_DYNAMIC_TOPOGRAPHY_FREESURFACE.md) | ||
| and its cited novelty assessment). Not wired into the published docs toctree | ||
| yet — release at the team's discretion.* |
__array_wrap__ detected in-place operations via `result.base is self.base`. A fresh ufunc result (e.g. `scalar * arr`) has base=None; when the array also owns its data (base=None), that test is `None is None` == True, so under numpy 2.0's ufunc dispatch it returned `self` and DROPPED the operation — e.g. `1e-4 * v_at_Vpts` returned `v_at_Vpts`. This silently broke swarm.advection (dt factor lost -> displacement = v instead of v*dt) and CFL back-stepping (test_0007, test_0814 regressed only under numpy 2; fine on 1.26). Fix: require a NON-None shared base for the base-equality in-place branch, so a fresh scalar*array result is correctly returned (scaled) rather than mistaken for an in-place write. Verified under numpy 2.5: test_0007 + test_0814 pass, plus units/swarm/array/evaluate suites (43 passed). Underworld development team with AI support from Claude Code
This was referenced Jul 3, 2026
Member
Author
|
Thanks @copilot-pull-request-reviewer — good catches. Follow-up in #305:
Underworld development team with AI support from Claude Code |
lmoresi
added a commit
that referenced
this pull request
Jul 3, 2026
…ted artifact (#305) Follow-up to #301 (Copilot review): 1. numpy 2.0 removed the 2-D cross product. The UnitAwareArray np.cross handler delegated straight to np.cross, so `np.cross(a2d, b2d)` on unit-aware 2-D vectors raised ValueError under numpy 2. Emulate the 2-D z-component for (...,2) inputs (matching numpy 1.x), delegate to np.cross for 3-D. New tests/test_0758_unit_aware_cross.py (4 cases). 2. Expt_Grains/Particle_numbers.txt (a generated example output, written by docs/examples/porous_flow/advanced/Ex_Explicit_Flow_Grains.py) was swept into #301 by an over-broad `git add -A`. Remove it from version control and gitignore Expt_Grains/. Underworld development team with AI support from Claude Code
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.
Resolves #247. Lifts the
numpy = "<2"pin (clean break — numpy < 2 no longer supported) and replaces the numpy-1.x APIs removed/changed in numpy 2.0.Source changes
np.core.numeric/multiarray.*→ publicnp.*(cross/dot/concatenate/array_equal/allclose) —np.coreis private in 2.0np.row_stackremoved — it aliasednp.vstack(already handled); dropped the now-duplicate handler__array__(self)→__array__(self, dtype=None, copy=None)in the 4 array-view classes (numpy 2.0 passes dtype/copy)np.cross→ explicit z-component (numpy 2.0 removed the 2-D cross) in the triangle shape-quality pathnp.double→np.float64(51 occurrences, 8 files; cosmetic — valid in 1.x too)Env
pixi.toml:numpy = "<2"→">=2";pixi.lockre-solved cleanly to numpy 2.5.0.>=3.21(ships numpy-2 petsc4py builds) — no PETSc version bump needed. Answers the issue's min-PETSc question: 3.21.Validation
dev, numpy-2 petsc4py). Matches the prototype that passed core + 4-rank MPI at numpy 2.4.6 / PETSc 3.25../uw build/ petsc-local-build) after pulling — the custom petsc4py was compiled against numpy 1.26.Underworld development team with AI support from Claude Code