Input Equation Condition#

Module for the Input-Equation Condition class.

class InputEquationCondition(input, equation)[source]#

Bases: BaseCondition

The class InputEquationCondition defines a condition based on input data and an equation. This condition is typically used in physics-informed problems, where the model is trained to satisfy a given equation through the evaluation of the residual performed at the provided input.

Example:

>>> from pina import Condition, LabelTensor
>>> from pina.equation import Equation
>>> import torch
>>> # Equation to be satisfied over the input points: # x^2 + y^2 - 1 = 0
>>> def dummy_equation(pts):
...     return pts["x"]**2 + pts["y"]**2 - 1
>>> pts = LabelTensor(torch.randn(100, 2), labels=["x", "y"])
>>> condition = Condition(input=pts, equation=Equation(dummy_equation))

Initialization of the BaseCondition class.

Parameters:

kwargs (dict) – The keyword arguments representing the data to be stored in the condition.

store_data(**kwargs)[source]#

Store the input data in a dictionary-like structure.

Parameters:

kwargs (dict) – The keyword arguments containing the data to be stored.

Returns:

A dictionary-like structure containing the stored data.

Return type:

_DataManager

property input#

The input data associated with the condition.

Returns:

The input data.

Return type:

LabelTensor | Graph | list[Graph] | tuple[Graph]

property equation#

The equation associated with the condition.

Returns:

The equation.

Return type:

BaseEquation

evaluate(batch, solver)[source]#

Evaluate the residual of the condition on the given batch using the solver.

This method computes the non-aggregated, element-wise residual of the condition. A forward pass of the solver’s model is performed on the input samples, and the condition residual is evaluated accordingly.

The returned tensor is not reduced, preserving the per-sample residual values.

Parameters:
  • batch (dict) – The batch containing the data required by the condition evaluation.

  • solver (BaseSolver) – The solver used to perform the forward pass and compute the residual. The solver provides access to the model and its parameters, which may be necessary for evaluating the condition residual.

Returns:

The non-aggregated residual tensor.

Return type:

LabelTensor