PINNInterface#
- class PINNInterface(problem, loss=None, **kwargs)[source]#
Bases:
SolverInterface
Base class for Physics-Informed Neural Network (PINN) solvers, implementing the
SolverInterface
class.The
PINNInterface
class can be used to define PINNs that work with one or multiple optimizers and/or models. By default, it is compatible with problems defined byAbstractProblem
, and users can choose the problem type the solver is meant to address.Initialization of the
PINNInterface
class.- Parameters:
problem (AbstractProblem) – The problem to be solved.
loss (torch.nn.Module) – The loss function to be minimized. If
None
, thetorch.nn.MSELoss
loss is used. Default isNone
.kwargs – Additional keyword arguments to be passed to the
SolverInterface
class.
- optimization_cycle(batch)[source]#
The optimization cycle for the PINN solver.
This method allows to call
_run_optimization_cycle
with the physics loss as argument, thus distinguishing the training step from the validation and test steps.- Parameters:
batch (list[tuple[str, dict]]) – A batch of data. Each element is a tuple containing a condition name and a dictionary of points.
- Returns:
The losses computed for all conditions in the batch, casted to a subclass of
torch.Tensor
. It should return a dict containing the condition name and the associated scalar loss.- Return type:
- validation_step(batch)[source]#
The validation step for the PINN solver.
- test_step(batch)[source]#
The test step for the PINN solver.
- loss_data(input_pts, output_pts)[source]#
Compute the data loss for the PINN solver by evaluating the loss between the network’s output and the true solution. This method should not be overridden, if not intentionally.
- Parameters:
input_pts (LabelTensor) – The input points to the neural network.
output_pts (LabelTensor) – The true solution to compare with the network’s output.
- Returns:
The supervised loss, averaged over the number of observations.
- Return type:
- abstract loss_phys(samples, equation)[source]#
Computes the physics loss for the physics-informed solver based on the provided samples and equation. This method must be overridden in subclasses. It distinguishes different types of PINN solvers.
- Parameters:
samples (LabelTensor) – The samples to evaluate the physics loss.
equation (EquationInterface) – The governing equation.
- Returns:
The computed physics loss.
- Return type:
- compute_residual(samples, equation)[source]#
Compute the residuals of the equation.
- Parameters:
samples (LabelTensor) – The samples to evaluate the loss.
equation (EquationInterface) – The governing equation.
- Returns:
The residual of the solution of the model.
- Return type:
- property loss#
The loss used for training.
- Returns:
The loss function used for training.
- Return type: