Fix conditions rendering

This commit is contained in:
FilippoOlivo
2025-03-14 14:51:40 +01:00
committed by Nicola Demo
parent 8dc682c849
commit 05105dd517
5 changed files with 67 additions and 56 deletions

View File

@@ -29,37 +29,49 @@ def warning_function(new, old):
class Condition: class Condition:
""" """
The class ``Condition`` is used to represent the constraints (physical Represents constraints (such as physical equations, boundary conditions,
equations, boundary conditions, etc.) that should be satisfied in the etc.) that must be satisfied in a given problem. Condition objects are used
problem at hand. Condition objects are used to formulate the to formulate the PINA
PINA :class:`~pina.problem.abstract_problem.AbstractProblem` object. :class:`~pina.problem.abstract_problem.AbstractProblem` object.
Conditions can be specified in four ways:
1. By specifying the input and target of the condition; in such a There are different types of conditions:
case, the model is trained to produce the output points given the input
points. Those points can either be torch.Tensor, LabelTensors, Graph.
Based on the type of the input and target, there are different
implementations of the condition. For more details, see
:class:`~pina.condition.input_target_condition.InputTargetCondition`.
2. By specifying the domain and the equation of the condition; in such - :class:`~pina.condition.input_target_condition.InputTargetCondition`:
a case, the model is trained to minimize the equation residual by Defined by specifying both the input and the target of the condition. In
evaluating it at some samples of the domain. this case, the model is trained to produce the target given the input. The
input and output data must be one of the :class:`torch.Tensor`,
:class:`~pina.label_tensor.LabelTensor`,
:class:`~torch_geometric.data.Data`, or :class:`~pina.graph.Graph`.
Different implementations exist depending on the type of input and target.
For more details, see
:class:`~pina.condition.input_target_condition.InputTargetCondition`.
3. By specifying the input and the equation of the condition; in - :class:`~pina.condition.domain_equation_condition.DomainEquationCondition`
such a case, the model is trained to minimize the equation residual by : Defined by specifying both the domain and the equation of the condition.
evaluating it at the passed input points. The input points must be Here, the model is trained to minimize the equation residual by evaluating
a LabelTensor. Based on the type of the input, there are different it at sampled points within the domain.
implementations of the condition. For more details, see
:class:`~pina.condition.input_equation_condition.InputEquationCondition`
.
4. By specifying only the input data; in such a case the model is - :class:`~pina.condition.input_equation_condition.InputEquationCondition`:
trained with an unsupervised costum loss and uses the data in training. Defined by specifying the input and the equation of the condition. In this
Additionaly conditioning variables can be passed, whenever the model case, the model is trained to minimize the equation residual by evaluating
has extra conditioning variable it depends on. Based on the type of the it at the provided input. The input must be either a
input, there are different implementations of the condition. For more :class:`~pina.label_tensor.LabelTensor` or a :class:`~pina.graph.Graph`.
details, see :class:`~pina.condition.data_condition.DataCondition`. Different implementations exist depending on the type of input. For more
details, see
:class:`~pina.condition.input_equation_condition.InputEquationCondition`.
- :class:`~pina.condition.data_condition.DataCondition`:
Defined by specifying only the input. In this case, the model is trained
with an unsupervised custom loss while using the provided data during
training. The input data must be one of :class:`torch.Tensor`,
:class:`~pina.label_tensor.LabelTensor`,
:class:`~torch_geometric.data.Data`, or :class:`~pina.graph.Graph`.
Additionally, conditional variables can be provided when the model
depends on extra parameters. These conditional variables must be either
:class:`torch.Tensor` or :class:`~pina.label_tensor.LabelTensor`.
Different implementations exist depending on the type of input.
For more details, see
:class:`~pina.condition.data_condition.DataCondition`.
:Example: :Example:
@@ -94,7 +106,8 @@ class Condition:
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
""" """
Check the input arguments and return the appropriate Condition object. Instantiate the appropriate Condition object based on the keyword
arguments passed.
:raises ValueError: If no keyword arguments are passed. :raises ValueError: If no keyword arguments are passed.
:raises ValueError: If the keyword arguments are invalid. :raises ValueError: If the keyword arguments are invalid.

View File

@@ -27,8 +27,8 @@ class ConditionInterface(metaclass=ABCMeta):
""" """
Return the problem to which the condition is associated. Return the problem to which the condition is associated.
:return: Problem to which the condition is associated :return: Problem to which the condition is associated.
:rtype: pina.problem.AbstractProblem :rtype: ~pina.problem.abstract_problem.AbstractProblem
""" """
return self._problem return self._problem

View File

