Self-Adaptive Physics-Informed Solver#

Module for the self-adaptive physics-informed multi-model solver.

class SelfAdaptivePhysicsInformedSolver(problem, model, weight_function=Sigmoid(), optimizer_model=None, optimizer_weights=None, scheduler_model=None, scheduler_weights=None, weighting=None, loss=None)[source]#

Bases: PhysicsInformedMixin, MultiModelSolver

Multi-model solver for self-adaptive physics-informed learning problems.

This solver approximates the solution of a differential problem using a trainable model together with condition-wise self-adaptive weights. It is intended for problems whose conditions may include supervised data, equation residuals evaluated on input points, and equation residuals sampled from domains.

Given a model \(\mathcal{M}\), the predicted solution is

\[\hat{\mathbf{u}}(\mathbf{x}) = \mathcal{M}(\mathbf{x}).\]

For each condition, the solver introduces trainable pointwise weights. These weights are passed through a user-defined weight function \(m\), typically chosen to keep the effective weights bounded or positive. The resulting weighted objective encourages the model to focus on regions where the residual is larger.

For a problem with governing equation operator \(\mathcal{A}\) in the domain \(\Omega\) and boundary operator \(\mathcal{B}\) on the boundary \(\partial\Omega\), the objective can be written as

\[\mathcal{L}_{\mathrm{problem}} = \frac{1}{N_{\Omega}} \sum_{i=1}^{N_{\Omega}} m(\lambda_{\Omega}^{i}) \mathcal{L} \left( \mathcal{A}[\hat{\mathbf{u}}](\mathbf{x}_i) \right) + \frac{1}{N_{\partial\Omega}} \sum_{i=1}^{N_{\partial\Omega}} m(\lambda_{\partial\Omega}^{i}) \mathcal{L} \left( \mathcal{B}[\hat{\mathbf{u}}](\mathbf{x}_i) \right),\]

where \(\lambda_{\Omega}^{i}\) and \(\lambda_{\partial\Omega}^{i}\) are the self-adaptive weights associated with points in \(\Omega\) and \(\partial\Omega\), respectively, and \(\mathcal{L}\) is the selected loss function, typically the mean squared error.

The model parameters and the self-adaptive weights are optimized through a min-max problem:

\[\min_{\theta} \max_{\lambda} \mathcal{L}_{\mathrm{problem}},\]

where \(\theta\) denotes the model parameters and \(\lambda\) denotes the collection of self-adaptive weights.

See also

Original reference: McClenny, L. D., & Braga-Neto, U. M. (2023). Self-adaptive physics-informed neural networks. Journal of Computational Physics, 474, 111722. DOI: 10.1016/j.jcp.2022.111722.

Initialization of the SelfAdaptivePhysicsInformedSolver class.

Parameters:
  • problem (BaseProblem) – The problem to be solved.

  • model (torch.nn.Module) – The model used by the solver.

  • weight_function (torch.nn.Module) – The weight function used to compute self-adaptive weights. Default is torch.nn.Sigmoid().

  • optimizer_model (TorchOptimizer) – The optimizer of the main model. If None, the torch.optim.Adam optimizer with a learning rate of 0.001 is used. Default is None.

  • optimizer_weights (TorchOptimizer) – The optimizer of the self-adaptive weights. If None, the torch.optim.Adam optimizer with a learning rate of 0.001 is used. Default is None.

  • scheduler_model (TorchScheduler) – The scheduler of the main model. If None, the torch.optim.lr_scheduler.ConstantLR scheduler with a factor of 1.0 is used. Default is None.

  • scheduler_weights (TorchScheduler) – The scheduler of the self-adaptive weights. If None, the torch.optim.lr_scheduler.ConstantLR scheduler with a factor of 1.0 is used. Default is None.

  • weighting (BaseWeighting) – The weighting strategy used to combine condition losses. If None, no weighting is applied. Default is None.

  • loss – The loss function used to compute residual losses. If None, torch.nn.MSELoss is used. Default is None.

Raises:
  • ValueError – If weight_function is not a torch.nn.Module.

  • ValueError – If not all domains have been discretised.

training_step(batch, batch_idx)[source]#

Solver training step.

Parameters:
  • batch (list[tuple[str, dict]]) – A batch of data. Each element is a tuple containing a condition name and a dictionary of points.

  • batch_idx (int) – The index of the current batch.

Returns:

The loss of the training step.

Return type:

torch.Tensor

forward(x)[source]#

Forward pass through the model.

Parameters:

x (torch.Tensor | LabelTensor | Data | Graph) – The input data.

Returns:

The output of the model.

Return type:

torch.Tensor | LabelTensor | Data | Graph

property model#

The single model used by the solver.

Returns:

The single model used by the solver.

Return type:

torch.nn.Module

property weights#

The self-adaptive weights used by the solver.

Returns:

The self-adaptive weights used by the solver.

Return type:

torch.nn.Module

property optimizer_model#

The optimizer for the model used by the solver.

Returns:

The optimizer for the model used by the solver.

Return type:

TorchOptimizer

property optimizer_weights#

The optimizer for the weights used by the solver.

Returns:

The optimizer for the weights used by the solver.

Return type:

TorchOptimizer

property scheduler_model#

The scheduler for the model used by the solver.

Returns:

The scheduler for the model used by the solver.

Return type:

TorchScheduler

property scheduler_weights#

The scheduler for the weights used by the solver.

Returns:

The scheduler for the weights used by the solver.

Return type:

TorchScheduler