System Equation#
- class SystemEquation(list_equation, reduction=None)[source]#
Bases:
EquationInterfaceImplementation of the System of Equations, to be passed to a
Conditionobject.Unlike the
Equationclass, which represents a single equation, theSystemEquationclass 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 singleLabelTensor.- 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
SystemEquationclass.- 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. IfNone, no reduction is applied. Ifmean, the output sum is divided by the number of elements in the output. Ifsum, the output is summed.callableis a user-defined callable function to perform reduction, no checks guaranteed. Default isNone.
- 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
reductionspecified 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.Moduleinstance.params (dict) – Dictionary of unknown parameters, associated with a
InverseProbleminstance. If the equation is not related to aInverseProbleminstance, the parameters must be initialized toNone. Default isNone.
- Returns:
The aggregated residuals of the system of equations.
- Return type: