Skip to content

Abstraction of array handling logic in sympl#50

Open
JoyMonteiro wants to merge 4 commits intomcgibbon:masterfrom
JoyMonteiro:master
Open

Abstraction of array handling logic in sympl#50
JoyMonteiro wants to merge 4 commits intomcgibbon:masterfrom
JoyMonteiro:master

Conversation

@JoyMonteiro
Copy link
Collaborator

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.

google-labs-jules bot and others added 3 commits February 7, 2026 15:46
- 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
@JoyMonteiro JoyMonteiro requested a review from mcgibbon February 11, 2026 05:11
@@ -1,60 +1,123 @@
# -*- coding: utf-8 -*-
from ._core.base_components import (
Copy link
Owner

Choose a reason for hiding this comment

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

Is anything changing in this file? Make sure we keep backwards compatibility.

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.

2 participants