diff --git a/.github/workflows/pace_tests.yaml b/.github/workflows/pace_tests.yaml index 3edb4f3..4e51eff 100644 --- a/.github/workflows/pace_tests.yaml +++ b/.github/workflows/pace_tests.yaml @@ -10,7 +10,7 @@ on: jobs: pace_unit_tests: - uses: NOAA-GFDL/pace/.github/workflows/main_unit_tests.yaml@develop + uses: floriandeconinck/pace/.github/workflows/main_unit_tests.yaml@update/numpy_2x with: component_trigger: true component_name: pySHiELD diff --git a/.github/workflows/translate.yaml b/.github/workflows/translate.yaml index bafffd7..104e344 100644 --- a/.github/workflows/translate.yaml +++ b/.github/workflows/translate.yaml @@ -44,8 +44,9 @@ jobs: uses: actions/checkout@v6 with: submodules: 'recursive' - repository: NOAA-GFDL/pySHiELD + repository: floriandeconinck/PySHiELD path: pySHiELD + ref: update/numpy_2x - name: 'Setup Python ${{ inputs.python_version && inputs.python_version || env.python_default }}' uses: actions/setup-python@v6 @@ -55,13 +56,6 @@ jobs: - name: Install mpi (MPICH flavor) run: pip install mpich - - name: Install numpy==1.26.4 - # Front-load installing numpy to force its usage in the radiation - # scheme of pySHiELD. - # TODO: This is an ugly hack and it should be cleaned up latest once - # we add support for numpy >= 2.0 - run: pip install numpy==1.26.4 - - name: External trigger remove existing component in pySHiELD/develop if: ${{ inputs.component_name }} run: rm -rf ${GITHUB_WORKSPACE}/pySHiELD/${{inputs.component_name}} diff --git a/examples/notebook/utilities.py b/examples/notebook/utilities.py index c7a727e..7800400 100644 --- a/examples/notebook/utilities.py +++ b/examples/notebook/utilities.py @@ -32,7 +32,7 @@ def states_from_fortran_restarts( tracer_data = xr.open_dataset(tracer_datafile) state = PhysicsState.init_zeros(quantity_factory, schemes) - radstate = RTE_RRTMGPState.init_zeros(quantity_factory, np) + radstate = RTE_RRTMGPState.init_zeros(quantity_factory) sstate = SurfaceState.init_zeros(quantity_factory) buff_3d = np.zeros_like(state.prsi.field) diff --git a/pyproject.toml b/pyproject.toml index 4d8d8f1..b4ff27b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ classifiers = [ ] dependencies = [ "f90nml>=1.1.0", - "numpy==1.26.4", + "numpy>=2", "xarray", "pyrte-rrtmgp @ git+https://github.com/NOAA-GFDL/pyRTE-RRTMGP.git@main" ] @@ -40,7 +40,7 @@ extras = [ "pyshield[pyfv3]", "pyshield[test]" ] -ndsl = ["ndsl @ git+https://github.com/NOAA-GFDL/NDSL.git@2026.02.00"] +ndsl = ["ndsl @ git+https://github.com/NOAA-GFDL/NDSL.git@develop"] pyfv3 = ["pyfv3 @ git+https://github.com/NOAA-GFDL/pyFV3.git@develop"] test = [ "coverage", diff --git a/pyshield/radiation/state.py b/pyshield/radiation/state.py index db94c04..3a0d9ff 100644 --- a/pyshield/radiation/state.py +++ b/pyshield/radiation/state.py @@ -1,13 +1,13 @@ from dataclasses import InitVar, dataclass, field, fields from typing import Any, Dict, Mapping +import numpy as np import xarray as xr import ndsl.dsl.gt4py_utils as gt_utils from ndsl import GridSizer, Quantity, QuantityFactory from ndsl.constants import I_DIM, J_DIM, K_DIM, K_INTERFACE_DIM from ndsl.dsl.typing import Float -from ndsl.types import NumpyModule @dataclass() @@ -261,14 +261,11 @@ class RTE_RRTMGPState: } ) quantity_factory: InitVar[QuantityFactory] - np_like: InitVar[NumpyModule] def __post_init__( self, quantity_factory: QuantityFactory, - np_like: NumpyModule, ): - self._np = np_like self._nz = quantity_factory.sizer.nz self._nx = quantity_factory.sizer.nx self._ny = quantity_factory.sizer.ny @@ -277,7 +274,6 @@ def __post_init__( def init_zeros( cls, quantity_factory, - np_like: NumpyModule, ) -> "RTE_RRTMGPState": initial_arrays = {} for _field in fields(cls): @@ -290,7 +286,6 @@ def init_zeros( return cls( **initial_arrays, quantity_factory=quantity_factory, - np_like=np_like, ) @classmethod @@ -299,7 +294,6 @@ def init_from_storages( storages: Mapping[str, Any], sizer: GridSizer, quantity_factory: QuantityFactory, - np_like: NumpyModule, ) -> "RTE_RRTMGPState": inputs: Dict[str, Quantity] = {} for _field in fields(cls): @@ -323,7 +317,6 @@ def init_from_storages( return cls( **inputs, quantity_factory=quantity_factory, - np_like=np_like, ) @property @@ -368,22 +361,22 @@ def to_rterrtmgp_xr(self) -> xr.Dataset: # dims.append(f"{dim_name}_{name}") if dim_name == "z_interface": slice_list.append( - self._np.s_[:] # type: ignore[attr-defined] + np.s_[:] # type: ignore[attr-defined] ) nz = self._nz + 1 dims.append("level") elif dim_name == "z": slice_list.append( - self._np.s_[:-1] # type: ignore[attr-defined] + np.s_[:-1] # type: ignore[attr-defined] ) dims.append("layer") elif "INTERFACE" in dim_name: slice_list.append( - self._np.s_[3:-3] # type: ignore[attr-defined] + np.s_[3:-3] # type: ignore[attr-defined] ) else: slice_list.append( - self._np.s_[3:-4] # type: ignore[attr-defined] + np.s_[3:-4] # type: ignore[attr-defined] ) # We have to reshape to get the max 2D shape rterrtmgp expects: if ndims == 3: # x-y-z array: diff --git a/tests/integration/test_all.py b/tests/integration/test_all.py index 86189f7..46708a5 100644 --- a/tests/integration/test_all.py +++ b/tests/integration/test_all.py @@ -82,7 +82,7 @@ def states_from_fortran_restarts( sfc_data = xr.open_dataset(sfc_datafile) state = PhysicsState.init_zeros(quantity_factory, schemes) sstate = SurfaceState.init_zeros(qf_sfc) - radstate = RTE_RRTMGPState.init_zeros(quantity_factory, np) + radstate = RTE_RRTMGPState.init_zeros(quantity_factory) buff_3d = np.zeros_like(state.prsi.field) npz = buff_3d.shape[2] for k in range(npz): diff --git a/tests/integration/test_radiation_driver.py b/tests/integration/test_radiation_driver.py index 0921bf8..23eaaa3 100644 --- a/tests/integration/test_radiation_driver.py +++ b/tests/integration/test_radiation_driver.py @@ -108,7 +108,7 @@ def states_from_fortran_restarts( tracer_data = xr.open_dataset(tracer_datafile) state = PhysicsState.init_zeros(quantity_factory, schemes) - radstate = RTE_RRTMGPState.init_zeros(quantity_factory, np) + radstate = RTE_RRTMGPState.init_zeros(quantity_factory) sstate = SurfaceState.init_zeros(quantity_factory) buff_3d = np.zeros_like(state.prsi.field) @@ -179,7 +179,7 @@ def test_rte_rrtmgp(datapath: Path): gridlon = grid_data.lon_agrid gridlat = grid_data.lat_agrid - state = RTE_RRTMGPState.init_zeros(quantity_factory, np) + state = RTE_RRTMGPState.init_zeros(quantity_factory) sstate = SurfaceState.init_zeros(quantity_factory) fortran_restart_to_radstate( dycore_datafile=dycore_data,