2323# |
2424#=============================================================================================#
2525
26- import os
26+ import os
2727import pyfiglet
2828import pickle
29- import numpy as np
29+ import numpy as np
3030
3131from Common .Properties import DefaultProperties , ActivationFunctionOptions
3232from Common .CommonMethods import write_SU2_MLP
@@ -65,7 +65,7 @@ class Config:
6565
6666 def __init__ (self ):
6767 self ._output_dir = os .getcwd ()
68- return
68+ return
6969
7070 def PrintBanner (self ):
7171 """Print the main banner for the SU2 DataMiner configuration in the terminal.
@@ -74,7 +74,7 @@ def PrintBanner(self):
7474 customfig = pyfiglet .Figlet (font = "slant" )
7575 print (customfig .renderText (self .__banner_header ))
7676
77- return
77+ return
7878
7979 def SetOutputDir (self , output_dir :str ):
8080 """Define the output directory where all raw and processed fluid data and manifold data are saved.
@@ -88,7 +88,7 @@ def SetOutputDir(self, output_dir:str):
8888
8989 self ._output_dir = output_dir
9090
91- return
91+ return
9292
9393 def GetOutputDir (self ):
9494 """Get the output directory where raw and processed fluid data and manifold data are stored.
@@ -110,9 +110,9 @@ def SetConcatenationFileHeader(self, header:str=DefaultProperties.output_file_he
110110 :type header: str, optional
111111 """
112112
113- self .__concatenated_file_header = header
113+ self .__concatenated_file_header = header
114114
115- return
115+ return
116116
117117 def GetConcatenationFileHeader (self ):
118118 """Get the file name header of the processed fluid manifold data.
@@ -130,17 +130,17 @@ def SetConfigName(self, config_name:str):
130130 :type config_name: str
131131 """
132132
133- self ._config_name = config_name
133+ self ._config_name = config_name
134134
135- return
135+ return
136136
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 """
143- return self ._config_name
143+ return self ._config_name
144144
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.
@@ -153,7 +153,7 @@ def SetControllingVariables(self, names_cv:list[str]):
153153 for c in names_cv :
154154 self ._controlling_variables .append (c )
155155
156- return
156+ return
157157
158158 def GetControllingVariables (self ):
159159 """Retrieve the set of controlling variable names used as inputs for the networks of the data-driven fluid model.
@@ -174,9 +174,9 @@ def SetTrainFraction(self, input:float=DefaultProperties.train_fraction):
174174
175175 if input >= 1 or input <= 0 :
176176 raise Exception ("Training data fraction should be between zero and one." )
177- self .__train_fraction = input
177+ self .__train_fraction = input
178178
179- return
179+ return
180180
181181 def SetTestFraction (self , input :float = DefaultProperties .test_fraction ):
182182 """Define the fraction of fluid data used for MLP prediction accuracy evaluation.
@@ -188,9 +188,9 @@ def SetTestFraction(self, input:float=DefaultProperties.test_fraction):
188188
189189 if input >= 1 or input <= 0 :
190190 raise Exception ("Test data fraction should be between zero and one." )
191- self .__test_fraction = input
191+ self .__test_fraction = input
192192
193- return
193+ return
194194
195195 def GetTrainFraction (self ):
196196 """Get the fraction of fluid data used for MLP training.
@@ -229,7 +229,7 @@ def SetAlphaExpo(self, alpha_expo_in:float=DefaultProperties.init_learning_rate_
229229 if alpha_expo_in >= 0 :
230230 raise Exception ("Initial learning rate exponent should be negative." )
231231 self ._alpha_expo = alpha_expo_in
232- return
232+ return
233233
234234 def GetLRDecay (self ):
235235 """Get the exponential learning rate decay parameter for MLP training.
@@ -250,7 +250,7 @@ def SetLRDecay(self, lr_decay_in:float=DefaultProperties.learning_rate_decay):
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
253- return
253+ return
254254
255255 def SetNEpochs (self , n_epochs_in :int = DefaultProperties .N_epochs ):
256256 """Specify the maximum number of epochs for training of the networks.
@@ -263,7 +263,7 @@ def SetNEpochs(self, n_epochs_in:int=DefaultProperties.N_epochs):
263263 raise Exception ("Number of epochs should be higher than 1" )
264264
265265 self ._n_epochs = int (n_epochs_in )
266- return
266+ return
267267
268268 def GetNEpochs (self ):
269269 """Retrieve the maximum number of epochs the networks are trained for.
@@ -284,15 +284,15 @@ def SetBatchExpo(self, batch_expo_in:int=DefaultProperties.batch_size_exponent):
284284 if batch_expo_in <= 0 :
285285 raise Exception ("Mini-batch size exponent should be positive." )
286286 self ._batch_expo = int (batch_expo_in )
287- return
287+ return
288288
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 """
295- return self ._batch_expo
295+ return self ._batch_expo
296296
297297 def __HiddenLayerChecks (self ,hidden_layer_architecture :list [int ]):
298298 if not hidden_layer_architecture :
@@ -302,7 +302,7 @@ def __HiddenLayerChecks(self,hidden_layer_architecture:list[int]):
302302 raise Exception ("Number of nodes in the hidden layers should be positive." )
303303 if type (h ) is not int :
304304 raise Exception ("Nodes in the hidden layers should be integers." )
305- return
305+ return
306306
307307 def SetHiddenLayerArchitecture (self , hidden_layer_architecture :list [int ]= DefaultProperties .hidden_layer_architecture ):
308308 """
@@ -318,7 +318,7 @@ def SetHiddenLayerArchitecture(self, hidden_layer_architecture:list[int]=Default
318318 self ._hidden_layer_architecture = []
319319 for n in hidden_layer_architecture :
320320 self ._hidden_layer_architecture .append (n )
321- return
321+ return
322322
323323 def GetHiddenLayerArchitecture (self ):
324324 """Get the hidden layer architecture of the multi-layer perceptron used for the MLP-based manifold.
@@ -336,7 +336,7 @@ def __WeightsCheck(self, weights:list[np.ndarray[float]]):
336336 w_ip = weights [i + 1 ]
337337 if np .shape (w_i )[1 ] != np .shape (w_ip )[0 ]:
338338 raise Exception ("Weight arrays are improperly formatted. Check rows and columns." )
339- return
339+ return
340340
341341
342342 def SetWeights (self , weights :list [np .ndarray [float ]]):
@@ -351,15 +351,15 @@ def SetWeights(self, weights:list[np.ndarray[float]]):
351351 self ._MLP_weights = []
352352 for w in weights :
353353 self ._MLP_weights .append (w )
354- return
354+ return
355355
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." )
362- return
362+ return
363363
364364 def SetBiases (self , biases :list [np .ndarray [float ]]):
365365 """Store the bias values of the neural network.
@@ -373,7 +373,7 @@ def SetBiases(self, biases:list[np.ndarray[float]]):
373373 self ._MLP_biases = []
374374 for w in biases :
375375 self ._MLP_biases .append (w )
376- return
376+ return
377377
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.
@@ -384,8 +384,8 @@ def SetActivationFunction(self, activation_function_in:str=DefaultProperties.act
384384 """
385385 if activation_function_in not in ActivationFunctionOptions .keys ():
386386 raise Exception ("Activation function " + activation_function_in + " not in available options." )
387- self ._activation_function = activation_function_in
388- return
387+ self ._activation_function = activation_function_in
388+ return
389389
390390 def GetActivationFunction (self ):
391391 """Get the hidden layer activation function name.
@@ -418,7 +418,7 @@ def UpdateMLPHyperParams(self, trainer):
418418 self ._MLP_biases = trainer .GetBiases ().copy ()
419419 self ._hidden_layer_architecture = [h for h in trainer .architecture ]
420420
421- return
421+ return
422422
423423 def GetWeightsBiases (self ):
424424 """Return values for weights and biases for the hidden layers in the MLP.
@@ -453,5 +453,5 @@ def SaveConfig(self):
453453 file = open (self ._config_name + '.cfg' ,'wb' )
454454 pickle .dump (self , file )
455455 file .close ()
456- return
456+ return
457457
0 commit comments