System Equation#

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

Bases: EquationInterface

Implementation of the System of Equations, to be passed to a Condition object.

Unlike the Equation class, which represents a single equation, the SystemEquation class allows multiple equations to be grouped together into a system. This is particularly useful when dealing with multi-component outputs or coupled physical models, where the residual must be computed collectively across several constraints.

Each equation in the system must be either: - An instance of Equation; - A callable function.

The residuals from each equation are computed independently and then aggregated using an optional reduction strategy (e.g., mean, sum). The resulting residual is returned as a single LabelTensor.

Example:

>>> from pina.equation import SystemEquation, FixedValue, FixedGradient
>>> from pina import LabelTensor
>>> import torch
>>> 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]) – A list containing either callable functions or instances of Equation, used to compute the residuals of mathematical equations.

  • reduction (str) – The reduction method to aggregate the residuals of each equation. Available options are: None, mean, sum, callable. If None, no reduction is applied. If mean, the output sum is divided by the number of elements in the output. If sum, the output is summed. callable is a user-defined callable function to perform reduction, no checks guaranteed. Default is None.

Raises:

NotImplementedError – If the reduction is not implemented.

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

Compute the residual for each equation in the system of equations and aggregate it according to the reduction specified in the __init__ method.

Parameters:
  • input (LabelTensor) – Input points where each equation of the system is evaluated.

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

  • params (dict) – Dictionary of unknown parameters, associated with a InverseProblem instance. If the equation is not related to a InverseProblem instance, the parameters must be initialized to None. Default is None.

Returns:

The aggregated residuals of the system of equations.

Return type:

LabelTensor