Skip to content

Commit 64930c4

Browse files
dario-cosciaGiovanniCanali
authored andcommitted
disable compilation py>=3.14
1 parent 24d806b commit 64930c4

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

pina/solver/physics_informed_solver/pinn_interface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ def setup(self, stage):
7171
"""
7272
# Override the compilation, compiling only for torch < 2.8, see
7373
# related issue at https://github.com/mathLab/PINA/issues/621
74-
if torch.__version__ < "2.8":
75-
self.trainer.compile = True
76-
else:
74+
if torch.__version__ >= "2.8":
7775
self.trainer.compile = False
7876
warnings.warn(
7977
"Compilation is disabled for torch >= 2.8. "

pina/solver/solver.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,7 @@ def setup(self, stage):
174174
:return: The result of the parent class ``setup`` method.
175175
:rtype: Any
176176
"""
177-
if stage == "fit" and self.trainer.compile:
178-
self._setup_compile()
179-
if stage == "test" and (
180-
self.trainer.compile and not self._is_compiled()
181-
):
177+
if self.trainer.compile and not self._is_compiled():
182178
self._setup_compile()
183179
return super().setup(stage)
184180

pina/trainer.py

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
"""Module for the Trainer."""
22

33
import sys
4+
import warnings
45
import torch
56
import lightning
6-
from .utils import check_consistency
7+
from .utils import check_consistency, custom_warning_format
78
from .data import PinaDataModule
89
from .solver import SolverInterface, PINNInterface
910

11+
# set the warning for compile options
12+
warnings.formatwarning = custom_warning_format
13+
warnings.filterwarnings("always", category=UserWarning)
14+
1015

1116
class Trainer(lightning.pytorch.Trainer):
1217
"""
@@ -49,7 +54,8 @@ def __init__(
4954
:param float val_size: The percentage of elements to include in the
5055
validation dataset. Default is ``0.0``.
5156
:param bool compile: If ``True``, the model is compiled before training.
52-
Default is ``False``. For Windows users, it is always disabled.
57+
Default is ``False``. For Windows users, it is always disabled. Not
58+
supported for python version greater or equal than 3.14.
5359
:param bool repeat: Whether to repeat the dataset data in each
5460
condition during training. For further details, see the
5561
:class:`~pina.data.data_module.PinaDataModule` class. Default is
@@ -104,8 +110,17 @@ def __init__(
104110
super().__init__(**kwargs)
105111

106112
# checking compilation and automatic batching
107-
if compile is None or sys.platform == "win32":
113+
# compilation disabled for Windows and for Python 3.14+
114+
if (
115+
compile is None
116+
or sys.platform == "win32"
117+
or sys.version_info >= (3, 14)
118+
):
108119
compile = False
120+
warnings.warn(
121+
"Compilation is disabled for Python 3.14+ and for Windows.",
122+
UserWarning,
123+
)
109124

110125
repeat = repeat if repeat is not None else False
111126

@@ -325,3 +340,23 @@ def _check_consistency_and_set_defaults(
325340
if batch_size is not None:
326341
check_consistency(batch_size, int)
327342
return pin_memory, num_workers, shuffle, batch_size
343+
344+
@property
345+
def compile(self):
346+
"""
347+
Whether compilation is required or not.
348+
349+
:return: ``True`` if compilation is required, ``False`` otherwise.
350+
:rtype: bool
351+
"""
352+
return self._compile
353+
354+
@compile.setter
355+
def compile(self, value):
356+
"""
357+
Setting the value of compile.
358+
359+
:param bool value: Whether compilation is required or not.
360+
"""
361+
check_consistency(value, bool)
362+
self._compile = value

0 commit comments

Comments
 (0)