3434class Config :
3535 """Base class for the SU2 DataMiner configuration.
3636 """
37-
37+
3838 __banner_header :str = "SU2 DataMiner" # Main banner message to be printed in fancy text.
3939
4040 # Output settings
@@ -62,11 +62,11 @@ class Config:
6262 _MLP_biases :list [np .ndarray [float ]] # MLP biases values.
6363
6464 _config_type :str = None # SU2 DataMiner configuration type.
65-
65+
6666 def __init__ (self ):
6767 self ._output_dir = os .getcwd ()
6868 return
69-
69+
7070 def PrintBanner (self ):
7171 """Print the main banner for the SU2 DataMiner configuration in the terminal.
7272 """
@@ -75,7 +75,7 @@ def PrintBanner(self):
7575 print (customfig .renderText (self .__banner_header ))
7676
7777 return
78-
78+
7979 def SetOutputDir (self , output_dir :str ):
8080 """Define the output directory where all raw and processed fluid data and manifold data are saved.
8181
@@ -85,11 +85,11 @@ def SetOutputDir(self, output_dir:str):
8585 """
8686 if not os .path .isdir (output_dir ):
8787 raise Exception ("Invalid output data directory" )
88-
88+
8989 self ._output_dir = output_dir
9090
9191 return
92-
92+
9393 def GetOutputDir (self ):
9494 """Get the output directory where raw and processed fluid data and manifold data are stored.
9595
@@ -102,7 +102,7 @@ def GetOutputDir(self):
102102 raise Exception ("Saved output directory not present on current machine." )
103103 else :
104104 return self ._output_dir
105-
105+
106106 def SetConcatenationFileHeader (self , header :str = DefaultProperties .output_file_header ):
107107 """Define the file name header of the processed fluid manifold data.
108108
@@ -113,7 +113,7 @@ def SetConcatenationFileHeader(self, header:str=DefaultProperties.output_file_he
113113 self .__concatenated_file_header = header
114114
115115 return
116-
116+
117117 def GetConcatenationFileHeader (self ):
118118 """Get the file name header of the processed fluid manifold data.
119119
@@ -122,7 +122,7 @@ def GetConcatenationFileHeader(self):
122122 """
123123
124124 return self .__concatenated_file_header
125-
125+
126126 def SetConfigName (self , config_name :str ):
127127 """Set the name for the current SU2 DataMiner configuration. When saving the configuration, it will be saved under this name.
128128
@@ -133,15 +133,15 @@ def SetConfigName(self, config_name:str):
133133 self ._config_name = config_name
134134
135135 return
136-
136+
137137 def GetConfigName (self ):
138138 """Get the name of the current SU2 DataMiner configuration.
139139
140140 :return: SU2 DataMiner configuration name.
141141 :rtype: str
142142 """
143143 return self ._config_name
144-
144+
145145 def SetControllingVariables (self , names_cv :list [str ]):
146146 """Define the set of controlling variable names used as inputs for the networks of the data-driven fluid model.
147147
@@ -154,7 +154,7 @@ def SetControllingVariables(self, names_cv:list[str]):
154154 self ._controlling_variables .append (c )
155155
156156 return
157-
157+
158158 def GetControllingVariables (self ):
159159 """Retrieve the set of controlling variable names used as inputs for the networks of the data-driven fluid model.
160160
@@ -163,7 +163,7 @@ def GetControllingVariables(self):
163163 """
164164
165165 return self ._controlling_variables
166-
166+
167167 def SetTrainFraction (self , input :float = DefaultProperties .train_fraction ):
168168 """Define the fraction of fluid data used for MLP training.
169169
@@ -177,7 +177,7 @@ def SetTrainFraction(self, input:float=DefaultProperties.train_fraction):
177177 self .__train_fraction = input
178178
179179 return
180-
180+
181181 def SetTestFraction (self , input :float = DefaultProperties .test_fraction ):
182182 """Define the fraction of fluid data used for MLP prediction accuracy evaluation.
183183
@@ -191,15 +191,15 @@ def SetTestFraction(self, input:float=DefaultProperties.test_fraction):
191191 self .__test_fraction = input
192192
193193 return
194-
194+
195195 def GetTrainFraction (self ):
196196 """Get the fraction of fluid data used for MLP training.
197197
198198 :return: fluid data train fraction.
199199 :rtype: float
200200 """
201201 return self .__train_fraction
202-
202+
203203 def GetTestFraction (self ):
204204 """Get the fraction of fluid data used for MLP accuracy evaluation.
205205
@@ -208,16 +208,16 @@ def GetTestFraction(self):
208208 """
209209
210210 return self .__test_fraction
211-
211+
212212 def GetAlphaExpo (self ):
213213 """Get the initial learning rate exponent (base 10).
214214
215215 :return: log10 of initial learning rate.
216216 :rtype: float
217217 """
218-
218+
219219 return self ._alpha_expo
220-
220+
221221 def SetAlphaExpo (self , alpha_expo_in :float = DefaultProperties .init_learning_rate_expo ):
222222 """Define the initial learning rate exponent (base 10).
223223
@@ -230,28 +230,28 @@ def SetAlphaExpo(self, alpha_expo_in:float=DefaultProperties.init_learning_rate_
230230 raise Exception ("Initial learning rate exponent should be negative." )
231231 self ._alpha_expo = alpha_expo_in
232232 return
233-
233+
234234 def GetLRDecay (self ):
235235 """Get the exponential learning rate decay parameter for MLP training.
236236
237237 :return: Exponential learning rate decay parameter.
238238 :rtype: float
239239 """
240240 return self ._lr_decay
241-
241+
242242 def SetLRDecay (self , lr_decay_in :float = DefaultProperties .learning_rate_decay ):
243243 """Set the exponential learning rate decay parameter for MLP training.
244244
245245 :param lr_decay_in: Exponential learning rate decay parameter, defaults to DefaultProperties.learning_rate_decay
246246 :type lr_decay_in: float, optional
247247 :raises Exception: if the learning rate decay parameter is not within zero and one.
248248 """
249-
249+
250250 if lr_decay_in <= 0 or lr_decay_in > 1.0 :
251251 raise Exception ("Learning rate decay parameter should be between zero and one." )
252252 self ._lr_decay = lr_decay_in
253253 return
254-
254+
255255 def SetNEpochs (self , n_epochs_in :int = DefaultProperties .N_epochs ):
256256 """Specify the maximum number of epochs for training of the networks.
257257
@@ -261,18 +261,18 @@ def SetNEpochs(self, n_epochs_in:int=DefaultProperties.N_epochs):
261261 """
262262 if n_epochs_in < 1 :
263263 raise Exception ("Number of epochs should be higher than 1" )
264-
264+
265265 self ._n_epochs = int (n_epochs_in )
266266 return
267-
267+
268268 def GetNEpochs (self ):
269269 """Retrieve the maximum number of epochs the networks are trained for.
270270
271271 :return: maximum number of training epochs.
272272 :rtype: int
273273 """
274274 return self ._n_epochs
275-
275+
276276 def SetBatchExpo (self , batch_expo_in :int = DefaultProperties .batch_size_exponent ):
277277 """Set the mini-batch size exponent (base 2) for MLP training.
278278
@@ -285,15 +285,15 @@ def SetBatchExpo(self, batch_expo_in:int=DefaultProperties.batch_size_exponent):
285285 raise Exception ("Mini-batch size exponent should be positive." )
286286 self ._batch_expo = int (batch_expo_in )
287287 return
288-
288+
289289 def GetBatchExpo (self ):
290290 """Get the MLP training mini-batch size exponent.
291291
292292 :return: mini-batch size exponent (base 2)
293293 :rtype: int
294294 """
295295 return self ._batch_expo
296-
296+
297297 def __HiddenLayerChecks (self ,hidden_layer_architecture :list [int ]):
298298 if not hidden_layer_architecture :
299299 raise Exception ("At least one hidden layer should be specified." )
@@ -303,7 +303,7 @@ def __HiddenLayerChecks(self,hidden_layer_architecture:list[int]):
303303 if type (h ) is not int :
304304 raise Exception ("Nodes in the hidden layers should be integers." )
305305 return
306-
306+
307307 def SetHiddenLayerArchitecture (self , hidden_layer_architecture :list [int ]= DefaultProperties .hidden_layer_architecture ):
308308 """
309309 Define the hidden layer architecture of the multi-layer perceptron used for the MLP-based manifold.
@@ -319,15 +319,15 @@ def SetHiddenLayerArchitecture(self, hidden_layer_architecture:list[int]=Default
319319 for n in hidden_layer_architecture :
320320 self ._hidden_layer_architecture .append (n )
321321 return
322-
322+
323323 def GetHiddenLayerArchitecture (self ):
324324 """Get the hidden layer architecture of the multi-layer perceptron used for the MLP-based manifold.
325325
326326 :return: list with number of neurons per hidden layer.
327327 :rtype: list[str]
328328 """
329329 return self ._hidden_layer_architecture
330-
330+
331331 def __WeightsCheck (self , weights :list [np .ndarray [float ]]):
332332 if not weights :
333333 raise Exception ("Weights list should contain at least one array." )
@@ -337,8 +337,8 @@ def __WeightsCheck(self, weights:list[np.ndarray[float]]):
337337 if np .shape (w_i )[1 ] != np .shape (w_ip )[0 ]:
338338 raise Exception ("Weight arrays are improperly formatted. Check rows and columns." )
339339 return
340-
341-
340+
341+
342342 def SetWeights (self , weights :list [np .ndarray [float ]]):
343343 """Store the weight values of the neural network.
344344
@@ -352,15 +352,15 @@ def SetWeights(self, weights:list[np.ndarray[float]]):
352352 for w in weights :
353353 self ._MLP_weights .append (w )
354354 return
355-
355+
356356 def __BiasesCheck (self , biases :list [np .ndarray [float ]]):
357357 if not biases :
358358 raise Exception ("Biases list should contain at least one entry." )
359359 for b in biases :
360360 if b .size == 0 :
361361 raise Exception ("Biases for hidden layers should contain at least one value." )
362362 return
363-
363+
364364 def SetBiases (self , biases :list [np .ndarray [float ]]):
365365 """Store the bias values of the neural network.
366366
@@ -374,7 +374,7 @@ def SetBiases(self, biases:list[np.ndarray[float]]):
374374 for w in biases :
375375 self ._MLP_biases .append (w )
376376 return
377-
377+
378378 def SetActivationFunction (self , activation_function_in :str = DefaultProperties .activation_function ):
379379 """Define the hidden layer activation function for the MLP-based manifold. See Common.Properties.ActivationFunctionOptions for the supported options.
380380
@@ -386,15 +386,15 @@ def SetActivationFunction(self, activation_function_in:str=DefaultProperties.act
386386 raise Exception ("Activation function " + activation_function_in + " not in available options." )
387387 self ._activation_function = activation_function_in
388388 return
389-
389+
390390 def GetActivationFunction (self ):
391391 """Get the hidden layer activation function name.
392392
393393 :return: hidden layer activation function name.
394394 :rtype: str
395395 """
396396 return self ._activation_function
397-
397+
398398 def UpdateMLPHyperParams (self , trainer ):
399399 """Retrieve the weights and biases from the MLP trainer class and store them in the configuration class.
400400
@@ -417,17 +417,17 @@ def UpdateMLPHyperParams(self, trainer):
417417 self ._MLP_weights = trainer .GetWeights ().copy ()
418418 self ._MLP_biases = trainer .GetBiases ().copy ()
419419 self ._hidden_layer_architecture = [h for h in trainer .architecture ]
420-
420+
421421 return
422-
422+
423423 def GetWeightsBiases (self ):
424424 """Return values for weights and biases for the hidden layers in the MLP.
425425
426426 :return: weight arrays, biases arrays
427427 :rtype: tuple(np.ndarray[float])
428428 """
429429 return self ._MLP_weights , self ._MLP_biases
430-
430+
431431 def WriteSU2MLP (self , file_name_out :str ):
432432 """Write ASCII MLP file containing the network weights and biases from the data stored in the configuration.
433433
@@ -454,4 +454,3 @@ def SaveConfig(self):
454454 pickle .dump (self , file )
455455 file .close ()
456456 return
457-
0 commit comments