@@ -92,6 +92,9 @@ def get_experiment_filename(PREFIX):
9292def load_experiment (PKL_NAME ):
9393 """
9494 Loads the experiment from a pickle file.
95+ If the spot tuner object and the fun control dictionary do not exist, an error is thrown.
96+ If the design control, surrogate control, and optimizer control dictionaries do not exist, a warning is issued
97+ and `None` is assigned to the corresponding variables.
9598
9699 Args:
97100 PKL_NAME (str): Name of the pickle file.
@@ -109,11 +112,32 @@ def load_experiment(PKL_NAME):
109112 """
110113 with open (PKL_NAME , "rb" ) as handle :
111114 experiment = pickle .load (handle )
115+ # assign spot_tuner and fun_control only if they exist otherwise throw an error
116+ if "spot_tuner" not in experiment :
117+ raise ValueError ("The spot tuner object does not exist in the pickle file." )
118+ if "fun_control" not in experiment :
119+ raise ValueError ("The fun control dictionary does not exist in the pickle file." )
112120 spot_tuner = experiment ["spot_tuner" ]
113121 fun_control = experiment ["fun_control" ]
114- design_control = experiment ["design_control" ]
115- surrogate_control = experiment ["surrogate_control" ]
116- optimizer_control = experiment ["optimizer_control" ]
122+ # assign the rest of the dictionaries if they exist otherwise assign None
123+ if "design_control" not in experiment :
124+ design_control = None
125+ # issue a warning
126+ print ("The design control dictionary does not exist in the pickle file. Returning None." )
127+ else :
128+ design_control = experiment ["design_control" ]
129+ if "surrogate_control" not in experiment :
130+ surrogate_control = None
131+ # issue a warning
132+ print ("The surrogate control dictionary does not exist in the pickle file. Returning None." )
133+ else :
134+ surrogate_control = experiment ["surrogate_control" ]
135+ if "optimizer_control" not in experiment :
136+ # issue a warning
137+ print ("The optimizer control dictionary does not exist in the pickle file. Returning None." )
138+ optimizer_control = None
139+ else :
140+ optimizer_control = experiment ["optimizer_control" ]
117141 return spot_tuner , fun_control , design_control , surrogate_control , optimizer_control
118142
119143
0 commit comments