From a763ad1ef56e91259d0cd688b23cdcc6ffbce578 Mon Sep 17 00:00:00 2001 From: Dario Coscia Date: Tue, 28 Oct 2025 12:29:19 +0100 Subject: [PATCH 1/3] disable compilation py>=3.14 --- .../physics_informed_solver/pinn_interface.py | 6 ++-- pina/solver/solver.py | 6 +--- pina/trainer.py | 28 ++++++++++++++++--- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/pina/solver/physics_informed_solver/pinn_interface.py b/pina/solver/physics_informed_solver/pinn_interface.py index 9155e19ec..cd0e25d23 100644 --- a/pina/solver/physics_informed_solver/pinn_interface.py +++ b/pina/solver/physics_informed_solver/pinn_interface.py @@ -71,10 +71,8 @@ def setup(self, stage): """ # 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: - self.trainer.compile = False + if torch.__version__ >= "2.8": + self.trainer._compile = False warnings.warn( "Compilation is disabled for torch >= 2.8. " "Forcing compilation may cause runtime errors or instability.", diff --git a/pina/solver/solver.py b/pina/solver/solver.py index 6948ec664..442574224 100644 --- a/pina/solver/solver.py +++ b/pina/solver/solver.py @@ -174,11 +174,7 @@ def setup(self, stage): :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) diff --git a/pina/trainer.py b/pina/trainer.py index 78dd77adf..e7788a2c5 100644 --- a/pina/trainer.py +++ b/pina/trainer.py @@ -3,10 +3,15 @@ import sys import torch import lightning -from .utils import check_consistency +import warnings +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 @@ def __init__( :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,18 @@ def __init__( super().__init__(**kwargs) # checking compilation and automatic batching - if compile is None or sys.platform == "win32": + # compile disambled for windows and py>=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 versions >= 3.14. " + "Compilation is also disabled for Windows 3.2.", + UserWarning, + ) repeat = repeat if repeat is not None else False @@ -114,7 +130,7 @@ def __init__( ) # set attributes - self.compile = compile + self._compile = compile self.solver = solver self.batch_size = batch_size self._move_to_device() @@ -325,3 +341,7 @@ def _check_consistency_and_set_defaults( if batch_size is not None: check_consistency(batch_size, int) return pin_memory, num_workers, shuffle, batch_size + + @property + def compile(self): + return self._compile \ No newline at end of file From c62da51170be76e78f6a799e32c94b3b7fe4592c Mon Sep 17 00:00:00 2001 From: Dario Coscia Date: Tue, 28 Oct 2025 14:33:20 +0100 Subject: [PATCH 2/3] forcing KeyError --- pina/trainer.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pina/trainer.py b/pina/trainer.py index e7788a2c5..8d4504816 100644 --- a/pina/trainer.py +++ b/pina/trainer.py @@ -117,8 +117,9 @@ def __init__( or sys.version_info >= (3, 14) ): compile = False + raise KeyError warnings.warn( - "Compilation is disabled for python versions >= 3.14. " + "Compilation is disabled for Python 3.14+. " "Compilation is also disabled for Windows 3.2.", UserWarning, ) From 0aca8b12e4fc90e8107d2be76d7b6c6a70787e7b Mon Sep 17 00:00:00 2001 From: Dario Coscia Date: Tue, 28 Oct 2025 14:42:10 +0100 Subject: [PATCH 3/3] forcing compile=False --- pina/trainer.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/pina/trainer.py b/pina/trainer.py index 8d4504816..bb819905f 100644 --- a/pina/trainer.py +++ b/pina/trainer.py @@ -111,18 +111,19 @@ def __init__( # checking compilation and automatic batching # compile disambled for windows and py>=3.14 - if ( - compile is None - or sys.platform == "win32" - or sys.version_info >= (3, 14) - ): - compile = False - raise KeyError - warnings.warn( - "Compilation is disabled for Python 3.14+. " - "Compilation is also disabled for Windows 3.2.", - UserWarning, - ) + compile = False + # if ( + # compile is None + # or sys.platform == "win32" + # or sys.version_info >= (3, 14) + # ): + # compile = False + # raise KeyError + # warnings.warn( + # "Compilation is disabled for Python 3.14+. " + # "Compilation is also disabled for Windows 3.2.", + # UserWarning, + # ) repeat = repeat if repeat is not None else False