Skip to content

Commit 03ec91d

Browse files
fix rendering part 2
1 parent e0fbd3d commit 03ec91d

17 files changed

+217
-147
lines changed

pina/problem/zoo/advection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ class AdvectionProblem(SpatialProblem, TimeDependentProblem):
6363
training physics-informed neural networks*.
6464
arXiv preprint arXiv:2308.08468 (2023).
6565
DOI: `arXiv:2308.08468 <https://arxiv.org/abs/2308.08468>`_.
66+
67+
:Example:
68+
>>> problem = AdvectionProblem(c=1.0)
6669
"""
6770

6871
output_variables = ["u"]

pina/problem/zoo/allen_cahn.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ class AllenCahnProblem(TimeDependentProblem, SpatialProblem):
4949
Computer Methods in Applied Mechanics and Engineering 421 (2024): 116805
5050
DOI: `10.1016/
5151
j.cma.2024.116805 <https://doi.org/10.1016/j.cma.2024.116805>`_.
52+
53+
:Example:
54+
>>> problem = AllenCahnProblem()
5255
"""
5356

5457
output_variables = ["u"]

pina/problem/zoo/diffusion_reaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ class DiffusionReactionProblem(TimeDependentProblem, SpatialProblem):
5959
**Original reference**: Si, Chenhao, et al. *Complex Physics-Informed
6060
Neural Network.* arXiv preprint arXiv:2502.04917 (2025).
6161
DOI: `arXiv:2502.04917 <https://arxiv.org/abs/2502.04917>`_.
62+
63+
:Example:
64+
>>> problem = DiffusionReactionProblem()
6265
"""
6366

6467
output_variables = ["u"]

pina/problem/zoo/helmholtz.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ class HelmholtzProblem(SpatialProblem):
5353
**Original reference**: Si, Chenhao, et al. *Complex Physics-Informed
5454
Neural Network.* arXiv preprint arXiv:2502.04917 (2025).
5555
DOI: `arXiv:2502.04917 <https://arxiv.org/abs/2502.04917>`_.
56+
57+
:Example:
58+
>>> problem = HelmholtzProblem()
5659
"""
5760

5861
output_variables = ["u"]

pina/problem/zoo/inverse_poisson_2d_square.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class InversePoisson2DSquareProblem(SpatialProblem, InverseProblem):
5050
Implementation of the inverse 2-dimensional Poisson problem in the square
5151
domain :math:`[0, 1] \times [0, 1]`,
5252
with unknown parameter domain :math:`[-1, 1] \times [-1, 1]`.
53+
54+
:Example:
55+
>>> problem = InversePoisson2DSquareProblem()
5356
"""
5457

5558
output_variables = ["u"]

pina/problem/zoo/poisson_2d_square.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ class Poisson2DSquareProblem(SpatialProblem):
3030
r"""
3131
Implementation of the 2-dimensional Poisson problem in the square domain
3232
:math:`[0, 1] \times [0, 1]`.
33+
34+
:Example:
35+
>>> problem = Poisson2DSquareProblem()
3336
"""
3437

3538
output_variables = ["u"]

pina/solver/garom.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,22 @@ def __init__(
4545
:param torch.nn.Module generator: The generator model.
4646
:param torch.nn.Module discriminator: The discriminator model.
4747
:param torch.nn.Module loss: The loss function to be minimized.
48-
If ``None``, ``PowerLoss(p=1)`` is used. Default is ``None``.
48+
If ``None``, :class:`~pina.loss.power_loss.PowerLoss` with ``p=1``
49+
is used. Default is ``None``.
4950
:param Optimizer optimizer_generator: The optimizer for the generator.
50-
If `None`, the Adam optimizer is used. Default is ``None``.
51-
:param Optimizer optimizer_discriminator: The optimizer for the
52-
discriminator. If `None`, the Adam optimizer is used.
51+
If `None`, the :class:`torch.optim.Adam` optimizer is used.
5352
Default is ``None``.
53+
:param Optimizer optimizer_discriminator: The optimizer for the
54+
discriminator. If `None`, the :class:`torch.optim.Adam` optimizer is
55+
used. Default is ``None``.
5456
:param Scheduler scheduler_generator: The learning rate scheduler for
5557
the generator.
58+
If `None`, the :class:`torch.optim.lr_scheduler.ConstantLR`
59+
scheduler is used. Default is ``None``.
5660
:param Scheduler scheduler_discriminator: The learning rate scheduler
5761
for the discriminator.
62+
If `None`, the :class:`torch.optim.lr_scheduler.ConstantLR`
63+
scheduler is used. Default is ``None``.
5864
:param float gamma: Ratio of expected loss for generator and
5965
discriminator. Default is ``0.3``.
6066
:param float lambda_k: Learning rate for control theory optimization.
@@ -109,7 +115,7 @@ def forward(self, x, mc_steps=20, variance=False):
109115
of the solution. Default is ``False``.
110116
:return: The expected value of the generator distribution. If
111117
``variance=True``, the method returns also the variance.
112-
:rtype: torch.Tensor | tuple(torch.Tensor, torch.Tensor)
118+
:rtype: torch.Tensor | tuple[torch.Tensor, torch.Tensor]
113119
"""
114120

