System Equation#

Module for the System of Equation.

class SystemEquation(list_equation, reduction=None)[source]#

Bases: BaseEquation

Implementation of the SystemEquation class, representing a system of mathematical equation to be satisfied by the model outputs. It is useful for multi-component outputs or coupled problems, where multiple constraints must be evaluated together.

It can be passed to a Condition object to define the conditions under which the model is trained.

Each equation in the system must be either an instance of Equation, or a callable function.

Residuals are computed independently for each equation and then aggregated using an optional reduction (e.g., mean, sum). The final result is returned as a single LabelTensor.

Example:

>>> pts = LabelTensor(torch.rand(10, 2), labels=["x", "y"])
>>> pts.requires_grad = True
>>> output_ = torch.pow(pts, 2)
>>> output_.labels = ["u", "v"]
>>> system_equation = SystemEquation(
...     [
...         FixedValue(value=1.0, components=["u"]),
...         FixedGradient(value=0.0, components=["v"], d=["y"]),
...     ],
...     reduction="mean",
... )
>>> residual = system_equation.residual(pts, output_)

Initialization of the SystemEquation class.

Parameters:
  • list_equation (list[Callable] | list[Equation]) – The list of equations used for the computation of the residuals. Each element of the list can be either a callable function or a Equation instance.

  • reduction – The method used to combine the residuals from each equation. Available options are: None, "mean", "sum", or a custom callable. If None, no reduction is applied. If "mean", the residuals are averaged. If "sum", the residuals are summed. If a callable is provided, it is used as a custom reduction (no validation is performed).

Raises:
  • ValueError – If the list of equations is not a list.

  • ValueError – If any element of the list of equations is not a callable function or a Equation instance.

  • ValueError – If an invalid reduction method is used.

residual(input_, output_, params_=None)[source]#

Evaluate each equation residual from the system of equations at the given inputs and aggregate it according to the specified reduction.

Parameters:
  • input (LabelTensor) – The input points where the residual is computed.

  • output (LabelTensor) – The output tensor, potentially produced by a torch.nn.Module instance.

  • params (dict) – An optional dictionary of unknown parameters, used in InverseProblem settings. If the equation is not related to an inverse problem, this should be set to None. Default is None.

Returns:

The aggregated residuals of the system of equations.

Return type:

LabelTensor