@@ -69,13 +69,12 @@ class DataCondition(ConditionInterface):
:type input: torch.Tensor | LabelTensor | Graph | Data | list[Graph] | :type input: torch.Tensor | LabelTensor | Graph | Data | list[Graph] |
list[Data] | tuple[Graph] | tuple[Data] list[Data] | tuple[Graph] | tuple[Data]
:param conditional_variables: Conditional variables for the condition. :param conditional_variables: Conditional variables for the condition.
:type conditional_variables: torch.Tensor or LabelTensor :type conditional_variables: torch.Tensor | LabelTensor
.. note:: .. note::
If either ``input`` is composed by a list of If ``input`` consists of a list of :class:`~pina.graph.Graph` or
:class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data`, :class:`~torch_geometric.data.Data`, all elements must have the same
all elements must have the same structure (keys and data structure (keys and data types)
types)
""" """
super().__init__() super().__init__()

View File

@@ -16,9 +16,9 @@ class InputEquationCondition(ConditionInterface):
used in a Physics Informed problems. Based on the type of the input, used in a Physics Informed problems. Based on the type of the input,
different condition implementations are available: different condition implementations are available:
- :class:`InputTensorEquationCondition`: For - :class:`InputTensorEquationCondition`: For \
:class:`~pina.label_tensor.LabelTensor` input data. :class:`~pina.label_tensor.LabelTensor` input data.
- :class:`InputGraphEquationCondition`: For :class:`~pina.graph.Graph` - :class:`InputGraphEquationCondition`: For :class:`~pina.graph.Graph` \
input data. input data.
""" """
@@ -65,19 +65,18 @@ class InputEquationCondition(ConditionInterface):
def __init__(self, input, equation): def __init__(self, input, equation):
""" """
Initialize the InputEquationCondition by storing the input and equation. Initialize the object by storing the input data and equation object.
:param input: Input data for the condition. :param input: Input data for the condition.
:type input: pina.label_tensor.LabelTensor | pina.graph.Graph | :type input: LabelTensor | Graph |
list[pina.graph.Graph] | tuple[pina.graph.Graph] list[Graph] | tuple[Graph]
:param EquationInterface equation: Equation object containing the :param EquationInterface equation: Equation object containing the
equation function. equation function.
.. note:: .. note::
If ``input`` is composed by a list of :class:`~pina.graph.Graph` If ``input`` consists of a list of :class:`~pina.graph.Graph` or
objects, all elements must have the same structure (keys and data :class:`~torch_geometric.data.Data`, all elements must have the same
types). Moreover, at least one attribute must be a structure (keys and data types)
:class:`~pina.label_tensor.LabelTensor`.
""" """
super().__init__() super().__init__()

View File

@@ -15,17 +15,17 @@ class InputTargetCondition(ConditionInterface):
both supervised learning and Physics-informed problems. Based on the type of both supervised learning and Physics-informed problems. Based on the type of
the input and target, different condition implementations are available: the input and target, different condition implementations are available:
- :class:`TensorInputTensorTargetCondition`: For :class:`torch.Tensor` or - :class:`TensorInputTensorTargetCondition`: For :class:`torch.Tensor` or \
:class:`~pina.label_tensor.LabelTensor` input and target data. :class:`~pina.label_tensor.LabelTensor` input and target data.
- :class:`TensorInputGraphTargetCondition`: For :class:`torch.Tensor` or - :class:`TensorInputGraphTargetCondition`: For :class:`torch.Tensor` or \
:class:`~pina.label_tensor.LabelTensor` input and :class:`~pina.label_tensor.LabelTensor` input and \
:class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data` :class:`~pina.graph.Graph` or :class:`torch_geometric.data.Data` \
target data. target data.
- :class:`GraphInputTensorTargetCondition`: For :class:`~pina.graph.Graph` - :class:`GraphInputTensorTargetCondition`: For :class:`~pina.graph.Graph` \
or :class:`~torch_geometric.data.Data` input and :class:`torch.Tensor` or :class:`~torch_geometric.data.Data` input and :class:`torch.Tensor` \
or :class:`~pina.label_tensor.LabelTensor` target data. or :class:`~pina.label_tensor.LabelTensor` target data.
- :class:`GraphInputGraphTargetCondition`: For :class:`~pina.graph.Graph` or - :class:`GraphInputGraphTargetCondition`: For :class:`~pina.graph.Graph` \
:class:`~torch_geometric.data.Data` input and target data. or :class:`~torch_geometric.data.Data` input and target data.
""" """
__slots__ = ["input", "target"] __slots__ = ["input", "target"]
@@ -104,10 +104,10 @@ class InputTargetCondition(ConditionInterface):
list[Data] | tuple[Graph] | tuple[Data] list[Data] | tuple[Graph] | tuple[Data]
.. note:: .. note::
If either ``input`` or ``target`` are composed by a list of If either input or target consists of a list of
:class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data` :class:~pina.graph.Graph or :class:~torch_geometric.data.Data
objects, all elements must have the same structure (keys and data objects, all elements must have the same structure (matching
types) keys and data types).
""" """
super().__init__() super().__init__()