From 05105dd517aba1cba83bbd798b99b82368b22335 Mon Sep 17 00:00:00 2001 From: FilippoOlivo Date: Fri, 14 Mar 2025 14:51:40 +0100 Subject: [PATCH] Fix conditions rendering --- pina/condition/condition.py | 69 +++++++++++++--------- pina/condition/condition_interface.py | 4 +- pina/condition/data_condition.py | 9 ++- pina/condition/input_equation_condition.py | 17 +++--- pina/condition/input_target_condition.py | 24 ++++---- 5 files changed, 67 insertions(+), 56 deletions(-) diff --git a/pina/condition/condition.py b/pina/condition/condition.py index f8a81f9..5ad4d36 100644 --- a/pina/condition/condition.py +++ b/pina/condition/condition.py @@ -29,37 +29,49 @@ def warning_function(new, old): class Condition: """ - The class ``Condition`` is used to represent the constraints (physical - equations, boundary conditions, etc.) that should be satisfied in the - problem at hand. Condition objects are used to formulate the - PINA :class:`~pina.problem.abstract_problem.AbstractProblem` object. - Conditions can be specified in four ways: + Represents constraints (such as physical equations, boundary conditions, + etc.) that must be satisfied in a given problem. Condition objects are used + to formulate the PINA + :class:`~pina.problem.abstract_problem.AbstractProblem` object. - 1. By specifying the input and target of the condition; in such a - 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`. + There are different types of conditions: - 2. By specifying the domain and the equation of the condition; in such - a case, the model is trained to minimize the equation residual by - evaluating it at some samples of the domain. + - :class:`~pina.condition.input_target_condition.InputTargetCondition`: + Defined by specifying both the input and the target of the condition. In + 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 - such a case, the model is trained to minimize the equation residual by - evaluating it at the passed input points. The input points must be - a LabelTensor. Based on the type of the input, there are different - implementations of the condition. For more details, see - :class:`~pina.condition.input_equation_condition.InputEquationCondition` - . + - :class:`~pina.condition.domain_equation_condition.DomainEquationCondition` + : Defined by specifying both the domain and the equation of the condition. + Here, the model is trained to minimize the equation residual by evaluating + it at sampled points within the domain. - 4. By specifying only the input data; in such a case the model is - trained with an unsupervised costum loss and uses the data in training. - Additionaly conditioning variables can be passed, whenever the model - has extra conditioning variable it depends on. Based on the type of the - input, there are different implementations of the condition. For more - details, see :class:`~pina.condition.data_condition.DataCondition`. + - :class:`~pina.condition.input_equation_condition.InputEquationCondition`: + Defined by specifying the input and the equation of the condition. In this + case, the model is trained to minimize the equation residual by evaluating + it at the provided input. The input must be either a + :class:`~pina.label_tensor.LabelTensor` or a :class:`~pina.graph.Graph`. + 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: @@ -94,7 +106,8 @@ class Condition: 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 the keyword arguments are invalid. diff --git a/pina/condition/condition_interface.py b/pina/condition/condition_interface.py index 41dfa7b..8610283 100644 --- a/pina/condition/condition_interface.py +++ b/pina/condition/condition_interface.py @@ -27,8 +27,8 @@ class ConditionInterface(metaclass=ABCMeta): """ Return the problem to which the condition is associated. - :return: Problem to which the condition is associated - :rtype: pina.problem.AbstractProblem + :return: Problem to which the condition is associated. + :rtype: ~pina.problem.abstract_problem.AbstractProblem """ return self._problem diff --git a/pina/condition/data_condition.py b/pina/condition/data_condition.py index 196c3d2..783282d 100644 --- a/pina/condition/data_condition.py +++ b/pina/condition/data_condition.py @@ -69,13 +69,12 @@ class DataCondition(ConditionInterface): :type input: torch.Tensor | LabelTensor | Graph | Data | list[Graph] | list[Data] | tuple[Graph] | tuple[Data] :param conditional_variables: Conditional variables for the condition. - :type conditional_variables: torch.Tensor or LabelTensor + :type conditional_variables: torch.Tensor | LabelTensor .. note:: - If either ``input`` is composed by a list of - :class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data`, - all elements must have the same structure (keys and data - types) + If ``input`` consists of a list of :class:`~pina.graph.Graph` or + :class:`~torch_geometric.data.Data`, all elements must have the same + structure (keys and data types) """ super().__init__() diff --git a/pina/condition/input_equation_condition.py b/pina/condition/input_equation_condition.py index 16a521c..ef9b1e3 100644 --- a/pina/condition/input_equation_condition.py +++ b/pina/condition/input_equation_condition.py @@ -16,9 +16,9 @@ class InputEquationCondition(ConditionInterface): used in a Physics Informed problems. Based on the type of the input, different condition implementations are available: - - :class:`InputTensorEquationCondition`: For + - :class:`InputTensorEquationCondition`: For \ :class:`~pina.label_tensor.LabelTensor` input data. - - :class:`InputGraphEquationCondition`: For :class:`~pina.graph.Graph` + - :class:`InputGraphEquationCondition`: For :class:`~pina.graph.Graph` \ input data. """ @@ -65,19 +65,18 @@ class InputEquationCondition(ConditionInterface): 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. - :type input: pina.label_tensor.LabelTensor | pina.graph.Graph | - list[pina.graph.Graph] | tuple[pina.graph.Graph] + :type input: LabelTensor | Graph | + list[Graph] | tuple[Graph] :param EquationInterface equation: Equation object containing the equation function. .. note:: - If ``input`` is composed by a list of :class:`~pina.graph.Graph` - objects, all elements must have the same structure (keys and data - types). Moreover, at least one attribute must be a - :class:`~pina.label_tensor.LabelTensor`. + If ``input`` consists of a list of :class:`~pina.graph.Graph` or + :class:`~torch_geometric.data.Data`, all elements must have the same + structure (keys and data types) """ super().__init__() diff --git a/pina/condition/input_target_condition.py b/pina/condition/input_target_condition.py index 3ed571d..d39fb28 100644 --- a/pina/condition/input_target_condition.py +++ b/pina/condition/input_target_condition.py @@ -15,17 +15,17 @@ class InputTargetCondition(ConditionInterface): both supervised learning and Physics-informed problems. Based on the type of 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:`TensorInputGraphTargetCondition`: For :class:`torch.Tensor` or - :class:`~pina.label_tensor.LabelTensor` input and - :class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data` + - :class:`TensorInputGraphTargetCondition`: For :class:`torch.Tensor` or \ + :class:`~pina.label_tensor.LabelTensor` input and \ + :class:`~pina.graph.Graph` or :class:`torch_geometric.data.Data` \ target data. - - :class:`GraphInputTensorTargetCondition`: For :class:`~pina.graph.Graph` - or :class:`~torch_geometric.data.Data` input and :class:`torch.Tensor` + - :class:`GraphInputTensorTargetCondition`: For :class:`~pina.graph.Graph` \ + or :class:`~torch_geometric.data.Data` input and :class:`torch.Tensor` \ or :class:`~pina.label_tensor.LabelTensor` target data. - - :class:`GraphInputGraphTargetCondition`: For :class:`~pina.graph.Graph` or - :class:`~torch_geometric.data.Data` input and target data. + - :class:`GraphInputGraphTargetCondition`: For :class:`~pina.graph.Graph` \ + or :class:`~torch_geometric.data.Data` input and target data. """ __slots__ = ["input", "target"] @@ -104,10 +104,10 @@ class InputTargetCondition(ConditionInterface): list[Data] | tuple[Graph] | tuple[Data] .. note:: - If either ``input`` or ``target`` are composed by a list of - :class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data` - objects, all elements must have the same structure (keys and data - types) + If either input or target consists of a list of + :class:~pina.graph.Graph or :class:~torch_geometric.data.Data + objects, all elements must have the same structure (matching + keys and data types). """ super().__init__()