Renaming
* solvers -> solver * adaptive_functions -> adaptive_function * callbacks -> callback * operators -> operator * pinns -> physics_informed_solver * layers -> block
This commit is contained in:
committed by
Nicola Demo
parent
810d215ca0
commit
df673cad4e
@@ -10,6 +10,7 @@ __all__ = [
|
||||
|
||||
from .label_tensor import LabelTensor
|
||||
from .graph import Graph
|
||||
from .solvers.solver import SolverInterface, MultiSolverInterface
|
||||
from .solver import SolverInterface, MultiSolverInterface
|
||||
from .trainer import Trainer
|
||||
from .condition.condition import Condition
|
||||
from .data import PinaDataModule
|
||||
@@ -9,7 +9,7 @@ from abc import ABCMeta
|
||||
class AdaptiveActivationFunctionInterface(torch.nn.Module, metaclass=ABCMeta):
|
||||
r"""
|
||||
The
|
||||
:class:`~pina.adaptive_functions.adaptive_func_interface.AdaptiveActivationFunctionInterface`
|
||||
:class:`~pina.adaptive_function.adaptive_func_interface.AdaptiveActivationFunctionInterface`
|
||||
class makes a :class:`torch.nn.Module` activation function into an adaptive
|
||||
trainable activation function. If one wants to create an adpative activation
|
||||
function, this class must be use as base class.
|
||||
10
pina/callback/__init__.py
Normal file
10
pina/callback/__init__.py
Normal file
@@ -0,0 +1,10 @@
|
||||
__all__ = [
|
||||
"SwitchOptimizer",
|
||||
"R3Refinement",
|
||||
"MetricTracker",
|
||||
"PINAProgressBar",
|
||||
]
|
||||
|
||||
from .optimizer_callback import SwitchOptimizer
|
||||
from .adaptive_refinment_callback import R3Refinement
|
||||
from .processing_callback import MetricTracker, PINAProgressBar
|
||||
@@ -19,7 +19,7 @@ class SwitchOptimizer(Callback):
|
||||
|
||||
:param new_optimizers: The model optimizers to switch to. Can be a
|
||||
single :class:`torch.optim.Optimizer` or a list of them for multiple
|
||||
model solvers.
|
||||
model solver.
|
||||
:type new_optimizers: pina.optim.TorchOptimizer | list
|
||||
:param epoch_switch: The epoch at which to switch to the new optimizer.
|
||||
:type epoch_switch: int
|
||||
@@ -87,12 +87,12 @@ class PINAProgressBar(TQDMProgressBar):
|
||||
:Keyword Arguments:
|
||||
The additional keyword arguments specify the progress bar
|
||||
and can be choosen from the `pytorch-lightning
|
||||
TQDMProgressBar API <https://lightning.ai/docs/pytorch/stable/_modules/lightning/pytorch/callbacks/progress/tqdm_progress.html#TQDMProgressBar>`_
|
||||
TQDMProgressBar API <https://lightning.ai/docs/pytorch/stable/_modules/lightning/pytorch/callback/progress/tqdm_progress.html#TQDMProgressBar>`_
|
||||
|
||||
Example:
|
||||
>>> pbar = PINAProgressBar(['mean'])
|
||||
>>> # ... Perform training ...
|
||||
>>> trainer = Trainer(solver, callbacks=[pbar])
|
||||
>>> trainer = Trainer(solver, callback=[pbar])
|
||||
"""
|
||||
super().__init__(**kwargs)
|
||||
# check consistency
|
||||
@@ -1,10 +0,0 @@
|
||||
__all__ = [
|
||||
"SwitchOptimizer",
|
||||
"R3Refinement",
|
||||
"MetricTracker",
|
||||
"PINAProgressBar",
|
||||
]
|
||||
|
||||
from .optimizer_callbacks import SwitchOptimizer
|
||||
from .adaptive_refinment_callbacks import R3Refinement
|
||||
from .processing_callbacks import MetricTracker, PINAProgressBar
|
||||
@@ -27,7 +27,7 @@ class InputPointsEquationCondition(ConditionInterface):
|
||||
if key == 'input_points':
|
||||
check_consistency(
|
||||
value, (LabelTensor)
|
||||
) # for now only labeltensors, we need labels for the operators!
|
||||
) # for now only labeltensors, we need labels for the operator!
|
||||
InputPointsEquationCondition.__dict__[key].__set__(self, value)
|
||||
elif key == 'equation':
|
||||
check_consistency(value, (EquationInterface))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
""" Module """
|
||||
|
||||
from .equation import Equation
|
||||
from ..operators import grad, div, laplacian
|
||||
from ..operator import grad, div, laplacian
|
||||
|
||||
|
||||
class FixedValue(Equation):
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
|
||||
import torch
|
||||
from torch import nn, cat
|
||||
from .layers import AVNOBlock
|
||||
from .block import AVNOBlock
|
||||
from .base_no import KernelNeuralOperator
|
||||
from pina.utils import check_consistency
|
||||
from ..utils import check_consistency
|
||||
|
||||
|
||||
class AveragingNeuralOperator(KernelNeuralOperator):
|
||||
|
||||
@@ -3,14 +3,14 @@ Kernel Neural Operator Module.
|
||||
"""
|
||||
|
||||
import torch
|
||||
from pina.utils import check_consistency
|
||||
from ..utils import check_consistency
|
||||
|
||||
|
||||
class KernelNeuralOperator(torch.nn.Module):
|
||||
r"""
|
||||
Base class for composing Neural Operators with integral kernels.
|
||||
|
||||
This is a base class for composing neural operators with multiple
|
||||
This is a base class for composing neural operator with multiple
|
||||
integral kernels. All neural operator models defined in PINA inherit
|
||||
from this class. The structure is inspired by the work of Kovachki, N.
|
||||
et al. see Figure 2 of the reference for extra details. The Neural
|
||||
|
||||
35
pina/model/block/__init__.py
Normal file
35
pina/model/block/__init__.py
Normal file
@@ -0,0 +1,35 @@
|
||||
__all__ = [
|
||||
"ContinuousConvBlock",
|
||||
"ResidualBlock",
|
||||
"EnhancedLinear",
|
||||
"SpectralConvBlock1D",
|
||||
"SpectralConvBlock2D",
|
||||
"SpectralConvBlock3D",
|
||||
"FourierBlock1D",
|
||||
"FourierBlock2D",
|
||||
"FourierBlock3D",
|
||||
"PODBlock",
|
||||
"OrthogonalBlock",
|
||||
"PeriodicBoundaryEmbedding",
|
||||
"FourierFeatureEmbedding",
|
||||
"AVNOBlock",
|
||||
"LowRankBlock",
|
||||
"RBFBlock",
|
||||
"GNOBlock"
|
||||
]
|
||||
|
||||
from .convolution_2d import ContinuousConvBlock
|
||||
from .residual import ResidualBlock, EnhancedLinear
|
||||
from .spectral import (
|
||||
SpectralConvBlock1D,
|
||||
SpectralConvBlock2D,
|
||||
SpectralConvBlock3D,
|
||||
)
|
||||
from .fourier import FourierBlock1D, FourierBlock2D, FourierBlock3D
|
||||
from .pod import PODBlock
|
||||
from .orthogonal import OrthogonalBlock
|
||||
from .embedding import PeriodicBoundaryEmbedding, FourierFeatureEmbedding
|
||||
from .avno_layer import AVNOBlock
|
||||
from .lowrank_layer import LowRankBlock
|
||||
from .rbf_layer import RBFBlock
|
||||
from .gno_block import GNOBlock
|
||||
@@ -2,7 +2,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
from ...utils import check_consistency
|
||||
|
||||
from pina.model.layers import (
|
||||
from pina.model.block import (
|
||||
SpectralConvBlock1D,
|
||||
SpectralConvBlock2D,
|
||||
SpectralConvBlock3D,
|
||||
@@ -18,7 +18,7 @@ class MIONet(torch.nn.Module):
|
||||
.. seealso::
|
||||
|
||||
**Original reference**: Jin, Pengzhan, Shuai Meng, and Lu Lu.
|
||||
*MIONet: Learning multiple-input operators via tensor product.*
|
||||
*MIONet: Learning multiple-input operator via tensor product.*
|
||||
SIAM Journal on Scientific Computing 44.6 (2022): A3490-A351
|
||||
DOI: `10.1137/22M1477751
|
||||
<https://doi.org/10.1137/22M1477751>`_
|
||||
@@ -289,8 +289,8 @@ class DeepONet(MIONet):
|
||||
.. seealso::
|
||||
|
||||
**Original reference**: Lu, L., Jin, P., Pang, G. et al. *Learning
|
||||
nonlinear operators via DeepONet based on the universal approximation
|
||||
theorem of operators*. Nat Mach Intell 3, 218–229 (2021).
|
||||
nonlinear operator via DeepONet based on the universal approximation
|
||||
theorem of operator*. Nat Mach Intell 3, 218–229 (2021).
|
||||
DOI: `10.1038/s42256-021-00302-5
|
||||
<https://doi.org/10.1038/s42256-021-00302-5>`_
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from ..utils import check_consistency
|
||||
from .layers.residual import EnhancedLinear
|
||||
from .block.residual import EnhancedLinear
|
||||
|
||||
|
||||
class FeedForward(torch.nn.Module):
|
||||
|
||||
@@ -7,7 +7,7 @@ import torch.nn as nn
|
||||
from ..label_tensor import LabelTensor
|
||||
import warnings
|
||||
from ..utils import check_consistency
|
||||
from .layers.fourier import FourierBlock1D, FourierBlock2D, FourierBlock3D
|
||||
from .block.fourier import FourierBlock1D, FourierBlock2D, FourierBlock3D
|
||||
from .base_no import KernelNeuralOperator
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import torch
|
||||
from torch.nn import Tanh
|
||||
from .layers import GNOBlock
|
||||
from .block import GNOBlock
|
||||
from .base_no import KernelNeuralOperator
|
||||
|
||||
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
__all__ = [
|
||||
"ContinuousConvBlock",
|
||||
"ResidualBlock",
|
||||
"EnhancedLinear",
|
||||
"SpectralConvBlock1D",
|
||||
"SpectralConvBlock2D",
|
||||
"SpectralConvBlock3D",
|
||||
"FourierBlock1D",
|
||||
"FourierBlock2D",
|
||||
"FourierBlock3D",
|
||||
"PODBlock",
|
||||
"OrthogonalBlock",
|
||||
"PeriodicBoundaryEmbedding",
|
||||
"FourierFeatureEmbedding",
|
||||
"AVNOBlock",
|
||||
"LowRankBlock",
|
||||
"RBFBlock",
|
||||
"GNOBlock"
|
||||
]
|
||||
|
||||
from .convolution_2d import ContinuousConvBlock
|
||||
from .residual import ResidualBlock, EnhancedLinear
|
||||
from .spectral import (
|
||||
SpectralConvBlock1D,
|
||||
SpectralConvBlock2D,
|
||||
SpectralConvBlock3D,
|
||||
)
|
||||
from .fourier import FourierBlock1D, FourierBlock2D, FourierBlock3D
|
||||
from .pod import PODBlock
|
||||
from .orthogonal import OrthogonalBlock
|
||||
from .embedding import PeriodicBoundaryEmbedding, FourierFeatureEmbedding
|
||||
from .avno_layer import AVNOBlock
|
||||
from .lowrank_layer import LowRankBlock
|
||||
from .rbf_layer import RBFBlock
|
||||
from .gno_block import GNOBlock
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
import torch
|
||||
from torch import nn, cat
|
||||
|
||||
from pina.utils import check_consistency
|
||||
from ..utils import check_consistency
|
||||
|
||||
from .base_no import KernelNeuralOperator
|
||||
from .layers.lowrank_layer import LowRankBlock
|
||||
from .block.lowrank_layer import LowRankBlock
|
||||
|
||||
|
||||
class LowRankNeuralOperator(KernelNeuralOperator):
|
||||
@@ -19,7 +19,7 @@ class LowRankNeuralOperator(KernelNeuralOperator):
|
||||
to other functions. It can be trained with Supervised or PINN based
|
||||
learning strategies.
|
||||
LowRankNeuralOperator does convolution by performing a low rank
|
||||
approximation, see :class:`~pina.model.layers.lowrank_layer.LowRankBlock`.
|
||||
approximation, see :class:`~pina.model.block.lowrank_layer.LowRankBlock`.
|
||||
|
||||
.. seealso::
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
"""Module for Spline model"""
|
||||
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from ..utils import check_consistency
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Module for operators vectorize implementation. Differential operators are used to write any differential problem.
|
||||
These operators are implemented to work on different accellerators: CPU, GPU, TPU or MPS.
|
||||
All operators take as input a tensor onto which computing the operator, a tensor with respect
|
||||
Module for operator vectorize implementation. Differential operator are used to write any differential problem.
|
||||
These operator are implemented to work on different accellerators: CPU, GPU, TPU or MPS.
|
||||
All operator take as input a tensor onto which computing the operator, a tensor with respect
|
||||
to which computing the operator, the name of the output variables to calculate the operator
|
||||
for (in case of multidimensional functions), and the variables name on which the operator is calculated.
|
||||
"""
|
||||
@@ -16,7 +16,7 @@ class InverseProblem(AbstractProblem):
|
||||
|
||||
:Example:
|
||||
>>> from pina.problem import SpatialProblem, InverseProblem
|
||||
>>> from pina.operators import grad
|
||||
>>> from pina.operator import grad
|
||||
>>> from pina.equation import ParametricEquation, FixedValue
|
||||
>>> from pina import Condition
|
||||
>>> from pina.geometry import CartesianDomain
|
||||
|
||||
@@ -16,7 +16,7 @@ class ParametricProblem(AbstractProblem):
|
||||
|
||||
:Example:
|
||||
>>> from pina.problem import SpatialProblem, ParametricProblem
|
||||
>>> from pina.operators import grad
|
||||
>>> from pina.operator import grad
|
||||
>>> from pina.equations import Equation, FixedValue
|
||||
>>> from pina import Condition
|
||||
>>> from pina.geometry import CartesianDomain
|
||||
|
||||
@@ -14,7 +14,7 @@ class SpatialProblem(AbstractProblem):
|
||||
|
||||
:Example:
|
||||
>>> from pina.problem import SpatialProblem
|
||||
>>> from pina.operators import grad
|
||||
>>> from pina.operator import grad
|
||||
>>> from pina.equation import Equation, FixedValue
|
||||
>>> from pina import Condition
|
||||
>>> from pina.geometry import CartesianDomain
|
||||
|
||||
@@ -14,7 +14,7 @@ class TimeDependentProblem(AbstractProblem):
|
||||
|
||||
:Example:
|
||||
>>> from pina.problem import SpatialProblem, TimeDependentProblem
|
||||
>>> from pina.operators import grad, laplacian
|
||||
>>> from pina.operator import grad, laplacian
|
||||
>>> from pina.equation import Equation, FixedValue
|
||||
>>> from pina import Condition
|
||||
>>> from pina.geometry import CartesianDomain
|
||||
|
||||
@@ -5,7 +5,7 @@ from pina import Condition
|
||||
from pina.problem import SpatialProblem, TimeDependentProblem
|
||||
from pina.equation.equation import Equation
|
||||
from pina.domain import CartesianDomain
|
||||
from pina.operators import grad
|
||||
from pina.operator import grad
|
||||
|
||||
def diffusion_reaction(input_, output_):
|
||||
"""
|
||||
|
||||
@@ -5,7 +5,7 @@ from pina import Condition, LabelTensor
|
||||
from pina.problem import SpatialProblem, TimeDependentProblem, InverseProblem
|
||||
from pina.equation.equation import Equation
|
||||
from pina.domain import CartesianDomain
|
||||
from pina.operators import grad
|
||||
from pina.operator import grad
|
||||
|
||||
def diffusion_reaction(input_, output_):
|
||||
"""
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import torch
|
||||
from pina import Condition, LabelTensor
|
||||
from pina.problem import SpatialProblem, InverseProblem
|
||||
from pina.operators import laplacian
|
||||
from pina.operator import laplacian
|
||||
from pina.domain import CartesianDomain
|
||||
from pina.equation.equation import Equation
|
||||
from pina.equation.equation_factory import FixedValue
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
""" Definition of the Poisson problem on a square domain."""
|
||||
|
||||
from pina.problem import SpatialProblem
|
||||
from pina.operators import laplacian
|
||||
from pina.operator import laplacian
|
||||
from pina import Condition
|
||||
from pina.domain import CartesianDomain
|
||||
from pina.equation.equation import Equation
|
||||
|
||||
@@ -15,7 +15,7 @@ __all__ = [
|
||||
]
|
||||
|
||||
from .solver import SolverInterface, SingleSolverInterface, MultiSolverInterface
|
||||
from .pinns import *
|
||||
from .physic_informed_solver import *
|
||||
from .supervised import SupervisedSolver
|
||||
from .rom import ReducedOrderModelSolver
|
||||
from .garom import GAROM
|
||||
@@ -11,7 +11,7 @@ class CausalPINN(PINN):
|
||||
r"""
|
||||
Causal Physics Informed Neural Network (CausalPINN) solver class.
|
||||
This class implements Causal Physics Informed Neural
|
||||
Network solvers, using a user specified ``model`` to solve a specific
|
||||
Network solver, using a user specified ``model`` to solve a specific
|
||||
``problem``. It can be used for solving both forward and inverse problems.
|
||||
|
||||
The Causal Physics Informed Network aims to find
|
||||
@@ -12,7 +12,7 @@ class CompetitivePINN(PINNInterface, MultiSolverInterface):
|
||||
r"""
|
||||
Competitive Physics Informed Neural Network (PINN) solver class.
|
||||
This class implements Competitive Physics Informed Neural
|
||||
Network solvers, using a user specified ``model`` to solve a specific
|
||||
Network solver, using a user specified ``model`` to solve a specific
|
||||
``problem``. It can be used for solving both forward and inverse problems.
|
||||
|
||||
The Competitive Physics Informed Network aims to find
|
||||
@@ -3,7 +3,7 @@
|
||||
import torch
|
||||
|
||||
from .pinn import PINN
|
||||
from pina.operators import grad
|
||||
from pina.operator import grad
|
||||
from pina.problem import SpatialProblem
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ class GradientPINN(PINN):
|
||||
r"""
|
||||
Gradient Physics Informed Neural Network (GradientPINN) solver class.
|
||||
This class implements Gradient Physics Informed Neural
|
||||
Network solvers, using a user specified ``model`` to solve a specific
|
||||
Network solver, using a user specified ``model`` to solve a specific
|
||||
``problem``. It can be used for solving both forward and inverse problems.
|
||||
|
||||
The Gradient Physics Informed Network aims to find
|
||||
@@ -11,7 +11,7 @@ class PINN(PINNInterface, SingleSolverInterface):
|
||||
r"""
|
||||
Physics Informed Neural Network (PINN) solver class.
|
||||
This class implements Physics Informed Neural
|
||||
Network solvers, using a user specified ``model`` to solve a specific
|
||||
Network solver, using a user specified ``model`` to solve a specific
|
||||
``problem``. It can be used for solving both forward and inverse problems.
|
||||
|
||||
The Physics Informed Network aims to find
|
||||
@@ -18,7 +18,7 @@ from ...condition import (
|
||||
class PINNInterface(SolverInterface, metaclass=ABCMeta):
|
||||
"""
|
||||
Base PINN solver class. This class implements the Solver Interface
|
||||
for Physics Informed Neural Network solvers.
|
||||
for Physics Informed Neural Network solver.
|
||||
|
||||
This class can be used to define PINNs with multiple ``optimizers``,
|
||||
and/or ``models``.
|
||||
@@ -11,7 +11,7 @@ class RBAPINN(PINN):
|
||||
r"""
|
||||
Residual-based Attention PINN (RBAPINN) solver class.
|
||||
This class implements Residual-based Attention Physics Informed Neural
|
||||
Network solvers, using a user specified ``model`` to solve a specific
|
||||
Network solver, using a user specified ``model`` to solve a specific
|
||||
``problem``. It can be used for solving both forward and inverse problems.
|
||||
|
||||
The Residual-based Attention Physics Informed Neural Network aims to find
|
||||
@@ -39,7 +39,7 @@ class SelfAdaptivePINN(PINNInterface, MultiSolverInterface):
|
||||
r"""
|
||||
Self Adaptive Physics Informed Neural Network (SelfAdaptivePINN)
|
||||
solver class. This class implements Self-Adaptive Physics Informed Neural
|
||||
Network solvers, using a user specified ``model`` to solve a specific
|
||||
Network solver, using a user specified ``model`` to solve a specific
|
||||
``problem``. It can be used for solving both forward and inverse problems.
|
||||
|
||||
The Self Adapive Physics Informed Neural Network aims to find
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import torch
|
||||
|
||||
from pina.solvers import SupervisedSolver
|
||||
from pina.solver import SupervisedSolver
|
||||
|
||||
|
||||
class ReducedOrderModelSolver(SupervisedSolver):
|
||||
@@ -15,7 +15,7 @@ class SupervisedSolver(SingleSolverInterface):
|
||||
The Supervised Solver class aims to find
|
||||
a map between the input :math:`\mathbf{s}:\Omega\rightarrow\mathbb{R}^m`
|
||||
and the output :math:`\mathbf{u}:\Omega\rightarrow\mathbb{R}^m`. The input
|
||||
can be discretised in space (as in :obj:`~pina.solvers.rom.ROMe2eSolver`),
|
||||
can be discretised in space (as in :obj:`~pina.solver.rom.ROMe2eSolver`),
|
||||
or not (e.g. when training Neural Operators).
|
||||
|
||||
Given a model :math:`\mathcal{M}`, the following loss function is
|
||||
@@ -4,7 +4,7 @@ import torch
|
||||
import lightning
|
||||
from .utils import check_consistency
|
||||
from .data import PinaDataModule
|
||||
from .solvers import SolverInterface, PINNInterface
|
||||
from .solver import SolverInterface, PINNInterface
|
||||
|
||||
|
||||
class Trainer(lightning.pytorch.Trainer):
|
||||
|
||||
@@ -7,6 +7,10 @@ from functools import reduce
|
||||
from .label_tensor import LabelTensor
|
||||
|
||||
|
||||
def custom_warning_format(
|
||||
message, category, filename, lineno, file=None, line=None
|
||||
):
|
||||
return f"{filename}: {category.__name__}: {message}\n"
|
||||
|
||||
def check_consistency(object, object_instance, subclass=False):
|
||||
"""Helper function to check object inheritance consistency.
|
||||
|
||||
Reference in New Issue
Block a user