Skip to content

Commit a763ad1

Browse files
committed
disable compilation py>=3.14
1 parent 256ac9d commit a763ad1

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

pina/solver/physics_informed_solver/pinn_interface.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ 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:
77-
self.trainer.compile = False
74+
if torch.__version__ >= "2.8":
75+
self.trainer._compile = False
7876
warnings.warn(
7977
"Compilation is disabled for torch >= 2.8. "
8078
"Forcing compilation may cause runtime errors or instability.",

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: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@
33
import sys
44
import torch
55
import lightning
6-
from .utils import check_consistency
6+
import warnings
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,18 @@ def __init__(
104110
super().__init__(**kwargs)
105111

106112
# checking compilation and automatic batching
107-
if compile is None or sys.platform == "win32":
113+
# compile disambled for windows and py>=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 versions >= 3.14. "
122+
"Compilation is also disabled for Windows 3.2.",
123+
UserWarning,
124+
)
109125

110126
repeat = repeat if repeat is not None else False
111127

@@ -114,7 +130,7 @@ def __init__(
114130
)
115131

116132
# set attributes
117-
self.compile = compile
133+
self._compile = compile
118134
self.solver = solver
119135
self.batch_size = batch_size
120136
self._move_to_device()
@@ -325,3 +341,7 @@ def _check_consistency_and_set_defaults(
325341
if batch_size is not None:
326342
check_consistency(batch_size, int)
327343
return pin_memory, num_workers, shuffle, batch_size
344+
345+
@property
346+
def compile(self):
347+
return self._compile

0 commit comments

Comments
 (0)