Competitive Physics-Informed Solver#

Module for the competitive physics-informed multi-model solver.

class CompetitivePhysicsInformedSolver(problem, model, discriminator=None, optimizer_model=None, optimizer_discriminator=None, scheduler_model=None, scheduler_discriminator=None, weighting=None, loss=None)[source]#

Bases: PhysicsInformedMixin, MultiModelSolver

Multi-model solver for competitive physics-informed learning problems.

This solver approximates the solution of a differential problem using a trainable model together with a discriminator network. 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}).\]

The discriminator \(D\) assigns pointwise weights to the residuals, encouraging the model to focus on regions where the approximation performs poorly. The model parameters are optimized by minimizing the loss, while the discriminator parameters are optimized by maximizing it.

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

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

where \(D\) is the discriminator network and \(\mathcal{L}\) is the selected loss function, typically the mean squared error.

The model and discriminator are trained through a min-max problem:

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

where \(\theta\) denotes the model parameters and \(\phi\) denotes the discriminator parameters.

See also

Original reference: Zeng, Q., Kothari, P., Chou, E., & Masi, G. (2022). Competitive physics informed networks. International Conference on Learning Representations, ICLR 2022. OpenReview Preprint.

Initialization of the CompetitivePhysicsInformedSolver class.

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

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

  • discriminator (torch.nn.Module) – The discriminator used by the solver. If None, a deep copy of the model is used as discriminator. Default is None.

  • 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_discriminator (TorchOptimizer) – The optimizer of the discriminator. 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_discriminator (TorchScheduler) – The scheduler of the discriminator. 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 discriminator#

The discriminator used by the solver.

Returns:

The discriminator 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_discriminator#

The optimizer for the discriminator used by the solver.

Returns:

The optimizer for the discriminator 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_discriminator#

The scheduler for the discriminator used by the solver.

Returns:

The scheduler for the discriminator used by the solver.

Return type:

TorchScheduler