Causal Physics Informed Single Model Solver#
Module for the causal physics-informed single-model solver class.
- class CausalPhysicsInformedSingleModelSolver(problem, model, optimizer=None, scheduler=None, weighting=None, loss=None, eps=100, n_steps=10, regularized_conditions=None)[source]
Bases:
PhysicsInformedMixin,SingleModelSolverSingle-model solver for causal physics-informed learning problems.
This solver approximates the solution of a time-dependent differential problem using a single model and a causality-aware training objective. It is intended for problems whose conditions include equation residuals and boundary residuals evaluated across ordered time snapshots. It can be used only for forward problems, due to the causal nature of the training objective.
Given a model \(\mathcal{M}\), the predicted solution is
\[\hat{\mathbf{u}}(\mathbf{x}, t) = \mathcal{M}(\mathbf{x}, t).\]The solver minimizes a causal residual loss that weights each time snapshot according to the residuals accumulated at previous times. For a time dependent 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_t} \sum_{i=1}^{N_t} \omega_i \mathcal{L}_r(t_i),\]where the residual loss at time \(t\) is
\[\mathcal{L}_r(t) = \frac{1}{N_{\Omega}} \sum_{j=1}^{N_{\Omega}} \mathcal{L}\left( \mathcal{A}[\hat{\mathbf{u}}](\mathbf{x}_j, t) \right) + \frac{1}{N_{\partial\Omega}} \sum_{j=1}^{N_{\partial\Omega}} \mathcal{L} \left( \mathcal{B}[\hat{\mathbf{u}}](\mathbf{x}_j, t) \right).\]The causal weights are defined as
\[\omega_i = \exp \left( -\epsilon \sum_{k=1}^{i-1} \mathcal{L}_r(t_k) \right),\]where \(\epsilon\) is a hyperparameter controlling the strength of the causal weighting, and \(\mathcal{L}\) is the selected loss function, typically the mean squared error.
See also
Original reference: Wang, S., Sankaran, S., & Perdikaris, P. (2024). Respecting causality for training physics-informed neural networks. Computer Methods in Applied Mechanics and Engineering, 421, 116813. DOI: 10.1016/j.cma.2024.116813.
Note
This solver is compatible only with problems inheriting from
TimeDependentProblem.Initialization of the
CausalPhysicsInformedSingleModelSolverclass.- Parameters:
problem (BaseProblem) – The problem to be solved.
model (torch.nn.Module) – The model used by the solver.
optimizer (TorchOptimizer) – The optimizer used by the solver. If
None, thetorch.optim.Adamoptimizer with a learning rate of0.001is used. Default isNone.scheduler (TorchScheduler) – The scheduler used by the solver. If
None, thetorch.optim.lr_scheduler.ConstantLRscheduler with a factor of1.0is used. Default isNone.weighting (BaseWeighting) – The weighting strategy used to combine condition losses. If
None, no weighting is applied. Default isNone.loss – The loss function used to compute residual losses. If
None,torch.nn.MSELossis used. Default isNone.eps (float | int) – The exponential decay parameter. Default is
100.n_steps (int) – The number of equispaced temporal steps used to compute the causal loss. Default is
10.regularized_conditions – The names of the conditions that should receive causal regularization. Default is
None.
- Raises:
ValueError – If the problem is not time-dependent.
ValueError – If the user does not specify any regularized conditions.
ValueError – If any of the specified
regularized_conditionsare not present in theproblem’s conditions.ValueError – If
epsis not a float or int.ValueError – If
n_stepsis not a positive integer.
- property temporal_variable
The temporal variable of the problem.
- Returns:
The temporal variable name.
- Return type:
- Raises:
ValueError – If the problem does not have exactly one temporal variable.
- property spatial_variables
The spatial variables of the problem.
- Returns:
The spatial variable names.
- Return type:
- Raises:
ValueError – If the problem does not have any spatial variables.