1- """Module for AbstractProblem class"""
1+ """Module for the AbstractProblem class"""
22
33from abc import ABCMeta , abstractmethod
44from copy import deepcopy
1111
1212class AbstractProblem (metaclass = ABCMeta ):
1313 """
14- The abstract `AbstractProblem` class. All the class defining a PINA Problem
15- should be inherited from this class.
14+ Abstract base class for PINA problems. All specific problem types should
15+ inherit from this class.
1616
17- In the definition of a PINA problem, the fundamental elements are:
18- the output variables, the condition(s), and the domain(s) where the
19- conditions are applied.
17+ A PINA problem is defined by key components, which typically include output
18+ variables, conditions, and domains over which the conditions are applied.
2019 """
2120
2221 def __init__ (self ):
2322 """
24- TODO
25-
26- :return: _description_
27- :rtype: _type_
23+ Initialization of the :class:`AbstractProblem` class.
2824 """
2925 self ._discretised_domains = {}
3026 # create collector to manage problem data
@@ -48,31 +44,31 @@ def __init__(self):
4844 @property
4945 def batching_dimension (self ):
5046 """
51- TODO
47+ Get batching dimension.
5248
53- :return: _description_
54- :rtype: _type_
49+ :return: The batching dimension.
50+ :rtype int
5551 """
5652 return self ._batching_dimension
5753
5854 @batching_dimension .setter
5955 def batching_dimension (self , value ):
6056 """
61- TODO
57+ Set the batching dimension.
6258
63- :return: _description_
64- :rtype: _type_
59+ :param int value: The batching dimension.
6560 """
6661 self ._batching_dimension = value
6762
6863 # back compatibility 0.1
6964 @property
7065 def input_pts (self ):
7166 """
72- TODO
67+ Return a dictionary mapping condition names to their corresponding
68+ input points.
7369
74- :return: _description_
75- :rtype: _type_
70+ :return: The input points of the problem.
71+ :rtype: dict
7672 """
7773 to_return = {}
7874 for cond_name , cond in self .conditions .items ():
@@ -85,21 +81,21 @@ def input_pts(self):
8581 @property
8682 def discretised_domains (self ):
8783 """
88- TODO
84+ Return a dictionary mapping domains to their corresponding sampled
85+ points.
8986
90- :return: _description_
91- :rtype: _type_
87+ :return: The discretised domains.
88+ :rtype dict
9289 """
9390 return self ._discretised_domains
9491
9592 def __deepcopy__ (self , memo ):
9693 """
97- Implements deepcopy for the
98- :class:`~pina.problem.abstract_problem.AbstractProblem` class.
94+ Perform a deep copy of the :class:`AbstractProblem` instance.
9995
100- :param dict memo: Memory dictionary, to avoid excess copy
101- :return: The deep copy of the
102- :class:`~pina.problem.abstract_problem. AbstractProblem` class
96+ :param dict memo: A dictionary used to track objects already copied
97+ during the deep copy process to prevent redundant copies.
98+ :return: A deep copy of the :class:`AbstractProblem` instance.
10399 :rtype: AbstractProblem
104100 """
105101 cls = self .__class__
@@ -114,7 +110,7 @@ def are_all_domains_discretised(self):
114110 """
115111 Check if all the domains are discretised.
116112
117- :return: True if all the domains are discretised, False otherwise
113+ :return: `` True`` if all domains are discretised, `` False`` otherwise.
118114 :rtype: bool
119115 """
120116 return all (
@@ -124,12 +120,10 @@ def are_all_domains_discretised(self):
124120 @property
125121 def input_variables (self ):
126122 """
127- The input variables of the AbstractProblem, whose type depends on the
128- type of domain (spatial, temporal, and parameter).
129-
130- :return: the input variables of self
131- :rtype: list
123+ Get the input variables of the problem.
132124
125+ :return: The input variables of the problem.
126+ :rtype: list[str]
133127 """
134128 variables = []
135129
@@ -144,51 +138,58 @@ def input_variables(self):
144138
145139 @input_variables .setter
146140 def input_variables (self , variables ):
141+ """
142+ Set the input variables of the AbstractProblem.
143+
144+ :param list[str] variables: The input variables of the problem.
145+ :raises RuntimeError: Not implemented.
146+ """
147147 raise RuntimeError
148148
149149 @property
150150 @abstractmethod
151151 def output_variables (self ):
152152 """
153- The output variables of the problem.
153+ Get the output variables of the problem.
154154 """
155155
156156 @property
157157 @abstractmethod
158158 def conditions (self ):
159159 """
160- The conditions of the problem.
160+ Get the conditions of the problem.
161+
162+ :return: The conditions of the problem.
163+ :rtype: dict
161164 """
162165 return self .conditions
163166
164167 def discretise_domain (
165168 self , n = None , mode = "random" , domains = "all" , sample_rules = None
166169 ):
167170 """
168- Generate a set of points to span the `Location` of all the conditions of
169- the problem .
171+ Discretize the problem's domains by sampling a specified number of
172+ points according to the selected sampling mode .
170173
171- :param n: Number of points to sample, see Note below
172- for reference.
173- :type n: int
174- :param mode: Mode for sampling, defaults to ``random``.
174+ :param int n: The number of points to sample.
175+ :param mode: The sampling method. Default is ``random``.
175176 Available modes include: random sampling, ``random``;
176177 latin hypercube sampling, ``latin`` or ``lh``;
177178 chebyshev sampling, ``chebyshev``; grid sampling ``grid``.
178- :param variables: variable(s) to sample, defaults to 'all'.
179- :type variables: str | list[str]
180- :param domains: Domain from where to sample, defaults to 'all'.
179+ :param domains: The domains from which to sample. Default is ``all``.
181180 :type domains: str | list[str]
181+ :param dict sample_rules: A dictionary of custom sampling rules.
182+ :raises RuntimeError: If both ``n`` and ``sample_rules`` are specified.
183+ :raises RuntimeError: If neither ``n`` nor ``sample_rules`` are set.
182184
183185 :Example:
184- >>> pinn.discretise_domain(n=10, mode='grid')
185- >>> pinn.discretise_domain(n=10, mode='grid', domain=['bound1'])
186- >>> pinn.discretise_domain(n=10, mode='grid', variables=['x'])
186+ >>> problem.discretise_domain(n=10, mode='grid')
187+ >>> problem.discretise_domain(n=10, mode='grid', domains=['gamma1'])
187188
188189 .. warning::
189190 ``random`` is currently the only implemented ``mode`` for all
190191 geometries, i.e. ``EllipsoidDomain``, ``CartesianDomain``,
191- ``SimplexDomain`` and the geometries compositions ``Union``,
192+ ``SimplexDomain``, and geometry compositions ``Union``,
192193 ``Difference``, ``Exclusion``, ``Intersection``. The
193194 modes ``latin`` or ``lh``, ``chebyshev``, ``grid`` are only
194195 implemented for ``CartesianDomain``.
@@ -218,12 +219,31 @@ def discretise_domain(
218219 raise RuntimeError ("You have to specify either n or sample_rules." )
219220
220221 def _apply_default_discretization (self , n , mode , domains ):
222+ """
223+ Apply default discretization to the problem's domains.
224+
225+ :param int n: The number of points to sample.
226+ :param mode: The sampling method.
227+ :param domains: The domains from which to sample.
228+ :type domains: str | list[str]
229+ """
221230 for domain in domains :
222231 self .discretised_domains [domain ] = (
223232 self .domains [domain ].sample (n , mode ).sort_labels ()
224233 )
225234
226235 def _apply_custom_discretization (self , sample_rules , domains ):
236+ """
237+ Apply custom discretization to the problem's domains.
238+
239+ :param dict sample_rules: A dictionary of custom sampling rules.
240+ :param domains: The domains from which to sample.
241+ :type domains: str | list[str]
242+ :raises RuntimeError: If the keys of the sample_rules dictionary are not
243+ the same as the input variables.
244+ :raises RuntimeError: If custom discretisation is applied on a domain
245+ that is not a CartesianDomain.
246+ """
227247 if sorted (list (sample_rules .keys ())) != sorted (self .input_variables ):
228248 raise RuntimeError (
229249 "The keys of the sample_rules dictionary must be the same as "
@@ -247,10 +267,10 @@ def _apply_custom_discretization(self, sample_rules, domains):
247267
248268 def add_points (self , new_points_dict ):
249269 """
250- Add input points to a sampled condition
251- :param new_points_dict: Dictionary of input points (condition_name:
252- LabelTensor)
253- :raises RuntimeError: if at least one condition is not already sampled
270+ Add new points to an already sampled domain.
271+
272+ :param dict new_points_dict: The dictionary mapping new points to their
273+ corresponding domain.
254274 """
255275 for k , v in new_points_dict .items ():
256276 self .discretised_domains [k ] = LabelTensor .vstack (
0 commit comments