-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from NeuroDiffGym/v0.5.0
fix bug in H1 and H1-semi loss
- Loading branch information
Showing
4 changed files
with
106 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
|
@@ -17,14 +17,14 @@ def func(m): | |
|
||
setuptools.setup( | ||
name="neurodiffeq", | ||
version="0.4.0", | ||
version="0.5.0", | ||
author="neurodiffgym", | ||
author_email="[email protected]", | ||
description="A light-weight & flexible library for solving differential equations using neural networks based on PyTorch. ", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/NeuroDiffGym/neurodiffeq", | ||
download_url="https://github.com/NeuroDiffGym/neurodiffeq/archive/v0.4.0.tar.gz", | ||
download_url="https://github.com/NeuroDiffGym/neurodiffeq/archive/v0.5.0.tar.gz", | ||
keywords=[ | ||
"neural network", | ||
"deep learning", | ||
|
This file contains 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,37 @@ | ||
import pytest | ||
import torch | ||
from neurodiffeq import diff | ||
from neurodiffeq.losses import _losses as losses | ||
|
||
N = 100 | ||
|
||
|
||
def pde_system(u, v, w, x, y): | ||
return [ | ||
diff(u, x, order=2) + diff(u, y, order=2), | ||
diff(v, x, order=2) + diff(v, y, order=2), | ||
diff(w, x, order=2) + diff(w, y, order=2), | ||
] | ||
|
||
|
||
def get_rfx(n_input, n_output, n_equation): | ||
coords = [torch.rand((N, 1), requires_grad=True) for _ in range(n_input)] | ||
coords_tensor = torch.cat(coords, dim=1) | ||
funcs = [torch.sigmoid(torch.sum(coords_tensor, dim=1, keepdim=True)) for _ in range(n_output)] | ||
residual = [diff(funcs[0], coords[0]) + funcs[0] for _ in range(n_equation)] | ||
residual = torch.cat(residual, dim=1) | ||
return residual, funcs, coords | ||
|
||
|
||
@pytest.mark.parametrize(argnames='n_input', argvalues=[1, 3]) | ||
@pytest.mark.parametrize(argnames='n_output', argvalues=[1, 3]) | ||
@pytest.mark.parametrize(argnames='n_equation', argvalues=[1, 3]) | ||
@pytest.mark.parametrize( | ||
argnames=('loss_name', 'loss_fn'), | ||
argvalues=losses.items(), | ||
) | ||
def test_losses(n_input, n_output, n_equation, loss_name, loss_fn): | ||
r, f, x = get_rfx(n_input, n_output, n_equation) | ||
loss = loss_fn(r, f, x) | ||
assert loss.shape == (), f"{loss_name} doesn't output scalar" | ||
assert loss.requires_grad, f"{loss_name} doesn't require gradient" |