115121
# sampling
@@ -143,7 +149,7 @@ def _train_generator(self, parameters, snapshots):
143149
:param torch.Tensor parameters: The input tensor.
144150
:param torch.Tensor snapshots: The target tensor.
145151
:return: The residual loss and the generator loss.
146-
:rtype: tuple(torch.Tensor, torch.Tensor)
152+
:rtype: tuple[torch.Tensor, torch.Tensor]
147153
"""
148154
optimizer = self.optimizer_generator
149155
optimizer.zero_grad()
@@ -170,7 +176,8 @@ def on_train_batch_end(self, outputs, batch, batch_idx):
170176
171177
:param torch.Tensor outputs: The ``model``'s output for the current
172178
batch.
173-
:param dict batch: The current batch of data.
179+
:param list[tuple[str, dict]] batch: A batch of data. Each element is a
180+
tuple containing a condition name and a dictionary of points.
174181
:param int batch_idx: The index of the current batch.
175182
"""
176183
# increase by one the counter of optimization to save loggers
@@ -187,7 +194,7 @@ def _train_discriminator(self, parameters, snapshots):
187194
:param torch.Tensor parameters: The input tensor.
188195
:param torch.Tensor snapshots: The target tensor.
189196
:return: The residual loss and the generator loss.
190-
:rtype: tuple(torch.Tensor, torch.Tensor)
197+
:rtype: tuple[torch.Tensor, torch.Tensor]
191198
"""
192199
optimizer = self.optimizer_discriminator
193200
optimizer.zero_grad()
@@ -234,9 +241,12 @@ def optimization_cycle(self, batch):
234241
"""
235242
The optimization cycle for the GAROM solver.
236243
237-
:param tuple batch: The batch element in the dataloader.
238-
:return: The loss of the optimization cycle.
239-
:rtype: LabelTensor
244+
:param list[tuple[str, dict]] batch: A batch of data. Each element is a
245+
tuple containing a condition name and a dictionary of points.
246+
:return: The losses computed for all conditions in the batch, casted
247+
to a subclass of :class:`torch.Tensor`. It should return a dict
248+
containing the condition name and the associated scalar loss.
249+
:rtype: dict
240250
"""
241251
condition_loss = {}
242252
for condition_name, points in batch:
@@ -265,7 +275,8 @@ def validation_step(self, batch):
265275
"""
266276
The validation step for the PINN solver.
267277
268-
:param dict batch: The batch of data to use in the validation step.
278+
:param list[tuple[str, dict]] batch: A batch of data. Each element is a
279+
tuple containing a condition name and a dictionary of points.
269280
:return: The loss of the validation step.
270281
:rtype: torch.Tensor
271282
"""
@@ -287,7 +298,8 @@ def test_step(self, batch):
287298
"""
288299
The test step for the PINN solver.
289300
290-
:param dict batch: The batch of data to use in the test step.
301+
:param list[tuple[str, dict]] batch: A batch of data. Each element is a
302+
tuple containing a condition name and a dictionary of points.
291303
:return: The loss of the test step.
292304
:rtype: torch.Tensor
293305
"""

pina/solver/physic_informed_solver/causal_pinn.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,16 @@ class CausalPINN(PINN):
5353
.. seealso::
5454
5555
**Original reference**: Wang, Sifan, Shyam Sankaran, and Paris
56-
Perdikaris. "Respecting causality for training physics-informed
57-
neural networks." Computer Methods in Applied Mechanics
58-
and Engineering 421 (2024): 116813.
59-
DOI `10.1016 <https://doi.org/10.1016/j.cma.2024.116813>`_.
56+
Perdikaris.
57+
*Respecting causality for training physics-informed
58+
neural networks.*
59+
Computer Methods in Applied Mechanics and Engineering 421 (2024):116813.
60+
DOI: `10.1016 <https://doi.org/10.1016/j.cma.2024.116813>`_.
6061
6162
.. note::
6263
This class is only compatible with problems that inherit from the
63-
:class:`~pina.problem.TimeDependentProblem` class.
64+
:class:`~pina.problem.time_dependent_problem.TimeDependentProblem`
65+
class.
6466
"""
6567

