Skip to content

Commit 989c503

Browse files
committed
Fix warnings in solver
1 parent 55b3017 commit 989c503

File tree

11 files changed

+84
-33
lines changed

11 files changed

+84
-33
lines changed

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ max-branches=12
395395
max-locals=15
396396

397397
# Maximum number of parents for a class (see R0901).
398-
max-parents=7
398+
max-parents=12
399399

400400
# Maximum number of public methods for a class (see R0904).
401401
max-public-methods=20

pina/solver/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
"""
2+
TODO
3+
"""
4+
15
__all__ = [
26
"SolverInterface",
37
"SingleSolverInterface",

pina/solver/garom.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
"""Module for GAROM"""
22

33
import torch
4-
4+
from torch.nn.modules.loss import _Loss
55
from .solver import MultiSolverInterface
6-
from ..utils import check_consistency
7-
from ..loss.loss_interface import LossInterface
86
from ..condition import InputTargetCondition
97
from ..utils import check_consistency
108
from ..loss import LossInterface, PowerLoss
11-
from torch.nn.modules.loss import _Loss
129

1310

1411
class GAROM(MultiSolverInterface):
@@ -60,18 +57,22 @@ def __init__(
6057
rate scheduler for the generator.
6158
:param Scheduler scheduler_discriminator: Learning
6259
rate scheduler for the discriminator.
63-
:param dict scheduler_discriminator_kwargs: LR scheduler constructor keyword args.
64-
:param gamma: Ratio of expected loss for generator and discriminator, defaults to 0.3.
60+
:param dict scheduler_discriminator_kwargs: LR scheduler constructor
61+
keyword args.
62+
:param gamma: Ratio of expected loss for generator and discriminator,
63+
defaults to 0.3.
6564
:type gamma: float
66-
:param lambda_k: Learning rate for control theory optimization, defaults to 0.001.
65+
:param lambda_k: Learning rate for control theory optimization,
66+
defaults to 0.001.
6767
:type lambda_k: float
68-
:param regularizer: Regularization term in the GAROM loss, defaults to False.
68+
:param regularizer: Regularization term in the GAROM loss,
69+
defaults to False.
6970
:type regularizer: bool
7071
7172
.. warning::
72-
The algorithm works only for data-driven model. Hence in the ``problem`` definition
73-
the codition must only contain ``input`` (e.g. coefficient parameters, time
74-
parameters), and ``target``.
73+
The algorithm works only for data-driven model. Hence in the
74+
``problem`` definition the codition must only contain ``input``
75+
(e.g. coefficient parameters, time parameters), and ``target``.
7576
"""
7677

7778
# set loss
@@ -118,9 +119,11 @@ def forward(self, x, mc_steps=20, variance=False):
118119
:param mc_steps: Number of montecarlo samples to approximate the
119120
expected value, defaults to 20.
120121
:type mc_steps: int
121-
:param variance: Returining also the sample variance of the solution, defaults to False.
122+
:param variance: Returining also the sample variance of the solution,
123+
defaults to False.
122124
:type variance: bool
123-
:return: The expected value of the generator distribution. If ``variance=True`` also the
125+
:return: The expected value of the generator distribution. If
126+
``variance=True`` also the
124127
sample variance is returned.
125128
:rtype: torch.Tensor | tuple(torch.Tensor, torch.Tensor)
126129
"""
@@ -139,6 +142,7 @@ def forward(self, x, mc_steps=20, variance=False):
139142
return mean
140143

141144
def sample(self, x):
145+
"""TODO"""
142146
# sampling
143147
return self.generator(x)
144148

@@ -285,24 +289,30 @@ def test_step(self, batch):
285289

286290
@property
287291
def generator(self):
292+
"""TODO"""
288293
return self.models[0]
289294

290295
@property
291296
def discriminator(self):
297+
"""TODO"""
292298
return self.models[1]
293299

294300
@property
295301
def optimizer_generator(self):
302+
"""TODO"""
296303
return self.optimizers[0].instance
297304

298305
@property
299306
def optimizer_discriminator(self):
307+
"""TODO"""
300308
return self.optimizers[1].instance
301309

302310
@property
303311
def scheduler_generator(self):
312+
"""TODO"""
304313
return self.schedulers[0].instance
305314

306315
@property
307316
def scheduler_discriminator(self):
317+
"""TODO"""
308318
return self.schedulers[1].instance

pina/solver/physic_informed_solver/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""TODO"""
2+
13
__all__ = [
24
"PINNInterface",
35
"PINN",

pina/solver/physic_informed_solver/causal_pinn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import torch
44

5-
from pina.problem import TimeDependentProblem
5+
from ...problem import TimeDependentProblem
66
from .pinn import PINN
7-
from pina.utils import check_consistency
7+
from ...utils import check_consistency
88

99

1010
class CausalPINN(PINN):

pina/solver/physic_informed_solver/competitive_pinn.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Module for Competitive PINN."""
22

3-
import torch
43
import copy
4+
import torch
55

66
from ...problem import InverseProblem
77
from .pinn_interface import PINNInterface
@@ -211,6 +211,8 @@ def on_train_batch_end(self, outputs, batch, batch_idx):
211211
"""
212212
# increase by one the counter of optimization to save loggers
213213
(
214+
# Unavoidable long line
215+
# pylint: disable=line-too-long
214216
self.trainer.fit_loop.epoch_loop.manual_optimization.optim_step_progress.total.completed
215217
) += 1
216218

@@ -236,6 +238,9 @@ def discriminator(self):
236238
"""
237239
return self.models[1]
238240

241+
# In this case self.optimizers is a list of two optimizers!!!
242+
# pylint: disable=unsubscriptable-object
243+
239244
@property
240245
def optimizer_model(self):
241246
"""

pina/solver/physic_informed_solver/gradient_pinn.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import torch
44

55
from .pinn import PINN
6-
from pina.operator import grad
7-
from pina.problem import SpatialProblem
6+
from ...operator import grad
7+
from ...problem import SpatialProblem
88

99

1010
class GradientPINN(PINN):

pina/solver/physic_informed_solver/pinn_interface.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def loss_phys(self, samples, equation):
106106
samples and equation.
107107
:rtype: LabelTensor
108108
"""
109-
pass
110109

111110
def compute_residual(self, samples, equation):
112111
"""

pina/solver/physic_informed_solver/self_adaptive_pinn.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""Module for Self-Adaptive PINN."""
22

3-
import torch
43
from copy import deepcopy
4+
import torch
55

6-
from pina.utils import check_consistency
7-
from pina.problem import InverseProblem
6+
from ...utils import check_consistency
7+
from ...problem import InverseProblem
88
from ..solver import MultiSolverInterface
99
from .pinn_interface import PINNInterface
1010

@@ -155,7 +155,7 @@ def __init__(
155155
self._vectorial_loss.reduction = "none"
156156

157157
def forward(self, x):
158-
"""
158+
r"""
159159
Forward pass implementation for the PINN
160160
solver. It returns the function
161161
evaluation :math:`\mathbf{u}(\mathbf{x})` at the control points
@@ -234,6 +234,8 @@ def on_train_batch_end(self, outputs, batch, batch_idx):
234234
"""
235235
# increase by one the counter of optimization to save loggers
236236
(
237+
# Unavoidable pylint error
238+
# pylint: disable=line-too-long
237239
self.trainer.fit_loop.epoch_loop.manual_optimization.optim_step_progress.total.completed
238240
) += 1
239241

@@ -370,6 +372,9 @@ def scheduler_weights(self):
370372
"""
371373
return self.schedulers[1]
372374

375+
# In this case self.optimizers is a list of two optimizers!!!
376+
# pylint: disable=unsubscriptable-object
377+
373378
@property
374379
def optimizer_model(self):
375380
"""

pina/solver/reduced_order_model.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ class ReducedOrderModelSolver(SupervisedSolver):
3939
\mathcal{D}_{\rm{net}}[\mathcal{E}_{\rm{net}}[\mathbf{u}(\mu_i)]] -
4040
\mathbf{u}(\mu_i))
4141
42-
where :math:`\mathcal{L}` is a specific loss function, default Mean Square Error:
42+
where :math:`\mathcal{L}` is a specific loss function, default
43+
Mean Square Error:
4344
4445
.. math::
4546
\mathcal{L}(v) = \| v \|^2_2.

0 commit comments

Comments
 (0)