Skip to content

Commit 53be672

Browse files
committed
Fix conditions rendering
1 parent 2edf4ea commit 53be672

File tree

5 files changed

+71
-60
lines changed

5 files changed

+71
-60
lines changed

pina/condition/condition.py

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,37 +29,49 @@ def warning_function(new, old):
2929

3030
class Condition:
3131
"""
32-
The class ``Condition`` is used to represent the constraints (physical
33-
equations, boundary conditions, etc.) that should be satisfied in the
34-
problem at hand. Condition objects are used to formulate the
35-
PINA :class:`~pina.problem.abstract_problem.AbstractProblem` object.
36-
Conditions can be specified in four ways:
37-
38-
1. By specifying the input and target of the condition; in such a
39-
case, the model is trained to produce the output points given the input
40-
points. Those points can either be torch.Tensor, LabelTensors, Graph.
41-
Based on the type of the input and target, there are different
42-
implementations of the condition. For more details, see
43-
:class:`~pina.condition.input_target_condition.InputTargetCondition`.
44-
45-
2. By specifying the domain and the equation of the condition; in such
46-
a case, the model is trained to minimize the equation residual by
47-
evaluating it at some samples of the domain.
48-
49-
3. By specifying the input and the equation of the condition; in
50-
such a case, the model is trained to minimize the equation residual by
51-
evaluating it at the passed input points. The input points must be
52-
a LabelTensor. Based on the type of the input, there are different
53-
implementations of the condition. For more details, see
54-
:class:`~pina.condition.input_equation_condition.InputEquationCondition`
55-
.
56-
57-
4. By specifying only the input data; in such a case the model is
58-
trained with an unsupervised costum loss and uses the data in training.
59-
Additionaly conditioning variables can be passed, whenever the model
60-
has extra conditioning variable it depends on. Based on the type of the
61-
input, there are different implementations of the condition. For more
62-
details, see :class:`~pina.condition.data_condition.DataCondition`.
32+
Represents constraints (such as physical equations, boundary conditions,
33+
etc.) that must be satisfied in a given problem. Condition objects are used
34+
to formulate the PINA
35+
:class:`~pina.problem.abstract_problem.AbstractProblem` object.
36+
37+
There are different types of conditions:
38+
39+
- :class:`~pina.condition.input_target_condition.InputTargetCondition`:
40+
Defined by specifying both the input and the target of the condition. In
41+
this case, the model is trained to produce the target given the input. The
42+
input and output data must be one of the :class:`torch.Tensor`,
43+
:class:`~pina.label_tensor.LabelTensor`,
44+
:class:`~torch_geometric.data.Data`, or :class:`~pina.graph.Graph`.
45+
Different implementations exist depending on the type of input and target.
46+
For more details, see
47+
:class:`~pina.condition.input_target_condition.InputTargetCondition`.
48+
49+
- :class:`~pina.condition.domain_equation_condition.DomainEquationCondition`
50+
: Defined by specifying both the domain and the equation of the condition.
51+
Here, the model is trained to minimize the equation residual by evaluating
52+
it at sampled points within the domain.
53+
54+
- :class:`~pina.condition.input_equation_condition.InputEquationCondition`:
55+
Defined by specifying the input and the equation of the condition. In this
56+
case, the model is trained to minimize the equation residual by evaluating
57+
it at the provided input. The input must be either a
58+
:class:`~pina.label_tensor.LabelTensor` or a :class:`~pina.graph.Graph`.
59+
Different implementations exist depending on the type of input. For more
60+
details, see
61+
:class:`~pina.condition.input_equation_condition.InputEquationCondition`.
62+
63+
- :class:`~pina.condition.data_condition.DataCondition`:
64+
Defined by specifying only the input. In this case, the model is trained
65+
with an unsupervised custom loss while using the provided data during
66+
training. The input data must be one of :class:`torch.Tensor`,
67+
:class:`~pina.label_tensor.LabelTensor`,
68+
:class:`~torch_geometric.data.Data`, or :class:`~pina.graph.Graph`.
69+
Additionally, conditional variables can be provided when the model
70+
depends on extra parameters. These conditional variables must be either
71+
:class:`torch.Tensor` or :class:`~pina.label_tensor.LabelTensor`.
72+
Different implementations exist depending on the type of input.
73+
For more details, see
74+
:class:`~pina.condition.data_condition.DataCondition`.
6375
6476
:Example:
6577
@@ -94,7 +106,8 @@ class Condition:
94106

95107
def __new__(cls, *args, **kwargs):
96108
"""
97-
Check the input arguments and return the appropriate Condition object.
109+
Instantiate the appropriate Condition object based on the keyword
110+
arguments passed.
98111
99112
:raises ValueError: If no keyword arguments are passed.
100113
:raises ValueError: If the keyword arguments are invalid.

pina/condition/condition_interface.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ def problem(self):
2727
"""
2828
Return the problem to which the condition is associated.
2929
30-
:return: Problem to which the condition is associated
31-
:rtype: pina.problem.AbstractProblem
30+
:return: Problem to which the condition is associated.
31+
:rtype: ~pina.problem.abstract_problem.AbstractProblem
3232
"""
3333
return self._problem
3434

