-
Notifications
You must be signed in to change notification settings - Fork 47
YAC as an optional remapping backend for uxarray #1440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
rajeeja
wants to merge
27
commits into
main
Choose a base branch
from
rajeeja/yac
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
fe66a32
o First pass at YAC - expose remap, nnn and conservative
rajeeja ca75ae4
o Fix actions
rajeeja 45da06f
o Add MPI flags for CI
rajeeja 9849d14
o Explicitly set MPI
rajeeja e88975e
o Use --without-regard-for-quality flag
rajeeja e84d1df
Merge branch 'main' into rajeeja/yac
hongyuchen1030 ba49926
Merge branch 'main' into rajeeja/yac
hongyuchen1030 81bd563
Merge branch 'main' into rajeeja/yac
rajeeja 65c765f
Merge branch 'main' into rajeeja/yac
rajeeja 50498d1
Switch YAC remap backend to yac.core
rajeeja d810aed
Merge remote-tracking branch 'origin/main' into rajeeja/yac
rajeeja d0febae
Fix YAC and Windows CI workflows
rajeeja e1e1c46
Merge remote-tracking branch 'origin/main' into rajeeja/yac
rajeeja 34ac282
Clarify remap docstring and add conservative face-only validation
Copilot ecbde03
fix: only pass yac_method to nearest_neighbor when it's not None in _…
Copilot 4446c6c
fix: validate backend parameter in RemapAccessor methods, raise Value…
Copilot 5fc0399
Update uxarray/remap/accessor.py
rljacob 7079b6e
fix: raise NotImplementedError for bilinear with backend='yac'
Copilot 96d33b1
Fix argument in uxarray/remap/yac.py
rljacob 00b1506
Finish YAC review follow-ups
rajeeja 1c58343
Merge branch 'main' into rajeeja/yac
rajeeja 032bed6
Add YAC conservative fallback and mask support
rajeeja ecb5bf5
Add YAC average bilinear support
rajeeja f720999
Merge branch 'main' into rajeeja/yac
rajeeja 4bcbf77
Merge remote-tracking branch 'origin/rajeeja/yac' into rajeeja/yac
rajeeja caf4a5e
Address review comments and add docs
rajeeja b86cbb6
Reword error
rajeeja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| name: YAC Optional CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| paths: | ||
| - ".github/workflows/yac-optional.yml" | ||
| - "uxarray/remap/**" | ||
| - "test/test_remap_yac.py" | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| yac-optional: | ||
| name: YAC core v3.14.0_p1 (Ubuntu) | ||
| runs-on: ubuntu-latest | ||
| defaults: | ||
| run: | ||
| shell: bash -l {0} | ||
| env: | ||
| YAC_VERSION: v3.14.0_p1 | ||
| YAXT_VERSION: v0.11.5.1 | ||
| MPIEXEC: /usr/bin/mpirun | ||
| MPIRUN: /usr/bin/mpirun | ||
| MPICC: /usr/bin/mpicc | ||
| MPIFC: /usr/bin/mpif90 | ||
| MPIF90: /usr/bin/mpif90 | ||
| OMPI_ALLOW_RUN_AS_ROOT: 1 | ||
| OMPI_ALLOW_RUN_AS_ROOT_CONFIRM: 1 | ||
| steps: | ||
| - name: checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| token: ${{ github.token }} | ||
|
|
||
| - name: conda_setup | ||
| uses: conda-incubator/setup-miniconda@v3 | ||
| with: | ||
| activate-environment: uxarray_build | ||
| channel-priority: strict | ||
| python-version: "3.11" | ||
| channels: conda-forge | ||
| environment-file: ci/environment.yml | ||
| miniforge-variant: Miniforge3 | ||
| miniforge-version: latest | ||
|
|
||
| - name: Install build dependencies (apt) | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y \ | ||
| autoconf \ | ||
| automake \ | ||
| gawk \ | ||
| gfortran \ | ||
| libopenmpi-dev \ | ||
| libtool \ | ||
| make \ | ||
| openmpi-bin \ | ||
| pkg-config | ||
| - name: Verify MPI tools | ||
| run: | | ||
| which mpirun | ||
| which mpicc | ||
| which mpif90 | ||
| mpirun --version | ||
| mpicc --version | ||
| mpif90 --version | ||
| - name: Install Python build dependencies | ||
| run: | | ||
| python -m pip install --upgrade pip | ||
| python -m pip install cython wheel | ||
| - name: Build and install YAXT | ||
| run: | | ||
| set -euxo pipefail | ||
| YAC_PREFIX="${GITHUB_WORKSPACE}/yac_prefix" | ||
| echo "YAC_PREFIX=${YAC_PREFIX}" >> "${GITHUB_ENV}" | ||
| git clone --depth 1 --branch "${YAXT_VERSION}" https://gitlab.dkrz.de/dkrz-sw/yaxt.git | ||
| if [ ! -x yaxt/configure ]; then | ||
| if [ -x yaxt/autogen.sh ]; then | ||
| (cd yaxt && ./autogen.sh) | ||
| else | ||
| (cd yaxt && autoreconf -i) | ||
| fi | ||
| fi | ||
| mkdir -p yaxt/build | ||
| cd yaxt/build | ||
| ../configure \ | ||
| --prefix="${YAC_PREFIX}" \ | ||
| --without-regard-for-quality \ | ||
| CC="${MPICC}" \ | ||
| FC="${MPIF90}" | ||
| make -j2 | ||
| make install | ||
| - name: Build and install YAC | ||
| run: | | ||
| set -euxo pipefail | ||
| git clone --depth 1 --branch "${YAC_VERSION}" https://gitlab.dkrz.de/dkrz-sw/yac.git | ||
| if [ ! -x yac/configure ]; then | ||
| if [ -x yac/autogen.sh ]; then | ||
| (cd yac && ./autogen.sh) | ||
| else | ||
| (cd yac && autoreconf -i) | ||
| fi | ||
| fi | ||
| mkdir -p yac/build | ||
| cd yac/build | ||
| ../configure \ | ||
| --prefix="${YAC_PREFIX}" \ | ||
| --with-yaxt-root="${YAC_PREFIX}" \ | ||
| --disable-mci \ | ||
| --disable-utils \ | ||
| --disable-examples \ | ||
| --disable-tools \ | ||
| --disable-netcdf \ | ||
| --enable-python-bindings \ | ||
| CC="${MPICC}" \ | ||
| FC="${MPIF90}" | ||
| make -j2 | ||
| make install | ||
| - name: Configure YAC runtime paths | ||
| run: | | ||
| set -euxo pipefail | ||
| PY_VER="$(python -c 'import sys; print(f"{sys.version_info.major}.{sys.version_info.minor}")')" | ||
| echo "LD_LIBRARY_PATH=${YAC_PREFIX}/lib:${LD_LIBRARY_PATH:-}" >> "${GITHUB_ENV}" | ||
| echo "PYTHONPATH=${YAC_PREFIX}/lib/python${PY_VER}/site-packages:${YAC_PREFIX}/lib/python${PY_VER}/dist-packages:${PYTHONPATH:-}" >> "${GITHUB_ENV}" | ||
| - name: Verify YAC core Python bindings | ||
| run: | | ||
| python - <<'PY' | ||
| from pathlib import Path | ||
| import sys | ||
| candidates = [] | ||
| for entry in sys.path: | ||
| pkg = Path(entry) / "yac" | ||
| candidates.extend(pkg.glob("core*.so")) | ||
| candidates.extend(pkg.glob("core*.pyd")) | ||
| assert candidates, "yac.core extension not found on sys.path" | ||
| print("Found yac.core extension:", candidates[0]) | ||
| PY | ||
| - name: Install uxarray | ||
| run: | | ||
| python -m pip install . --no-deps | ||
| - name: Run tests (uxarray with YAC) | ||
| run: | | ||
| python -m pytest test/test_remap_yac.py |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import numpy as np | ||
| import pytest | ||
|
|
||
| import uxarray as ux | ||
| from uxarray.remap.yac import YacNotAvailableError, _import_yac | ||
|
|
||
|
|
||
| try: | ||
| _import_yac() | ||
| except YacNotAvailableError: | ||
| pytest.skip("yac.core is not available", allow_module_level=True) | ||
|
|
||
|
|
||
| def test_yac_nnn_node_remap(gridpath, datasetpath): | ||
| grid_path = gridpath("ugrid", "geoflow-small", "grid.nc") | ||
| uxds = ux.open_dataset(grid_path, datasetpath("ugrid", "geoflow-small", "v1.nc")) | ||
| dest = ux.open_grid(grid_path) | ||
|
|
||
| out = uxds["v1"].remap.nearest_neighbor( | ||
| destination_grid=dest, | ||
| remap_to="nodes", | ||
| backend="yac", | ||
| yac_method="nnn", | ||
| yac_options={"n": 1}, | ||
| ) | ||
| assert out.size > 0 | ||
| assert "n_node" in out.dims | ||
|
|
||
|
|
||
| def test_yac_conservative_face_remap(gridpath): | ||
| mesh_path = gridpath("mpas", "QU", "mesh.QU.1920km.151026.nc") | ||
| uxds = ux.open_dataset(mesh_path, mesh_path) | ||
| dest = ux.open_grid(mesh_path) | ||
|
|
||
| out = uxds["latCell"].remap.nearest_neighbor( | ||
| destination_grid=dest, | ||
| remap_to="faces", | ||
| backend="yac", | ||
| yac_method="conservative", | ||
| yac_options={"order": 1}, | ||
| ) | ||
| assert out.size == dest.n_face | ||
|
|
||
|
|
||
| def test_yac_matches_uxarray_nearest_neighbor(): | ||
| verts = np.array([(0.0, 90.0), (-180.0, 0.0), (0.0, -90.0)]) | ||
| grid = ux.open_grid(verts) | ||
| da = ux.UxDataArray( | ||
| np.asarray([1.0, 2.0, 3.0]), | ||
| dims=["n_node"], | ||
| coords={"n_node": [0, 1, 2]}, | ||
| uxgrid=grid, | ||
| ) | ||
|
|
||
| ux_out = da.remap.nearest_neighbor( | ||
| destination_grid=grid, | ||
| remap_to="nodes", | ||
| backend="uxarray", | ||
| ) | ||
| yac_out = da.remap.nearest_neighbor( | ||
| destination_grid=grid, | ||
| remap_to="nodes", | ||
| backend="yac", | ||
| yac_method="nnn", | ||
| yac_options={"n": 1}, | ||
| ) | ||
| assert ux_out.shape == yac_out.shape | ||
| assert (ux_out.values == yac_out.values).all() | ||
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.