Conditions#

class Condition(*args, **kwargs)[source]#

Bases: object

The Condition class is a core component of the PINA framework that provides a unified interface to define heterogeneous constraints that must be satisfied by a AbstractProblem.

It encapsulates all types of constraints - physical, boundary, initial, or data-driven - that the solver must satisfy during training. The specific behavior is inferred from the arguments passed to the constructor.

Multiple types of conditions can be used within the same problem, allowing for a high degree of flexibility in defining complex problems.

The Condition class behavior specializes internally based on the arguments provided during instantiation. Depending on the specified keyword arguments, the class automatically selects the appropriate internal implementation.

Available Condition types:

  • InputTargetCondition: represents a supervised condition defined by both input and target data. The model is trained to reproduce the target values given the input. Supported data types include torch.Tensor, LabelTensor, Graph, or Data. The class automatically selects the appropriate implementation based on the types of input and target.

  • DomainEquationCondition : represents a general physics-informed condition defined by a domain and an equation. The model learns to minimize the equation residual through evaluations performed at points sampled from the specified domain.

  • InputEquationCondition: represents a general physics-informed condition defined by input points and an equation. The model learns to minimize the equation residual through evaluations performed at the provided input. Supported data types for the input include LabelTensor or Graph. The class automatically selects the appropriate implementation based on the types of the input.

  • DataCondition: represents an unsupervised, data-driven condition defined by the input only. The model is trained using a custom unsupervised loss determined by the chosen SolverInterface, while leveraging the provided data during training. Optional conditional_variables can be specified when the model depends on additional parameters. Supported data types include torch.Tensor, LabelTensor, Graph, or Data. The class automatically selects the appropriate implementation based on the type of the input.

Note

The user should always instantiate Condition directly, without manually creating subclass instances. Please refer to the specific Condition classes for implementation details.

Example:

>>> from pina import Condition
>>> # Example of InputTargetCondition signature
>>> condition = Condition(input=input, target=target)
>>> # Example of DomainEquationCondition signature
>>> condition = Condition(domain=domain, equation=equation)
>>> # Example of InputEquationCondition signature
>>> condition = Condition(input=input, equation=equation)
>>> # Example of DataCondition signature
>>> condition = Condition(input=data, conditional_variables=cond_vars)

Instantiate the appropriate Condition object based on the keyword arguments passed.

Parameters:
  • args (tuple) – The positional arguments (should be empty).

  • kwargs (dict) – The keyword arguments corresponding to the parameters of the specific Condition type to instantiate.

Raises:
  • ValueError – If unexpected positional arguments are provided.

  • ValueError – If the keyword arguments are invalid.

Returns:

The appropriate Condition object.

Return type:

ConditionInterface