pina/condition/data_condition.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,12 @@ def __init__(self, input, conditional_variables=None):
6969
:type input: torch.Tensor | LabelTensor | Graph | Data | list[Graph] |
7070
list[Data] | tuple[Graph] | tuple[Data]
7171
:param conditional_variables: Conditional variables for the condition.
72-
:type conditional_variables: torch.Tensor or LabelTensor
72+
:type conditional_variables: torch.Tensor | LabelTensor
7373
7474
.. note::
75-
If either ``input`` is composed by a list of
76-
:class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data`,
77-
all elements must have the same structure (keys and data
78-
types)
75+
If ``input`` consists of a list of :class:`~pina.graph.Graph` or
76+
:class:`~torch_geometric.data.Data`, all elements must have the same
77+
structure (keys and data types)
7978
"""
8079

8180
super().__init__()

pina/condition/input_equation_condition.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class InputEquationCondition(ConditionInterface):
1616
used in a Physics Informed problems. Based on the type of the input,
1717
different condition implementations are available:
1818
19-
- :class:`InputTensorEquationCondition`: For
19+
- :class:`InputTensorEquationCondition`: For \
2020
:class:`~pina.label_tensor.LabelTensor` input data.
21-
- :class:`InputGraphEquationCondition`: For :class:`~pina.graph.Graph`
21+
- :class:`InputGraphEquationCondition`: For :class:`~pina.graph.Graph` \
2222
input data.
2323
"""
2424

@@ -65,19 +65,18 @@ def __new__(cls, input, equation):
6565

6666
def __init__(self, input, equation):
6767
"""
68-
Initialize the InputEquationCondition by storing the input and equation.
68+
Initialize the object by storing the input data and equation object.
6969
7070
:param input: Input data for the condition.
71-
:type input: pina.label_tensor.LabelTensor | pina.graph.Graph |
72-
list[pina.graph.Graph] | tuple[pina.graph.Graph]
71+
:type input: LabelTensor | Graph |
72+
list[Graph] | tuple[Graph]
7373
:param EquationInterface equation: Equation object containing the
7474
equation function.
7575
7676
.. note::
77-
If ``input`` is composed by a list of :class:`~pina.graph.Graph`
78-
objects, all elements must have the same structure (keys and data
79-
types). Moreover, at least one attribute must be a
80-
:class:`~pina.label_tensor.LabelTensor`.
77+
If ``input`` consists of a list of :class:`~pina.graph.Graph` or
78+
:class:`~torch_geometric.data.Data`, all elements must have the same
79+
structure (keys and data types)
8180
"""
8281

8382
super().__init__()

pina/condition/input_target_condition.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ class InputTargetCondition(ConditionInterface):
1515
both supervised learning and Physics-informed problems. Based on the type of
1616
the input and target, different condition implementations are available:
1717
18-
- :class:`TensorInputTensorTargetCondition`: For :class:`torch.Tensor` or
18+
- :class:`TensorInputTensorTargetCondition`: For :class:`torch.Tensor` or \
1919
:class:`~pina.label_tensor.LabelTensor` input and target data.
20-
- :class:`TensorInputGraphTargetCondition`: For :class:`torch.Tensor` or
21-
:class:`~pina.label_tensor.LabelTensor` input and
22-
:class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data`
20+
- :class:`TensorInputGraphTargetCondition`: For :class:`torch.Tensor` or \
21+
:class:`~pina.label_tensor.LabelTensor` input and \
22+
:class:`~pina.graph.Graph` or :class:`torch_geometric.data.Data` \
2323
target data.
24-
- :class:`GraphInputTensorTargetCondition`: For :class:`~pina.graph.Graph`
25-
or :class:`~torch_geometric.data.Data` input and :class:`torch.Tensor`
24+
- :class:`GraphInputTensorTargetCondition`: For :class:`~pina.graph.Graph` \
25+
or :class:`~torch_geometric.data.Data` input and :class:`torch.Tensor` \
2626
or :class:`~pina.label_tensor.LabelTensor` target data.
27-
- :class:`GraphInputGraphTargetCondition`: For :class:`~pina.graph.Graph` or
28-
:class:`~torch_geometric.data.Data` input and target data.
27+
- :class:`GraphInputGraphTargetCondition`: For :class:`~pina.graph.Graph` \
28+
or :class:`~torch_geometric.data.Data` input and target data.
2929
"""
3030

3131
__slots__ = ["input", "target"]
@@ -104,10 +104,10 @@ def __init__(self, input, target):
104104
list[Data] | tuple[Graph] | tuple[Data]
105105
106106
.. note::
107-
If either ``input`` or ``target`` are composed by a list of
108-
:class:`~pina.graph.Graph` or :class:`~torch_geometric.data.Data`
109-
objects, all elements must have the same structure (keys and data
110-
types)
107+
If either input or target consists of a list of
108+
:class:~pina.graph.Graph or :class:~torch_geometric.data.Data
109+
objects, all elements must have the same structure (matching
110+
keys and data types).
111111
"""
112112

113113
super().__init__()

0 commit comments

Comments
 (0)