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 by AbstractProblem, and users can choose the problem type the solver is meant to address.

Initialization of the PINNInterface class.

Parameters:
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:

dict

validation_step(batch)[source]#

The validation step for the PINN solver.

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 loss of the validation step.

Return type:

torch.Tensor

test_step(batch)[source]#

The test step for the PINN solver.

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 loss of the test step.

Return type:

torch.Tensor

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:

torch.Tensor

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:
Returns:

The computed physics loss.

Return type:

LabelTensor

compute_residual(samples, equation)[source]#

Compute the residuals of the equation.

Parameters:
Returns:

The residual of the solution of the model.

Return type:

LabelTensor

property loss#

The loss used for training.

Returns:

The loss function used for training.

Return type:

torch.nn.Module

property current_condition_name#

The current condition name.

Returns:

The current condition name.

Return type:

str