Skip to content

Commit

Permalink
try to skip code with regex
Browse files Browse the repository at this point in the history
  • Loading branch information
enigne committed Jul 8, 2024
1 parent 4111b9e commit 6febc5f
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 26 deletions.
6 changes: 4 additions & 2 deletions pinnicle/physics/stressbalance.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def set_default(self):
self.scalar_variables = {
'n': 3.0, # exponent of Glen's flow law
}
class SSAVariableB(EquationBase): #{{{
class SSAVariableB(EquationBase):
""" SSA on 2D problem with spatially varying B
"""
_EQUATION_TYPE = 'SSA_VB'
Expand All @@ -121,6 +121,7 @@ def pde(self, nn_input_var, nn_output_var):
nn_input_var: global input to the nn
nn_output_var: global output from the nn
"""
# no cover: start
# get the ids
xid = self.local_input_var["x"]
yid = self.local_input_var["y"]

Check warning on line 127 in pinnicle/physics/stressbalance.py

View check run for this annotation

Codecov / codecov/patch

pinnicle/physics/stressbalance.py#L126-L127

Added lines #L126 - L127 were not covered by tests
Expand Down Expand Up @@ -164,7 +165,8 @@ def pde(self, nn_input_var, nn_output_var):
f1 = sigma11 + sigma12 - alpha*u/(u_norm+1e-30) - self.rhoi*self.g*H*s_x
f2 = sigma21 + sigma22 - alpha*v/(u_norm+1e-30) - self.rhoi*self.g*H*s_y

Check warning on line 166 in pinnicle/physics/stressbalance.py

View check run for this annotation

Codecov / codecov/patch

pinnicle/physics/stressbalance.py#L165-L166

Added lines #L165 - L166 were not covered by tests

return [f1, f2] #}}}
return [f1, f2] # }}}

Check warning on line 168 in pinnicle/physics/stressbalance.py

View check run for this annotation

Codecov / codecov/patch

pinnicle/physics/stressbalance.py#L168

Added line #L168 was not covered by tests
# no cover: stop
#}}}
# MOLHO constant B{{{
class MOLHOEquationParameter(EquationParameter, Constants):
Expand Down
24 changes: 13 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,21 @@ exclude = ["DATA", "Models", "docs*", "examples*"]
[tool.coverage.report]
# Regexes for lines to exclude from consideration
exclude_also = [
# Don't complain about missing debug-only code:
"def __repr__",
"if self\\.debug",
# 1. Comments to turn coverage on and off:
"no cover: start(?s:.)*?no cover: stop",
# Don't complain about missing debug-only code:
"def __repr__",
"if self\\.debug",

# Don't complain if tests don't hit defensive assertion code:
"raise AssertionError",
"raise NotImplementedError",
# Don't complain if tests don't hit defensive assertion code:
"raise AssertionError",
"raise NotImplementedError",

# Don't complain about abstract methods, they aren't run:
"@(abc\\.)?abstractmethod",
# Don't complain about abstract methods, they aren't run:
"@(abc\\.)?abstractmethod",

# Don't complain pytest.mark.skip:
"@pytest.mark.skip",
]
# Don't complain pytest.mark.skip:
"@pytest.mark.skip",
]

ignore_errors = true
48 changes: 37 additions & 11 deletions tests/test_pinn.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pinnicle as pinn
import numpy as np
import deepxde as dde
from pinnicle.utils import data_misfit, plot_nn, diffplot
from pinnicle.utils import data_misfit, plot_nn
import pytest

dde.config.set_default_float('float64')
Expand Down Expand Up @@ -231,17 +231,43 @@ def test_SSA_pde_function():
assert y[0].shape == (10,1)
assert y[1].shape == (10,1)

def test_diffplot(tmp_path):
hp["save_path"] = str(tmp_path)
hp["is_save"] = True
issm["data_size"] = {"u":4000, "v":4000, "s":4000, "H":4000, "C":None}
def test_SSA_VB_pde_function():
SSA = {}
SSA["n"] = {"n":3}
hp["equations"] = {"SSA_VB":SSA}
hp["num_collocation_points"] = 10
issm["data_size"] = {"u":10, "v":10, "s":10, "H":10, "C":None, "vel":10}
hp["data"] = {"ISSM": issm}
experiment = pinn.PINN(params=hp)
experiment.compile()
y = experiment.model.predict(experiment.model_data.X['u'], operator=experiment.physics.operator("SSA_VB"))
assert len(y) == 2
assert y[0].shape == (10,1)
assert y[1].shape == (10,1)

fig, axs = diffplot(experiment, 'H')
assert fig is not None
assert axs.shape == (3,)
fig, axs = diffplot(experiment, ['u', 'v'], feat_title='vel')
assert fig is not None
assert axs.shape == (3,)
def test_MOLHO_pde_function():
MOLHO = {}
MOLHO["n"] = {"n":3}
hp["equations"] = {"MOLHO":MOLHO}
hp["num_collocation_points"] = 10
issm["data_size"] = {"u":10, "v":10, "s":10, "H":10, "C":None, "vel":10}
hp["data"] = {"ISSM": issm}
experiment = pinn.PINN(params=hp)
experiment.compile()
y = experiment.model.predict(experiment.model_data.X['u'], operator=experiment.physics.operator("MOLHO"))
assert len(y) == 4
assert y[0].shape == (10,1)
assert y[3].shape == (10,1)

def test_MC_pde_function():
MC = {}
MC["n"] = {"n":3}
hp["equations"] = {"MC":MC}
hp["num_collocation_points"] = 10
issm["data_size"] = {"u":10, "v":10, "s":10, "H":10, "C":None, "vel":10}
hp["data"] = {"ISSM": issm}
experiment = pinn.PINN(params=hp)
experiment.compile()
y = experiment.model.predict(experiment.model_data.X['u'], operator=experiment.physics.operator("MC"))
assert len(y) == 1
assert y[0].shape == (10,1)
18 changes: 16 additions & 2 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pinnicle as pinn
import numpy as np
import deepxde as dde
from pinnicle.utils import plot_similarity, plot_residuals, tripcolor_similarity, tripcolor_residuals
from pinnicle.utils import plot_similarity, plot_residuals, tripcolor_similarity, tripcolor_residuals, diffplot
import matplotlib.pyplot as plt
import pytest

Expand Down Expand Up @@ -155,6 +155,20 @@ def test_triresiduals(tmp_path):
assert (fig is not None) and (np.size(axs)==2)
fig, axs = tripcolor_residuals(experiment, cbar_limits=[-7e3, 7e3])
assert (fig is not None) and (np.size(axs)==2)

plt.close("all")

def test_diffplot(tmp_path):
hp["save_path"] = str(tmp_path)
hp["is_save"] = True
issm["data_size"] = {"u":100, "v":100, "s":100, "H":100, "C":None}
hp["data"] = {"ISSM": issm}
experiment = pinn.PINN(params=hp)
experiment.compile()

fig, axs = diffplot(experiment, 'H')
assert fig is not None
assert axs.shape == (3,)
fig, axs = diffplot(experiment, ['u', 'v'], feat_title='vel')
assert fig is not None
assert axs.shape == (3,)
plt.close("all")

0 comments on commit 6febc5f

Please sign in to comment.