1616
1717NN_PARAMETERS = ["nodes_per_layer" , "optimizer" , "activation_per_layer" ]
1818HYPEROPTIMIZED_PARAMETERS = [
19- "nodes_per_layer" ,
20- "optimizer" ,
21- "learning_rate" ,
19+ "nodes_per_layer" ,
20+ "optimizer" ,
21+ "learning_rate" ,
2222 "clipnorm" ,
2323 "activation_per_layer" ,
2424 "initializer" ,
2525 "epochs" ,
2626 "stopping_patience" ,
2727 "layer_type" ,
28- "dropout"
29- ]
28+ "dropout" ,
29+ ]
3030
3131
3232def _is_floatable (num ):
@@ -40,13 +40,17 @@ def _is_floatable(num):
4040 except (ValueError , TypeError ):
4141 return False
4242
43+
4344def check_hyperopt_parameters (parameters , trial_specs ):
4445 tmp = []
4546 for param in HYPEROPTIMIZED_PARAMETERS :
4647 if param in parameters .keys ():
4748 tmp .append (param )
4849 if tmp :
49- raise CheckError (f"Parameters { tmp } already contained in the hyperoptimization scan. Please remove them from the parameters namespace." )
50+ raise CheckError (
51+ f"Parameters { tmp } already contained in the hyperoptimization scan. Please remove them from the parameters namespace."
52+ )
53+
5054
5155# Checks on the NN parameters
5256def check_existing_parameters (parameters ):
@@ -228,11 +232,38 @@ def check_model_file(save, load):
228232 raise CheckError (f"Model file { load } seems to be empty" )
229233
230234
235+ def check_load_fits_from_weight_file (load_weights_from_fit , load , load_weights_dict , replicas ):
236+ """Checks whether the load_weights_from_fit option is correctly defined.
237+ And whether the requested replica can be loaded
238+ """
239+ if load_weights_from_fit is not None :
240+ if load is not None :
241+ raise CheckError (
242+ "Cannot use both `load` and `load_weights_from_fit` options at the same time, please select only one of them"
243+ )
244+ if replicas is not None and load_weights_from_fit is not None :
245+ missing_replicas = set (replicas ) - set (load_weights_dict .keys ())
246+ if missing_replicas :
247+ raise CheckError (
248+ f"Not all replicas requested have weights to be loaded, missing: { missing_replicas } "
249+ )
250+
251+
231252@make_argcheck
232- def wrapper_check_NN (tensorboard , save , load , parameters , trial_specs ):
253+ def wrapper_check_NN (
254+ tensorboard ,
255+ save ,
256+ load ,
257+ load_weights_from_fit ,
258+ load_weights_dict ,
259+ parameters ,
260+ trial_specs ,
261+ replicas ,
262+ ):
233263 """Wrapper function for all NN-related checks"""
234264 check_tensorboard (tensorboard )
235265 check_model_file (save , load )
266+ check_load_fits_from_weight_file (load_weights_from_fit , load , load_weights_dict , replicas )
236267 check_lagrange_multipliers (parameters , "integrability" )
237268 check_lagrange_multipliers (parameters , "positivity" )
238269 if trial_specs :
@@ -489,7 +520,7 @@ def check_deprecated_options(fitting, parameters):
489520 raise CheckError (
490521 "`interpolation_points` no longer accepted, please change to `feature_scaling_points`"
491522 )
492-
523+
493524
494525@make_argcheck
495526def check_photonQED_exists (theoryid , fiatlux ):
0 commit comments