@@ -38,9 +38,33 @@ def __init__(self):
3838 self .domains [cond_name ] = cond .domain
3939 cond .domain = cond_name
4040
41- self .data = None
41+ self ._collect_data = {}
42+
43+ @property
44+ def collected_data (self ):
45+ """
46+ Return the collected data from the problem's conditions.
47+
48+ :return: The collected data.
49+ :rtype: dict
50+ """
51+ if not self ._collect_data :
52+ raise RuntimeError (
53+ "You have to call collect_data() before accessing the data."
54+ )
55+ return self ._collect_data
56+
57+ @collected_data .setter
58+ def collected_data (self , data ):
59+ """
60+ Set the collected data from the problem's conditions.
61+
62+ :param dict data: The collected data.
63+ """
64+ self ._collect_data = data
4265
4366 # back compatibility 0.1
67+
4468 @property
4569 def input_pts (self ):
4670 """
@@ -281,25 +305,31 @@ def add_points(self, new_points_dict):
281305 [self .discretised_domains [k ], v ]
282306 )
283307
284- def aggregate_data (self ):
308+ def collect_data (self ):
285309 """
286310 Aggregate data from the problem's conditions into a single dictionary.
287311 """
288- self .data = {}
312+ data = {}
313+ # check if all domains are discretised
289314 if not self .are_all_domains_discretised :
290315 raise RuntimeError (
291316 "All domains must be discretised before aggregating data."
292317 )
318+ # Iterate over the conditions and collect data
293319 for condition_name in self .conditions :
294320 condition = self .conditions [condition_name ]
321+ # Check if the condition has an domain attribute
295322 if hasattr (condition , "domain" ):
323+ # Store the discretisation points
296324 samples = self .discretised_domains [condition .domain ]
297-
298- self .data [condition_name ] = {
325+ data [condition_name ] = {
299326 "input" : samples ,
300327 "equation" : condition .equation ,
301328 }
302329 else :
330+ # If the condition does not have a domain attribute, store
331+ # the input and target points
303332 keys = condition .__slots__
304333 values = [getattr (condition , name ) for name in keys ]
305- self .data [condition_name ] = dict (zip (keys , values ))
334+ data [condition_name ] = dict (zip (keys , values ))
335+ self .collected_data = data
0 commit comments