PINNInterface#

class PINNInterface(models, problem, optimizers, optimizers_kwargs, extra_features, loss)[source]#

Bases: SolverInterface

Base PINN solver class. This class implements the Solver Interface for Physics Informed Neural Network solvers.

This class can be used to define PINNs with multiple optimizers, and/or models. By default it takes an AbstractProblem, so it is up to the user to choose which problem the implemented solver inheriting from this class is suitable for.

Parameters:
  • models (list(torch.nn.Module)) – Multiple torch neural network models instances.

  • problem (AbstractProblem) – A problem definition instance.

  • optimizer (list(torch.optim.Optimizer)) – A list of neural network optimizers to use.

  • optimizer_kwargs (list(dict)) – A list of optimizer constructor keyword args.

  • extra_features (list(torch.nn.Module)) – The additional input features to use as augmented input. If None no extra features are passed. If it is a list of torch.nn.Module, the extra feature list is passed to all models. If it is a list of extra features’ lists, each single list of extra feature is passed to a model.

  • loss (torch.nn.Module) – The loss function used as minimizer, default torch.nn.MSELoss.

training_step(batch, _)[source]#

The Physics Informed Solver Training Step. This function takes care of the physics informed training step, and it must not be override if not intentionally. It handles the batching mechanism, the workload division for the various conditions, the inverse problem clamping, and loggers.

Parameters:
  • batch (tuple) – The batch element in the dataloader.

  • batch_idx (int) – The batch index.

Returns:

The sum of the loss functions.

Return type:

LabelTensor

loss_data(input_tensor, output_tensor)[source]#

The data loss for the PINN solver. It computes the loss between the network output against the true solution. This function should not be override if not intentionally.

Parameters:
  • input_tensor (LabelTensor) – The input to the neural networks.

  • output_tensor (LabelTensor) – The true solution to compare the network solution.

Returns:

The residual loss averaged on the input coordinates

Return type:

torch.Tensor

abstract loss_phys(samples, equation)[source]#

Computes the physics loss for the physics informed solver based on given samples and equation. This method must be override by all inherited classes and it is the core to define a new physics informed solver.

Parameters:
  • samples (LabelTensor) – The samples to evaluate the physics loss.

  • equation (EquationInterface) – The governing equation representing the physics.

Returns:

The physics loss calculated based on given samples and equation.

Return type:

LabelTensor

compute_residual(samples, equation)[source]#

Compute the residual for Physics Informed learning. This function returns the Equation specified in the Condition evaluated at the samples points.

Parameters:
  • samples (LabelTensor) – The samples to evaluate the physics loss.

  • equation (EquationInterface) – The governing equation representing the physics.

Returns:

The residual of the neural network solution.

Return type:

LabelTensor

store_log(loss_value)[source]#

Stores the loss value in the logger. This function should be called for all conditions. It automatically handles the storing conditions names. It must be used anytime a specific variable wants to be stored for a specific condition. A simple example is to use the variable to store the residual.

Parameters:
  • name (str) – The name of the loss.

  • loss_value (torch.Tensor) – The value of the loss.

save_logs_and_release()[source]#

At the end of each epoch we free the stored losses. This function should not be override if not intentionally.

property loss#

Loss used for training.

property current_condition_name#

Returns the condition name. This function can be used inside the loss_phys() to extract the condition at which the loss is computed.