Skip to content
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

Create xtorch_harmonics package #2267

Merged
merged 15 commits into from
Jul 25, 2023
Merged

Create xtorch_harmonics package #2267

merged 15 commits into from
Jul 25, 2023

Conversation

spencerkclark
Copy link
Member

@spencerkclark spencerkclark commented Jun 30, 2023

This PR adds a package containing an xarray wrapper of a spherical harmonic transform roundtrip that can be completed with NVIDIA's torch_harmonics package. The roundtrip transform code itself is derived from this notebook of @oliverwm1. The xarray wrapper is based on that developed in this notebook of mine.

Some updates from that development notebook include:

  • Code to ensure that DataArray and Dataset level attributes are preserved in round trips.
  • A split of the grid parameter into forward_grid and inverse_grid components to allow for more flexibility.
  • Optional grid validation code to ensure that the coordinates of the grid match the expectation of the forward_grid specified. This can be disabled by setting unsafe=True.
  • Updating of the latitude coordinate in the case that the forward_grid does not equal the inverse_grid.

Added public API:

  • xtorch_harmonics.roundtrip: a function to apply a roundtrip spherical harmonic transform to all horizontally varying variables in a Dataset or to a single DataArray.

Requirement changes:

  • torch-harmonics@git+https://github.com/NVIDIA/torch-harmonics.git@8826246cacf6c37b600cdd63fde210815ba238fd

  • Install git and git-lfs in the fv3net Docker image to enable installation of torch_harmonics from GitHub.

  • Pin pip to version 20.2.4 (consistent with what we do in environment.yml in fv3net) in the lint build in CircleCI to avoid errors like this.

  • Ran make lock_deps/lock_pip following these instructions

  • Add PR review with license info for any additions to constraints.txt
    (example)

  • Tests added

Coverage reports (updated automatically):

@@ -288,6 +288,7 @@ tf-estimator-nightly==2.8.0.dev2021122109
threadpoolctl==3.1.0
toml==0.10.1
toolz==0.10.0
git+https://github.com/NVIDIA/torch-harmonics.git@8826246cacf6c37b600cdd63fde210815ba238fd
Copy link
Member Author

Choose a reason for hiding this comment

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

torch_harmonics uses a BSD-3-Clause license (see here).

@spencerkclark spencerkclark changed the title Create xtorch_harmonics package Create xtorch_harmonics package Jun 30, 2023
@spencerkclark spencerkclark force-pushed the xtorch_harmonics branch 4 times, most recently from 5bdc807 to 5cbc355 Compare July 6, 2023 00:39
Copy link
Contributor

@oliverwm1 oliverwm1 left a comment

Choose a reason for hiding this comment

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

In general looks great! The coordinate validation is tricky... In general I think it's fine to leave in what you have but it is a bit unclear to me whether a shifted/flipped coordinate should be valid.

Copy link
Member Author

@spencerkclark spencerkclark left a comment

Choose a reason for hiding this comment

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

Thanks for the initial review @oliverwm1. I tried to address all of your comments; see my responses below.

@spencerkclark spencerkclark marked this pull request as ready for review July 24, 2023 15:35
Copy link
Contributor

@oliverwm1 oliverwm1 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the changes.

spencerkclark added a commit that referenced this pull request Nov 6, 2023
#2267 added `torch_harmonics` via a GitHub URL to the
`pip-requirements.txt` file, which subsequently led to it being used in
the `constraints.txt` file. This broke the dataflow image build as newer
versions of `pip` no longer allow this: #2304.

This PR implements the fix suggested in a discussion between @frodre and
@oliverwm1 in Slack a while back:

> Could we just avoid having it in the constraints entirely? It would
still get installed in the image right?

Indeed it seems like even if older versions of `pip` allow GitHub URLs
to appear in constraints files, they do not have the desired effect. In
other words if one does:

```
$ pip install -c constraints.txt torch_harmonics
```

in an environment without it already installed, `pip` will download the
latest version off of PyPI instead of fetching it from the GitHub URL in
the constraints file (perhaps this is not surprising since it is unnamed
and `pip` is not set up to infer the name from the URL). Thus I suppose
it is somewhat misleading to include GitHub URLs in the constraints to
begin with, and sufficient / better that we specify `torch_harmonics`
from GitHub in the `setup.py` in `xtorch_harmonics`:


https://github.com/ai2cm/fv3net/blob/314edd50a1d9f1fe31d14a418dbe981d16c63f1d/external/xtorch_harmonics/setup.py#L16


All that being said, I have implemented this in a way such to retain
`git+https://github.com/NVIDIA/torch-harmonics.git@8826246cacf6c37b600cdd63fde210815ba238fd`
in `pip-requirements.txt` since it appears `pip-compile` can still
resolve dependencies from packages on GitHub and use that to inform the
versions of other packages pinned in the `constraints.txt` file, which
is still useful.

Requirement changes:
- [x] Ran `make lock_deps/lock_pip` following these
[instructions](https://vulcanclimatemodeling.com/docs/fv3net/dependency_management.html#dependency-management)

Resolves #2304

Coverage reports (updated automatically):

---------

Co-authored-by: Oliver Watt-Meyer <oliverwatt@gmail.com>
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