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.
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina.adaptive_functions import (AdaptiveReLU, AdaptiveSigmoid, AdaptiveTanh,
|
||||
from pina.adaptive_function import (AdaptiveReLU, AdaptiveSigmoid, AdaptiveTanh,
|
||||
AdaptiveSiLU, AdaptiveMish, AdaptiveELU,
|
||||
AdaptiveCELU, AdaptiveGELU, AdaptiveSoftmin,
|
||||
AdaptiveSoftmax, AdaptiveSIREN, AdaptiveExp)
|
||||
|
||||
|
||||
adaptive_functions = (AdaptiveReLU, AdaptiveSigmoid, AdaptiveTanh,
|
||||
adaptive_function = (AdaptiveReLU, AdaptiveSigmoid, AdaptiveTanh,
|
||||
AdaptiveSiLU, AdaptiveMish, AdaptiveELU,
|
||||
AdaptiveCELU, AdaptiveGELU, AdaptiveSoftmin,
|
||||
AdaptiveSoftmax, AdaptiveSIREN, AdaptiveExp)
|
||||
x = torch.rand(10, requires_grad=True)
|
||||
|
||||
@pytest.mark.parametrize("Func", adaptive_functions)
|
||||
@pytest.mark.parametrize("Func", adaptive_function)
|
||||
def test_constructor(Func):
|
||||
if Func.__name__ == 'AdaptiveExp':
|
||||
# simple
|
||||
@@ -50,12 +50,12 @@ def test_constructor(Func):
|
||||
Func(alpha='s')
|
||||
Func(alpha=1)
|
||||
|
||||
@pytest.mark.parametrize("Func", adaptive_functions)
|
||||
@pytest.mark.parametrize("Func", adaptive_function)
|
||||
def test_forward(Func):
|
||||
af = Func()
|
||||
af(x)
|
||||
|
||||
@pytest.mark.parametrize("Func", adaptive_functions)
|
||||
@pytest.mark.parametrize("Func", adaptive_function)
|
||||
def test_backward(Func):
|
||||
af = Func()
|
||||
y = af(x)
|
||||
@@ -1,4 +1,4 @@
|
||||
from pina.model.layers import ContinuousConvBlock
|
||||
from pina.model.block import ContinuousConvBlock
|
||||
import torch
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina.model.layers import PeriodicBoundaryEmbedding, FourierFeatureEmbedding
|
||||
from pina.model.block import PeriodicBoundaryEmbedding, FourierFeatureEmbedding
|
||||
|
||||
# test tolerance
|
||||
tol = 1e-6
|
||||
@@ -1,4 +1,4 @@
|
||||
from pina.model.layers import FourierBlock1D, FourierBlock2D, FourierBlock3D
|
||||
from pina.model.block import FourierBlock1D, FourierBlock2D, FourierBlock3D
|
||||
import torch
|
||||
|
||||
input_numb_fields = 3
|
||||
@@ -1,7 +1,7 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina.model.layers import LowRankBlock
|
||||
from pina.model.block import LowRankBlock
|
||||
from pina import LabelTensor
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import torch
|
||||
import pytest
|
||||
from pina.model.layers import OrthogonalBlock
|
||||
from pina.model.block import OrthogonalBlock
|
||||
|
||||
torch.manual_seed(111)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina.model.layers.pod import PODBlock
|
||||
from pina.model.block.pod import PODBlock
|
||||
|
||||
x = torch.linspace(-1, 1, 100)
|
||||
toy_snapshots = torch.vstack([torch.exp(-x**2)*c for c in torch.linspace(0, 1, 10)])
|
||||
@@ -2,7 +2,7 @@ import torch
|
||||
import pytest
|
||||
import math
|
||||
|
||||
from pina.model.layers.rbf_layer import RBFBlock
|
||||
from pina.model.block.rbf_layer import RBFBlock
|
||||
|
||||
x = torch.linspace(-1, 1, 100)
|
||||
toy_params = torch.linspace(0, 1, 10).unsqueeze(1)
|
||||
@@ -1,4 +1,4 @@
|
||||
from pina.model.layers import ResidualBlock, EnhancedLinear
|
||||
from pina.model.block import ResidualBlock, EnhancedLinear
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from pina.model.layers import SpectralConvBlock1D, SpectralConvBlock2D, SpectralConvBlock3D
|
||||
from pina.model.block import SpectralConvBlock1D, SpectralConvBlock2D, SpectralConvBlock3D
|
||||
import torch
|
||||
|
||||
input_numb_fields = 3
|
||||
@@ -1,8 +1,8 @@
|
||||
from pina.solvers import PINN
|
||||
from pina.solver import PINN
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.problem.zoo import Poisson2DSquareProblem as Poisson
|
||||
from pina.callbacks import R3Refinement
|
||||
from pina.callback import R3Refinement
|
||||
|
||||
|
||||
# make the problem
|
||||
@@ -25,7 +25,7 @@ solver = PINN(problem=poisson_problem, model=model)
|
||||
# def test_r3refinment_routine():
|
||||
# # make the trainer
|
||||
# trainer = Trainer(solver=solver,
|
||||
# callbacks=[R3Refinement(sample_every=1)],
|
||||
# callback=[R3Refinement(sample_every=1)],
|
||||
# accelerator='cpu',
|
||||
# max_epochs=5)
|
||||
# trainer.train()
|
||||
@@ -35,7 +35,7 @@ solver = PINN(problem=poisson_problem, model=model)
|
||||
# len(poisson_problem.output_variables))
|
||||
# solver = PINN(problem=poisson_problem, model=model)
|
||||
# trainer = Trainer(solver=solver,
|
||||
# callbacks=[R3Refinement(sample_every=1)],
|
||||
# callback=[R3Refinement(sample_every=1)],
|
||||
# accelerator='cpu',
|
||||
# max_epochs=5)
|
||||
# before_n_points = {loc : len(pts) for loc, pts in trainer.solver.problem.input_pts.items()}
|
||||
@@ -1,7 +1,7 @@
|
||||
from pina.solvers import PINN
|
||||
from pina.solver import PINN
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.callbacks import MetricTracker
|
||||
from pina.callback import MetricTracker
|
||||
from pina.problem.zoo import Poisson2DSquareProblem as Poisson
|
||||
|
||||
|
||||
@@ -24,14 +24,14 @@ def test_metric_tracker_constructor():
|
||||
# def test_metric_tracker_routine(): #TODO revert
|
||||
# # make the trainer
|
||||
# trainer = Trainer(solver=solver,
|
||||
# callbacks=[
|
||||
# callback=[
|
||||
# MetricTracker()
|
||||
# ],
|
||||
# accelerator='cpu',
|
||||
# max_epochs=5)
|
||||
# trainer.train()
|
||||
# # get the tracked metrics
|
||||
# metrics = trainer.callbacks[0].metrics
|
||||
# metrics = trainer.callback[0].metrics
|
||||
# # assert the logged metrics are correct
|
||||
# logged_metrics = sorted(list(metrics.keys()))
|
||||
# assert logged_metrics == ['train_loss_epoch', 'train_loss_step', 'val_loss']
|
||||
@@ -1,8 +1,8 @@
|
||||
from pina.callbacks import SwitchOptimizer
|
||||
from pina.callback import SwitchOptimizer
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
from pina.solvers import PINN
|
||||
from pina.solver import PINN
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.problem.zoo import Poisson2DSquareProblem as Poisson
|
||||
@@ -31,7 +31,7 @@ def test_switch_optimizer_constructor():
|
||||
# # make the trainer
|
||||
# switch_opt_callback = SwitchOptimizer(lbfgs_optimizer, epoch_switch=3)
|
||||
# trainer = Trainer(solver=solver,
|
||||
# callbacks=[switch_opt_callback],
|
||||
# callback=[switch_opt_callback],
|
||||
# accelerator='cpu',
|
||||
# max_epochs=5)
|
||||
# trainer.train()
|
||||
@@ -1,7 +1,7 @@
|
||||
from pina.solvers import PINN
|
||||
from pina.solver import PINN
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.callbacks.processing_callbacks import PINAProgressBar
|
||||
from pina.callback.processing_callback import PINAProgressBar
|
||||
from pina.problem.zoo import Poisson2DSquareProblem as Poisson
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ from pina.problem.zoo import Poisson2DSquareProblem as Poisson
|
||||
# def test_progress_bar_routine():
|
||||
# # make the trainer
|
||||
# trainer = Trainer(solver=solver,
|
||||
# callbacks=[
|
||||
# callback=[
|
||||
# PINAProgressBar(['mean', 'laplace_D'])
|
||||
# ],
|
||||
# accelerator='cpu',
|
||||
@@ -7,7 +7,7 @@ from pina.problem import AbstractProblem, SpatialProblem
|
||||
from pina.domain import CartesianDomain
|
||||
from pina.equation.equation import Equation
|
||||
from pina.equation.equation_factory import FixedValue
|
||||
from pina.operators import laplacian
|
||||
from pina.operator import laplacian
|
||||
from pina.collector import Collector
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from pina.problem.zoo import SupervisedProblem
|
||||
from pina.graph import RadiusGraph
|
||||
from pina.data.data_module import DummyDataloader
|
||||
from pina import Trainer
|
||||
from pina.solvers import SupervisedSolver
|
||||
from pina.solver import SupervisedSolver
|
||||
from torch_geometric.data import Batch
|
||||
from torch.utils.data import DataLoader
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pina.equation import Equation
|
||||
from pina.operators import grad, laplacian
|
||||
from pina.operator import grad, laplacian
|
||||
from pina import LabelTensor
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from pina.equation import SystemEquation
|
||||
from pina.operators import grad, laplacian
|
||||
from pina.operator import grad, laplacian
|
||||
from pina import LabelTensor
|
||||
import torch
|
||||
import pytest
|
||||
|
||||
@@ -2,7 +2,7 @@ import torch
|
||||
import pytest
|
||||
|
||||
from pina import LabelTensor
|
||||
from pina.operators import grad, div, laplacian
|
||||
from pina.operator import grad, div, laplacian
|
||||
|
||||
|
||||
def func_vector(x):
|
||||
@@ -3,7 +3,7 @@ import pytest
|
||||
|
||||
from pina import LabelTensor, Condition
|
||||
from pina.problem import SpatialProblem
|
||||
from pina.solvers import CausalPINN
|
||||
from pina.solver import CausalPINN
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.problem.zoo import (
|
||||
@@ -118,7 +118,7 @@ def test_solver_test(problem, batch_size, compile):
|
||||
|
||||
@pytest.mark.parametrize("problem", [problem, inverse_problem])
|
||||
def test_train_load_restore(problem):
|
||||
dir = "tests/test_solvers/tmp"
|
||||
dir = "tests/test_solver/tmp"
|
||||
problem = problem
|
||||
solver = CausalPINN(model=model, problem=problem)
|
||||
trainer = Trainer(solver=solver,
|
||||
@@ -153,4 +153,4 @@ def test_train_load_restore(problem):
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -2,7 +2,7 @@ import torch
|
||||
import pytest
|
||||
|
||||
from pina import LabelTensor, Condition
|
||||
from pina.solvers import CompetitivePINN as CompPINN
|
||||
from pina.solver import CompetitivePINN as CompPINN
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.problem.zoo import (
|
||||
@@ -107,7 +107,7 @@ def test_solver_test(problem, batch_size, compile):
|
||||
|
||||
@pytest.mark.parametrize("problem", [problem, inverse_problem])
|
||||
def test_train_load_restore(problem):
|
||||
dir = "tests/test_solvers/tmp"
|
||||
dir = "tests/test_solver/tmp"
|
||||
problem = problem
|
||||
solver = CompPINN(problem=problem, model=model)
|
||||
trainer = Trainer(solver=solver,
|
||||
@@ -142,4 +142,4 @@ def test_train_load_restore(problem):
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -3,7 +3,7 @@ import torch.nn as nn
|
||||
|
||||
import pytest
|
||||
from pina import Condition, LabelTensor
|
||||
from pina.solvers import GAROM
|
||||
from pina.solver import GAROM
|
||||
from pina.condition import InputOutputPointsCondition
|
||||
from pina.problem import AbstractProblem
|
||||
from pina.model import FeedForward
|
||||
@@ -141,7 +141,7 @@ def test_solver_test(batch_size, compile):
|
||||
|
||||
|
||||
def test_train_load_restore():
|
||||
dir = "tests/test_solvers/tmp/"
|
||||
dir = "tests/test_solver/tmp/"
|
||||
problem = TensorProblem()
|
||||
solver = GAROM(problem=TensorProblem(),
|
||||
generator=Generator(),
|
||||
@@ -174,4 +174,4 @@ def test_train_load_restore():
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -3,7 +3,7 @@ import torch
|
||||
|
||||
from pina import LabelTensor, Condition
|
||||
from pina.problem import TimeDependentProblem
|
||||
from pina.solvers import GradientPINN
|
||||
from pina.solver import GradientPINN
|
||||
from pina.model import FeedForward
|
||||
from pina.trainer import Trainer
|
||||
from pina.problem.zoo import (
|
||||
@@ -117,7 +117,7 @@ def test_solver_test(problem, batch_size, compile):
|
||||
|
||||
@pytest.mark.parametrize("problem", [problem, inverse_problem])
|
||||
def test_train_load_restore(problem):
|
||||
dir = "tests/test_solvers/tmp"
|
||||
dir = "tests/test_solver/tmp"
|
||||
problem = problem
|
||||
solver = GradientPINN(model=model, problem=problem)
|
||||
trainer = Trainer(solver=solver,
|
||||
@@ -152,4 +152,4 @@ def test_train_load_restore(problem):
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -4,7 +4,7 @@ import torch
|
||||
from pina import LabelTensor, Condition
|
||||
from pina.model import FeedForward
|
||||
from pina.trainer import Trainer
|
||||
from pina.solvers import PINN
|
||||
from pina.solver import PINN
|
||||
from pina.condition import (
|
||||
InputOutputPointsCondition,
|
||||
InputPointsEquationCondition,
|
||||
@@ -98,7 +98,7 @@ def test_solver_test(problem, batch_size, compile):
|
||||
|
||||
@pytest.mark.parametrize("problem", [problem, inverse_problem])
|
||||
def test_train_load_restore(problem):
|
||||
dir = "tests/test_solvers/tmp"
|
||||
dir = "tests/test_solver/tmp"
|
||||
problem = problem
|
||||
solver = PINN(model=model, problem=problem)
|
||||
trainer = Trainer(solver=solver,
|
||||
@@ -131,4 +131,4 @@ def test_train_load_restore(problem):
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -4,7 +4,7 @@ import torch
|
||||
from pina import LabelTensor, Condition
|
||||
from pina.model import FeedForward
|
||||
from pina.trainer import Trainer
|
||||
from pina.solvers import RBAPINN
|
||||
from pina.solver import RBAPINN
|
||||
from pina.condition import (
|
||||
InputOutputPointsCondition,
|
||||
InputPointsEquationCondition,
|
||||
@@ -119,7 +119,7 @@ def test_solver_test(problem, compile):
|
||||
|
||||
@pytest.mark.parametrize("problem", [problem, inverse_problem])
|
||||
def test_train_load_restore(problem):
|
||||
dir = "tests/test_solvers/tmp"
|
||||
dir = "tests/test_solver/tmp"
|
||||
problem = problem
|
||||
solver = RBAPINN(model=model, problem=problem)
|
||||
trainer = Trainer(solver=solver,
|
||||
@@ -154,4 +154,4 @@ def test_train_load_restore(problem):
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -4,7 +4,7 @@ import pytest
|
||||
from pina import Condition, LabelTensor
|
||||
from pina.problem import AbstractProblem
|
||||
from pina.condition import InputOutputPointsCondition
|
||||
from pina.solvers import ReducedOrderModelSolver
|
||||
from pina.solver import ReducedOrderModelSolver
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.problem.zoo import Poisson2DSquareProblem
|
||||
@@ -149,7 +149,7 @@ def test_solver_test(use_lt, compile):
|
||||
|
||||
|
||||
def test_train_load_restore():
|
||||
dir = "tests/test_solvers/tmp/"
|
||||
dir = "tests/test_solver/tmp/"
|
||||
problem = LabelTensorProblem()
|
||||
solver = ReducedOrderModelSolver(problem=problem,
|
||||
|
||||
@@ -184,4 +184,4 @@ def test_train_load_restore():
|
||||
solver.forward(test_pts))
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -2,7 +2,7 @@ import torch
|
||||
import pytest
|
||||
|
||||
from pina import LabelTensor, Condition
|
||||
from pina.solvers import SelfAdaptivePINN as SAPINN
|
||||
from pina.solver import SelfAdaptivePINN as SAPINN
|
||||
from pina.trainer import Trainer
|
||||
from pina.model import FeedForward
|
||||
from pina.problem.zoo import (
|
||||
@@ -122,7 +122,7 @@ def test_solver_test(problem, compile):
|
||||
|
||||
@pytest.mark.parametrize("problem", [problem, inverse_problem])
|
||||
def test_train_load_restore(problem):
|
||||
dir = "tests/test_solvers/tmp"
|
||||
dir = "tests/test_solver/tmp"
|
||||
problem = problem
|
||||
solver = SAPINN(model=model, problem=problem)
|
||||
trainer = Trainer(solver=solver,
|
||||
@@ -156,4 +156,4 @@ def test_train_load_restore(problem):
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -3,7 +3,7 @@ import pytest
|
||||
from pina import Condition, LabelTensor
|
||||
from pina.condition import InputOutputPointsCondition
|
||||
from pina.problem import AbstractProblem
|
||||
from pina.solvers import SupervisedSolver
|
||||
from pina.solver import SupervisedSolver
|
||||
from pina.model import FeedForward
|
||||
from pina.trainer import Trainer
|
||||
from torch._dynamo.eval_frame import OptimizedModule
|
||||
@@ -97,7 +97,7 @@ def test_solver_test(use_lt, compile):
|
||||
|
||||
|
||||
def test_train_load_restore():
|
||||
dir = "tests/test_solvers/tmp/"
|
||||
dir = "tests/test_solver/tmp/"
|
||||
problem = LabelTensorProblem()
|
||||
solver = SupervisedSolver(problem=problem, model=model)
|
||||
trainer = Trainer(solver=solver,
|
||||
@@ -130,4 +130,4 @@ def test_train_load_restore():
|
||||
|
||||
# rm directories
|
||||
import shutil
|
||||
shutil.rmtree('tests/test_solvers/tmp')
|
||||
shutil.rmtree('tests/test_solver/tmp')
|
||||
@@ -2,7 +2,7 @@ import pytest
|
||||
import torch
|
||||
|
||||
from pina import Trainer
|
||||
from pina.solvers import PINN
|
||||
from pina.solver import PINN
|
||||
from pina.model import FeedForward
|
||||
from pina.problem.zoo import Poisson2DSquareProblem
|
||||
from pina.loss import ScalarWeighting
|
||||
|
||||
Reference in New Issue
Block a user