6668
def __init__(
@@ -77,17 +79,19 @@ def __init__(
7779
Initialization of the :class:`CausalPINN` class.
7880
7981
:param AbstractProblem problem: The problem to be solved. It must
80-
inherit from at least :class:`~pina.problem.TimeDependentProblem`.
82+
inherit from at least
83+
:class:`~pina.problem.time_dependent_problem.TimeDependentProblem`.
8184
:param torch.nn.Module model: The neural network model to be used.
82-
:param torch.optim.Optimizer optimizer: The optimizer to be used
83-
If `None`, the Adam optimizer is used. Default is ``None``.
84-
:param torch.optim.LRScheduler scheduler: Learning rate scheduler.
85-
If `None`, the constant learning rate scheduler is used.
85+
:param Optimizer optimizer: The optimizer to be used.
86+
If `None`, the :class:`torch.optim.Adam` optimizer is used.
8687
Default is ``None``.
88+
:param torch.optim.LRScheduler scheduler: Learning rate scheduler.
89+
If `None`, the :class:`torch.optim.lr_scheduler.ConstantLR`
90+
scheduler is used. Default is ``None``.
8791
:param WeightingInterface weighting: The weighting schema to be used.
8892
If `None`, no weighting schema is used. Default is ``None``.
8993
:param torch.nn.Module loss: The loss function to be minimized.
90-
If `None`, the Mean Squared Error (MSE) loss is used.
94+
If `None`, the :class:`torch.nn.MSELoss` loss is used.
9195
Default is `None`.
9296
:param float eps: The exponential decay parameter. Default is ``100``.
9397
:raises ValueError: If the problem is not a TimeDependentProblem.

pina/solver/physic_informed_solver/competitive_pinn.py

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ class CompetitivePINN(PINNInterface, MultiSolverInterface):
4646
.. seealso::
4747
4848
**Original reference**: Zeng, Qi, et al.
49-
"Competitive physics informed networks." International Conference on
50-
Learning Representations, ICLR 2022
49+
*Competitive physics informed networks.*
50+
International Conference on Learning Representations, ICLR 2022
5151
`OpenReview Preprint <https://openreview.net/forum?id=z9SIj-IM7tn>`_.
5252
"""
5353

@@ -72,21 +72,23 @@ def __init__(
7272
If `None`, the discriminator is a deepcopy of the ``model``.
7373
Default is ``None``.
7474
:param torch.optim.Optimizer optimizer_model: The optimizer of the
75-
``model``. If `None`, the Adam optimizer is used.
76-
Default is ``None``.
75+
``model``. If `None`, the :class:`torch.optim.Adam` optimizer is
76+
used. Default is ``None``.
7777
:param torch.optim.Optimizer optimizer_discriminator: The optimizer of
78-
the ``discriminator``. If `None`, the Adam optimizer is used.
79-
Default is ``None``.
80-
:param torch.optim.LRScheduler scheduler_model: Learning rate scheduler
81-
for the ``model``. If `None`, the constant learning rate scheduler
82-
is used. Default is ``None``.
83-
:param torch.optim.LRScheduler scheduler_discriminator: Learning rate
84-
scheduler for the ``discriminator``. If `None`, the constant
85-
learning rate scheduler is used. Default is ``None``.
78+
the ``discriminator``. If `None`, the :class:`torch.optim.Adam`
79+
optimizer is used. Default is ``None``.
80+
:param Scheduler scheduler_model: Learning rate scheduler for the
81+
``model``.
82+
If `None`, the :class:`torch.optim.lr_scheduler.ConstantLR`
83+
scheduler is used. Default is ``None``.
84+
:param Scheduler scheduler_discriminator: Learning rate scheduler for
85+
the ``discriminator``.
86+
If `None`, the :class:`torch.optim.lr_scheduler.ConstantLR`
87+
scheduler is used. Default is ``None``.
8688
:param WeightingInterface weighting: The weighting schema to be used.
8789
If `None`, no weighting schema is used. Default is ``None``.
8890
:param torch.nn.Module loss: The loss function to be minimized.
89-
If `None`, the Mean Squared Error (MSE) loss is used.
91+
If `None`, the :class:`torch.nn.MSELoss` loss is used.
9092
Default is `None`.
9193
"""
9294
if discriminator is None:
@@ -118,7 +120,8 @@ def training_step(self, batch):
118120
"""
119121
Solver training step, overridden to perform manual optimization.
120122
121-
:param dict batch: The batch element in the dataloader.
123+
:param list[tuple[str, dict]] batch: A batch of data. Each element is a
124+
tuple containing a condition name and a dictionary of points.
122125
:return: The aggregated loss.
123126
:rtype: LabelTensor
124127
"""
@@ -163,7 +166,7 @@ def configure_optimizers(self):
163166
Optimizer configuration.
164167
165168
:return: The optimizers and the schedulers
166-
:rtype: tuple(list, list)
169+
:rtype: tuple[list[Optimizer], list[Scheduler]]
167170
"""
168171
# If the problem is an InverseProblem, add the unknown parameters
169172
# to the parameters to be optimized
@@ -198,7 +201,8 @@ def on_train_batch_end(self, outputs, batch, batch_idx):
198201
199202
:param torch.Tensor outputs: The ``model``'s output for the current
200203
batch.
201-
:param dict batch: The current batch of data.
204+
:param list[tuple[str, dict]] batch: A batch of data. Each element is a
205+
tuple containing a condition name and a dictionary of points.
202206
:param int batch_idx: The index of the current batch.
203207
"""
204208
# increase by one the counter of optimization to save loggers
@@ -234,7 +238,7 @@ def optimizer_model(self):
234238
The optimizer associated to the model.
235239
236240
:return: The optimizer for the model.
237-
:rtype: torch.optim.Optimizer
241+
:rtype: Optimizer
238242
"""
239243
return self.optimizers[0]
240244

@@ -244,7 +248,7 @@ def optimizer_discriminator(self):
244248
The optimizer associated to the discriminator.
245249
246250
:return: The optimizer for the discriminator.
247-
:rtype: torch.optim.Optimizer
251+
:rtype: Optimizer
248252
"""
249253
return self.optimizers[1]
250254

@@ -254,7 +258,7 @@ def scheduler_model(self):
254258
The scheduler associated to the model.
255259
256260
:return: The scheduler for the model.
257-
:rtype: torch.optim.lr_scheduler._LRScheduler
261+
:rtype: Scheduler
258262
"""
259263
return self.schedulers[0]
260264

@@ -264,6 +268,6 @@ def scheduler_discriminator(self):
264268
The scheduler associated to the discriminator.
265269
266270
:return: The scheduler for the discriminator.
267-
:rtype: torch.optim.lr_scheduler._LRScheduler
271+
:rtype: Scheduler
268272
"""
269273
return self.schedulers[1]

pina/solver/physic_informed_solver/gradient_pinn.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ class GradientPINN(PINN):
4646
4747
.. seealso::
4848
49-
**Original reference**: Yu, Jeremy, et al. "Gradient-enhanced
50-
physics-informed neural networks for forward and inverse
51-
PDE problems." Computer Methods in Applied Mechanics
52-
and Engineering 393 (2022): 114823.
49+
**Original reference**: Yu, Jeremy, et al.
50+
*Gradient-enhanced physics-informed neural networks for forward and
51+
inverse PDE problems.*
52+
Computer Methods in Applied Mechanics and Engineering 393 (2022):114823.
5353
DOI: `10.1016 <https://doi.org/10.1016/j.cma.2022.114823>`_.
5454
5555
.. note::
5656
This class is only compatible with problems that inherit from the
57-
:class:`~pina.problem.SpatialProblem` class.
57+
:class:`~pina.problem.spatial_problem.SpatialProblem` class.
5858
"""
5959

6060
def __init__(
@@ -70,18 +70,20 @@ def __init__(
7070
Initialization of the :class:`GradientPINN` class.
7171
7272
:param AbstractProblem problem: The problem to be solved.
73-
It must inherit from at least :class:`~pina.problem.SpatialProblem`
74-
to compute the gradient of the loss.
73+
It must inherit from at least
74+
:class:`~pina.problem.spatial_problem.SpatialProblem` to compute the
75+
gradient of the loss.
7576
:param torch.nn.Module model: The neural network model to be used.
76-
:param torch.optim.Optimizer optimizer: The optimizer to be used.
77-
If `None`, the Adam optimizer is used. Default is ``None``.
78-
:param torch.optim.LRScheduler scheduler: Learning rate scheduler.
79-
If `None`, the constant learning rate scheduler is used.
77+
:param Optimizer optimizer: The optimizer to be used.
78+
If `None`, the :class:`torch.optim.Adam` optimizer is used.
8079
Default is ``None``.
80+
:param Scheduler scheduler: Learning rate scheduler.
81+
If `None`, the :class:`torch.optim.lr_scheduler.ConstantLR`
82+
scheduler is used. Default is ``None``.
8183
:param WeightingInterface weighting: The weighting schema to be used.
8284
If `None`, no weighting schema is used. Default is ``None``.
8385
:param torch.nn.Module loss: The loss function to be minimized.
84-
If `None`, the Mean Squared Error (MSE) loss is used.
86+
If `None`, the :class:`torch.nn.MSELoss` loss is used.
8587
Default is `None`.
8688
:raises ValueError: If the problem is not a SpatialProblem.
8789
"""

0 commit comments

Comments
 (0)