Abstraction of array handling logic in sympl#50
Open
JoyMonteiro wants to merge 4 commits intomcgibbon:masterfrom
Open
Abstraction of array handling logic in sympl#50JoyMonteiro wants to merge 4 commits intomcgibbon:masterfrom
JoyMonteiro wants to merge 4 commits intomcgibbon:masterfrom
Conversation
- Optimized `get_numpy_array` in `sympl/_core/get_np_arrays.py` to use direct numpy operations (`transpose`, `reshape`) on `.values` instead of `DataArray` methods when possible, avoiding `expand_dims` and `DataArray.transpose` overhead. - Added short-circuit for matching dimensions in `get_numpy_array`. - Fixed `AttributeError: module 'numpy' has no attribute 'product'` by replacing `np.product` with `np.prod` in `sympl/_core/util.py` and `sympl/_core/wildcard.py`. - Fixed `AttributeError: module 'numpy' has no attribute 'byte_bounds'` in tests by using `numpy.lib.array_utils.byte_bounds` if available (NumPy 2.0+) or falling back to `numpy.byte_bounds`. - Added `benchmark.py` to measure performance of `Stepper` calls with and without dimension transposition. Co-authored-by: JoyMonteiro <7300413+JoyMonteiro@users.noreply.github.com>
…4026618306699 Optimize get_numpy_array and fix NumPy 2.0 compatibility
mcgibbon
reviewed
Feb 11, 2026
| @@ -1,60 +1,123 @@ | |||
| # -*- coding: utf-8 -*- | |||
| from ._core.base_components import ( | |||
Owner
There was a problem hiding this comment.
Is anything changing in this file? Make sure we keep backwards compatibility.
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.
After a very very long time, and thanks to Gemini, I was able to revisit the issue that I had raised about performance degradation due to DataArrays being the container for model state #46
This PR addresses that issue, and abstracts out the array handling logic. All sympl tests pass, some additional documentation has been added. I have added a Unyt based backend in climt as a proof of concept, and it makes single column runs ~4x faster, and generally the array handling during units conversion etc., has improved by much more than 4x.
https://github.com/CliMT/climt/blob/develop/examples/gmd_radiative_convective_unyt.py
I'm also working on a JAX backend on a separate branch.
I have also included benchmarks in climt comparing the unyt and dataarray backends in detail. In general everything seems to be working fine. https://github.com/CliMT/climt/tree/develop/benchmarks
I would like to merge this and release a new version of sympl so that I can release a new version of climt with the unyt backend. This has been a demand of long-time climt users.