Compare commits
10 Commits
fix-codacy
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f07e59b69b | ||
|
|
d4fa3ea9df | ||
|
|
fca3db7926 | ||
|
|
64930c431f | ||
|
|
24d806b262 | ||
|
|
9c3e55da91 | ||
|
|
256ac9d025 | ||
|
|
6935e0d58a | ||
|
|
4860a2db84 | ||
|
|
cb629cc554 |
2
.github/workflows/monthly-tagger.yml
vendored
2
.github/workflows/monthly-tagger.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
os: [windows-latest, macos-latest, ubuntu-latest]
|
||||
python-version: [3.9, '3.10', '3.11', '3.12', '3.13']
|
||||
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up Python
|
||||
|
||||
6
.github/workflows/tester.yml
vendored
6
.github/workflows/tester.yml
vendored
@@ -1,7 +1,7 @@
|
||||
name: "Testing Pull Request"
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
pull_request:
|
||||
branches:
|
||||
- "master"
|
||||
- "dev"
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [windows-latest, macos-latest, ubuntu-latest]
|
||||
python-version: [3.9, '3.10', '3.11', '3.12', '3.13']
|
||||
python-version: ['3.10', '3.11', '3.12', '3.13', '3.14']
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
@@ -75,4 +75,4 @@ jobs:
|
||||
threshold: 80.123
|
||||
fail: true
|
||||
publish: true
|
||||
coverage-summary-title: "Code Coverage Summary"
|
||||
coverage-summary-title: "Code Coverage Summary"
|
||||
4
.github/workflows/tutorial_exporter.yml
vendored
4
.github/workflows/tutorial_exporter.yml
vendored
@@ -23,7 +23,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.9
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@@ -91,7 +91,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.9
|
||||
python-version: '3.10'
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
|
||||
@@ -7,8 +7,8 @@ SPDX-License-Identifier: Apache-2.0
|
||||
<table>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="https://github.com/mathLab/PINA/raw/master/readme/pina_logo.png">
|
||||
<img src="https://github.com/mathLab/PINA/raw/master/readme/pina_logo.png"
|
||||
<a href="readme/pina_logo.png">
|
||||
<img src="readme/pina_logo.png"
|
||||
alt="PINA logo"
|
||||
style="width: 220px; aspect-ratio: 1 / 1; object-fit: contain;">
|
||||
</a>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 177 KiB After Width: | Height: | Size: 411 KiB |
@@ -1,7 +1,6 @@
|
||||
"""Module for the Equation."""
|
||||
|
||||
import inspect
|
||||
|
||||
from .equation_interface import EquationInterface
|
||||
|
||||
|
||||
@@ -49,6 +48,10 @@ class Equation(EquationInterface):
|
||||
:raises RuntimeError: If the underlying equation signature length is not
|
||||
2 (direct problem) or 3 (inverse problem).
|
||||
"""
|
||||
# Move the equation to the input_ device
|
||||
self.to(input_.device)
|
||||
|
||||
# Call the underlying equation based on its signature length
|
||||
if self.__len_sig == 2:
|
||||
return self.__equation(input_, output_)
|
||||
if self.__len_sig == 3:
|
||||
|
||||
@@ -239,19 +239,19 @@ class Advection(Equation): # pylint: disable=R0903
|
||||
)
|
||||
|
||||
# Ensure consistency of c length
|
||||
if len(self.c) != (len(input_lbl) - 1) and len(self.c) > 1:
|
||||
if self.c.shape[-1] != len(input_lbl) - 1 and self.c.shape[-1] > 1:
|
||||
raise ValueError(
|
||||
"If 'c' is passed as a list, its length must be equal to "
|
||||
"the number of spatial dimensions."
|
||||
)
|
||||
|
||||
# Repeat c to ensure consistent shape for advection
|
||||
self.c = self.c.repeat(output_.shape[0], 1)
|
||||
if self.c.shape[1] != (len(input_lbl) - 1):
|
||||
self.c = self.c.repeat(1, len(input_lbl) - 1)
|
||||
c = self.c.repeat(output_.shape[0], 1)
|
||||
if c.shape[1] != (len(input_lbl) - 1):
|
||||
c = c.repeat(1, len(input_lbl) - 1)
|
||||
|
||||
# Add a dimension to c for the following operations
|
||||
self.c = self.c.unsqueeze(-1)
|
||||
c = c.unsqueeze(-1)
|
||||
|
||||
# Compute the time derivative and the spatial gradient
|
||||
time_der = grad(output_, input_, components=None, d="t")
|
||||
@@ -262,7 +262,7 @@ class Advection(Equation): # pylint: disable=R0903
|
||||
tmp = tmp.transpose(-1, -2)
|
||||
|
||||
# Compute advection term
|
||||
adv = (tmp * self.c).sum(dim=tmp.tensor.ndim - 2)
|
||||
adv = (tmp * c).sum(dim=tmp.tensor.ndim - 2)
|
||||
|
||||
return time_der + adv
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
"""Module for the Equation Interface."""
|
||||
|
||||
from abc import ABCMeta, abstractmethod
|
||||
import torch
|
||||
|
||||
|
||||
class EquationInterface(metaclass=ABCMeta):
|
||||
@@ -33,3 +34,33 @@ class EquationInterface(metaclass=ABCMeta):
|
||||
:return: The computed residual of the equation.
|
||||
:rtype: LabelTensor
|
||||
"""
|
||||
|
||||
def to(self, device):
|
||||
"""
|
||||
Move all tensor attributes to the specified device.
|
||||
|
||||
:param torch.device device: The target device to move the tensors to.
|
||||
:return: The instance moved to the specified device.
|
||||
:rtype: EquationInterface
|
||||
"""
|
||||
# Iterate over all attributes of the Equation
|
||||
for key, val in self.__dict__.items():
|
||||
|
||||
# Move tensors in dictionaries to the specified device
|
||||
if isinstance(val, dict):
|
||||
self.__dict__[key] = {
|
||||
k: v.to(device) if torch.is_tensor(v) else v
|
||||
for k, v in val.items()
|
||||
}
|
||||
|
||||
# Move tensors in lists to the specified device
|
||||
elif isinstance(val, list):
|
||||
self.__dict__[key] = [
|
||||
v.to(device) if torch.is_tensor(v) else v for v in val
|
||||
]
|
||||
|
||||
# Move tensor attributes to the specified device
|
||||
elif torch.is_tensor(val):
|
||||
self.__dict__[key] = val.to(device)
|
||||
|
||||
return self
|
||||
|
||||
@@ -101,6 +101,10 @@ class SystemEquation(EquationInterface):
|
||||
:return: The aggregated residuals of the system of equations.
|
||||
:rtype: LabelTensor
|
||||
"""
|
||||
# Move the equation to the input_ device
|
||||
self.to(input_.device)
|
||||
|
||||
# Compute the residual for each equation
|
||||
residual = torch.hstack(
|
||||
[
|
||||
equation.residual(input_, output_, params_)
|
||||
@@ -108,6 +112,7 @@ class SystemEquation(EquationInterface):
|
||||
]
|
||||
)
|
||||
|
||||
# Skip reduction if not specified
|
||||
if self.reduction is None:
|
||||
return residual
|
||||
|
||||
|
||||
@@ -48,11 +48,10 @@ class HelmholtzProblem(SpatialProblem):
|
||||
:type alpha: float | int
|
||||
"""
|
||||
super().__init__()
|
||||
|
||||
self.alpha = alpha
|
||||
check_consistency(alpha, (int, float))
|
||||
self.alpha = alpha
|
||||
|
||||
def forcing_term(self, input_):
|
||||
def forcing_term(input_):
|
||||
"""
|
||||
Implementation of the forcing term.
|
||||
"""
|
||||
|
||||
@@ -71,9 +71,7 @@ class PINNInterface(SupervisedSolverInterface, metaclass=ABCMeta):
|
||||
"""
|
||||
# Override the compilation, compiling only for torch < 2.8, see
|
||||
# related issue at https://github.com/mathLab/PINA/issues/621
|
||||
if torch.__version__ < "2.8":
|
||||
self.trainer.compile = True
|
||||
else:
|
||||
if torch.__version__ >= "2.8":
|
||||
self.trainer.compile = False
|
||||
warnings.warn(
|
||||
"Compilation is disabled for torch >= 2.8. "
|
||||
|
||||
@@ -174,11 +174,7 @@ class SolverInterface(lightning.pytorch.LightningModule, metaclass=ABCMeta):
|
||||
:return: The result of the parent class ``setup`` method.
|
||||
:rtype: Any
|
||||
"""
|
||||
if stage == "fit" and self.trainer.compile:
|
||||
self._setup_compile()
|
||||
if stage == "test" and (
|
||||
self.trainer.compile and not self._is_compiled()
|
||||
):
|
||||
if self.trainer.compile and not self._is_compiled():
|
||||
self._setup_compile()
|
||||
return super().setup(stage)
|
||||
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
"""Module for the Trainer."""
|
||||
|
||||
import sys
|
||||
import warnings
|
||||
import torch
|
||||
import lightning
|
||||
from .utils import check_consistency
|
||||
from .utils import check_consistency, custom_warning_format
|
||||
from .data import PinaDataModule
|
||||
from .solver import SolverInterface, PINNInterface
|
||||
|
||||
# set the warning for compile options
|
||||
warnings.formatwarning = custom_warning_format
|
||||
warnings.filterwarnings("always", category=UserWarning)
|
||||
|
||||
|
||||
class Trainer(lightning.pytorch.Trainer):
|
||||
"""
|
||||
@@ -49,7 +54,8 @@ class Trainer(lightning.pytorch.Trainer):
|
||||
:param float val_size: The percentage of elements to include in the
|
||||
validation dataset. Default is ``0.0``.
|
||||
:param bool compile: If ``True``, the model is compiled before training.
|
||||
Default is ``False``. For Windows users, it is always disabled.
|
||||
Default is ``False``. For Windows users, it is always disabled. Not
|
||||
supported for python version greater or equal than 3.14.
|
||||
:param bool repeat: Whether to repeat the dataset data in each
|
||||
condition during training. For further details, see the
|
||||
:class:`~pina.data.data_module.PinaDataModule` class. Default is
|
||||
@@ -104,8 +110,17 @@ class Trainer(lightning.pytorch.Trainer):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
# checking compilation and automatic batching
|
||||
if compile is None or sys.platform == "win32":
|
||||
# compilation disabled for Windows and for Python 3.14+
|
||||
if (
|
||||
compile is None
|
||||
or sys.platform == "win32"
|
||||
or sys.version_info >= (3, 14)
|
||||
):
|
||||
compile = False
|
||||
warnings.warn(
|
||||
"Compilation is disabled for Python 3.14+ and for Windows.",
|
||||
UserWarning,
|
||||
)
|
||||
|
||||
repeat = repeat if repeat is not None else False
|
||||
|
||||
@@ -325,3 +340,23 @@ class Trainer(lightning.pytorch.Trainer):
|
||||
if batch_size is not None:
|
||||
check_consistency(batch_size, int)
|
||||
return pin_memory, num_workers, shuffle, batch_size
|
||||
|
||||
@property
|
||||
def compile(self):
|
||||
"""
|
||||
Whether compilation is required or not.
|
||||
|
||||
:return: ``True`` if compilation is required, ``False`` otherwise.
|
||||
:rtype: bool
|
||||
"""
|
||||
return self._compile
|
||||
|
||||
@compile.setter
|
||||
def compile(self, value):
|
||||
"""
|
||||
Setting the value of compile.
|
||||
|
||||
:param bool value: Whether compilation is required or not.
|
||||
"""
|
||||
check_consistency(value, bool)
|
||||
self._compile = value
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "pina-mathlab"
|
||||
version = "0.2.3"
|
||||
version = "0.2.5"
|
||||
description = "Physic Informed Neural networks for Advance modeling."
|
||||
readme = "README.md"
|
||||
authors = [
|
||||
@@ -19,7 +19,7 @@ dependencies = [
|
||||
"torch_geometric",
|
||||
"matplotlib",
|
||||
]
|
||||
requires-python = ">=3.9"
|
||||
requires-python = ">=3.10"
|
||||
|
||||
[project.optional-dependencies]
|
||||
doc = [
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 411 KiB |
@@ -104,7 +104,7 @@ def test_advection_equation(c):
|
||||
|
||||
# Should fail if c is a list and its length != spatial dimension
|
||||
with pytest.raises(ValueError):
|
||||
Advection([1, 2, 3])
|
||||
equation = Advection([1, 2, 3])
|
||||
residual = equation.residual(pts, u)
|
||||
|
||||
|
||||
|
||||
BIN
tutorials/static/pina_logo.png
vendored
BIN
tutorials/static/pina_logo.png
vendored
Binary file not shown.
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 411 KiB |
Reference in New Issue
Block a user