-
Notifications
You must be signed in to change notification settings - Fork 71
Radial Extension for SFNO #242
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
tmarkmann
wants to merge
20
commits into
NVIDIA:main
Choose a base branch
from
tmarkmann:tmarkmann/spherical-poisson
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 all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
663790d
Add drafts for poisson and heat equation
tmarkmann 10850a3
Add Poisson solver and notebook
tmarkmann 15be043
Remove heat equation
tmarkmann 0bc2c0f
Add drafts for poisson and heat equation
tmarkmann d4cfef6
Add Poisson solver and notebook
tmarkmann cae38ea
Remove heat equation
tmarkmann b5d8b71
Merge branch 'tmarkmann/spherical-poisson' of github.com:tmarkmann/to…
tmarkmann 1e35c71
Revert wrongfully changes
tmarkmann 314cfac
Cosmetic changes
tmarkmann 5dc37b9
Run precommit
tmarkmann 45a64bf
Remove einops dependency from Poisson solver
azrael417 a19f51b
Use precompute_latitudes in RadialPoissonSolver
azrael417 eb8e63e
Remove dead code and correct docs in the Poisson solver
azrael417 12f9e1b
Raise ValueError instead of asserting in plot_sphere
azrael417 40e2275
Render the Poisson notebook in the docs
azrael417 73d88d5
Document the domain-dependent meaning of r_min and r_max
azrael417 343b776
Fill in the remaining Poisson docstring gaps
azrael417 26bcd3c
Add changelog entries for the Poisson solver and geometric_weights
azrael417 3e8cb41
Add tests for geometric_weights
azrael417 5544661
Merge branch 'main' into tmarkmann/spherical-poisson
azrael417 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| *.DS_Store | ||
| __pycache__ | ||
| *.so | ||
| *.egg-info/ | ||
| checkpoints | ||
|
|
||
| # Build artifacts | ||
|
|
||
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
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 @@ | ||
| ../../notebooks/poisson_equation.ipynb |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,133 @@ | ||
| # coding=utf-8 | ||
|
|
||
| # SPDX-FileCopyrightText: Copyright (c) 2022 The torch-harmonics Authors. All rights reserved. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # Redistribution and use in source and binary forms, with or without | ||
| # modification, are permitted provided that the following conditions are met: | ||
| # | ||
| # 1. Redistributions of source code must retain the above copyright notice, this | ||
| # list of conditions and the following disclaimer. | ||
| # | ||
| # 2. Redistributions in binary form must reproduce the above copyright notice, | ||
| # this list of conditions and the following disclaimer in the documentation | ||
| # and/or other materials provided with the distribution. | ||
| # | ||
| # 3. Neither the name of the copyright holder nor the names of its | ||
| # contributors may be used to endorse or promote products derived from | ||
| # this software without specific prior written permission. | ||
| # | ||
| # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
| # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
| # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
| # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
| # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| # | ||
|
|
||
|
|
||
| import torch | ||
|
|
||
| from .poisson_equation import RadialPoissonSolver | ||
|
|
||
|
|
||
| class PoissonDataset(torch.utils.data.Dataset): | ||
| """Custom Dataset class for Poisson training data | ||
|
|
||
| Parameters | ||
| ---------- | ||
| dims : tuple, optional | ||
| Number of latitude, longitude and radial points, by default (64, 128, 256) | ||
| grid : str, optional | ||
| Angular grid type, by default "legendre-gauss" | ||
| domain : str, optional | ||
| Either "half-line" or "exterior", by default "half-line" | ||
| R : float, optional | ||
| Inner radius for exterior domain, by default None | ||
| nblobs : int or tuple of int, optional | ||
| Number of blobs in each source, by default (1, 8) | ||
| l_src : int, optional | ||
| Angular band limit of the source, by default 8 | ||
| positive : bool, optional | ||
| Draw only positive sources, by default False | ||
| num_examples : int, optional | ||
| Number of examples, by default 32 | ||
| device : torch.device, optional | ||
| Device to use, by default torch.device("cpu") | ||
| normalize : bool, optional | ||
| Whether to normalize the input and target, by default True | ||
|
|
||
| Returns | ||
| ------- | ||
| inp : torch.Tensor | ||
| Source, shape (nr, nlat, nlon) | ||
| tar : torch.Tensor | ||
| Solution, shape (nr, nlat, nlon) | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| dims=(64, 128, 256), | ||
| grid="legendre-gauss", | ||
| domain="half-line", | ||
| R=None, | ||
| nblobs=(1, 8), | ||
| l_src=8, | ||
| positive=False, | ||
| num_examples=32, | ||
| device=torch.device("cpu"), | ||
| normalize=True, | ||
| ): | ||
| self.num_examples = num_examples | ||
| self.device = device | ||
| self.normalize = normalize | ||
| self.nblobs = nblobs | ||
| self.l_src = l_src | ||
| self.positive = positive | ||
| self.nlat, self.nlon, self.nr = dims | ||
|
|
||
| self.solver = RadialPoissonSolver( | ||
| self.nlat, | ||
| self.nlon, | ||
| self.nr, | ||
| grid=grid, | ||
| domain=domain, | ||
| R=R, | ||
| ).to(self.device) | ||
|
|
||
| def __len__(self): | ||
| return self.num_examples | ||
|
|
||
| def _get_sample(self): | ||
| """Get one unscaled source + solution pair.""" | ||
|
|
||
| f = self.solver.random_source(nblobs=self.nblobs, l_src=self.l_src, positive=self.positive) | ||
| u = self.solver.solve(f) | ||
|
|
||
| return f.float(), u.float() | ||
|
|
||
| def scale(self, f): | ||
| """ | ||
| Scale factor for a pair: the L2 norm of the source, quadrature-weighted in the | ||
| radial direction by r**2 dr and approximated by an unweighted mean over the | ||
| angular directions. | ||
| """ | ||
|
|
||
| w, r = self.solver.w, self.solver.r | ||
| return ((w * r**2) * (f**2).mean(dim=(-1, -2))).sum().sqrt() | ||
|
|
||
| def __getitem__(self, index): | ||
|
|
||
| with torch.inference_mode(): | ||
| with torch.no_grad(): | ||
| inp, tar = self._get_sample() | ||
|
|
||
| if self.normalize: | ||
| s = self.scale(inp) | ||
| inp, tar = inp / s, tar / s | ||
|
|
||
| return inp.clone(), tar.clone() | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
torch-harmonics has a PDEDataset object. Couldn't we have reused that? or derived from that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not extend the PDEDataset because I did not want to break existing code and some things are different for the poisson equation:
My first thought was that caring about all the divergences between SWE and Poisson is a bit hacky. But for the example poisson I can just fix all parameters like domain and rmin, rmax and then it should be ok. I will fix that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should rename the PDE dataset to SWEDataset? Since that is more descriptive? Boris, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not mind having a separate class per example, in that way each example is self contained, up to the shared content from torch harmonics that is. But users can grab the example and their TH install and run it, no need to use classes or functions from an example helper folder or something like that.