30
30
from ax .core .outcome_constraint import OutcomeConstraint
31
31
from ax .core .parameter import ParameterType , RangeParameter
32
32
from ax .core .runner import Runner
33
+ from ax .core .trial import Trial
33
34
from ax .core .trial_status import TrialStatus
34
35
from ax .core .types import ComparisonOp
35
36
from ax .exceptions .core import ObjectNotFoundError
@@ -275,6 +276,8 @@ def test_saving_and_loading_experiment_with_aux_exp(self) -> None:
275
276
is_test = True ,
276
277
)
277
278
save_experiment (aux_experiment , config = self .config )
279
+ # pyre-ignore[16]: `AuxiliaryExperimentPurpose` has no attribute
280
+ purpose = self .config .auxiliary_experiment_purpose_enum .MyAuxExpPurpose
278
281
279
282
experiment_w_aux_exp = Experiment (
280
283
name = "test_experiment_w_aux_exp_in_SQAStoreTest" ,
@@ -284,10 +287,7 @@ def test_saving_and_loading_experiment_with_aux_exp(self) -> None:
284
287
tracking_metrics = [Metric (name = "tracking" )],
285
288
is_test = True ,
286
289
auxiliary_experiments_by_purpose = {
287
- # pyre-ignore[16]: `AuxiliaryExperimentPurpose` has no attribute
288
- self .config .auxiliary_experiment_purpose_enum .MyAuxExpPurpose : [
289
- AuxiliaryExperiment (experiment = aux_experiment )
290
- ]
290
+ purpose : [AuxiliaryExperiment (experiment = aux_experiment )]
291
291
},
292
292
)
293
293
self .assertIsNone (experiment_w_aux_exp .db_id )
@@ -299,6 +299,66 @@ def test_saving_and_loading_experiment_with_aux_exp(self) -> None:
299
299
self .assertEqual (experiment_w_aux_exp , loaded_experiment )
300
300
self .assertEqual (len (loaded_experiment .auxiliary_experiments_by_purpose ), 1 )
301
301
302
+ def test_saving_and_loading_experiment_with_aux_exp_reduced_state (self ) -> None :
303
+ aux_exp = Experiment (
304
+ name = "test_aux_exp_in_SQAStoreTest_reduced_state" ,
305
+ search_space = get_search_space (),
306
+ optimization_config = get_optimization_config (),
307
+ description = "test description" ,
308
+ tracking_metrics = [Metric (name = "tracking" )],
309
+ is_test = True ,
310
+ )
311
+ aux_exp_gs = get_generation_strategy (with_callable_model_kwarg = False )
312
+ aux_exp .new_trial (aux_exp_gs .gen (experiment = aux_exp ))
313
+ save_experiment (aux_exp , config = self .config )
314
+ # pyre-ignore[16]: `AuxiliaryExperimentPurpose` has no attribute
315
+ purpose = self .config .auxiliary_experiment_purpose_enum .MyAuxExpPurpose
316
+
317
+ target_exp = Experiment (
318
+ name = "test_experiment_w_aux_exp_in_SQAStoreTest_reduced_state" ,
319
+ search_space = get_search_space (),
320
+ optimization_config = get_optimization_config (),
321
+ description = "test description" ,
322
+ tracking_metrics = [Metric (name = "tracking" )],
323
+ is_test = True ,
324
+ auxiliary_experiments_by_purpose = {
325
+ purpose : [AuxiliaryExperiment (experiment = aux_exp )]
326
+ },
327
+ )
328
+ target_exp_gs = get_generation_strategy (with_callable_model_kwarg = False )
329
+ target_exp .new_trial (target_exp_gs .gen (experiment = target_exp ))
330
+ self .assertIsNone (target_exp .db_id )
331
+ save_experiment (target_exp , config = self .config )
332
+ self .assertIsNotNone (target_exp .db_id )
333
+ loaded_target_exp = load_experiment (
334
+ target_exp .name , config = self .config , reduced_state = True
335
+ )
336
+ self .assertNotEqual (target_exp , loaded_target_exp )
337
+ self .assertIsNotNone ( # State of the original aux experiment is not reduced.
338
+ none_throws (
339
+ assert_is_instance (aux_exp .trials [0 ], Trial ).generator_run
340
+ ).gen_metadata
341
+ )
342
+ self .assertIsNotNone ( # State of the original target experiment is not reduced.
343
+ none_throws (
344
+ assert_is_instance (target_exp .trials [0 ], Trial ).generator_run
345
+ ).gen_metadata
346
+ )
347
+ self .assertIsNone ( # State of the loaded target experiment *is reduced*.
348
+ none_throws (
349
+ assert_is_instance (loaded_target_exp .trials [0 ], Trial ).generator_run
350
+ ).gen_metadata
351
+ )
352
+ loaded_aux_exp = loaded_target_exp .auxiliary_experiments_by_purpose [purpose ][0 ]
353
+ self .assertIsNone ( # State of the loaded target experiment *is reduced*.
354
+ none_throws (
355
+ assert_is_instance (
356
+ loaded_aux_exp .experiment .trials [0 ], Trial
357
+ ).generator_run
358
+ ).gen_metadata
359
+ )
360
+ self .assertEqual (len (loaded_target_exp .auxiliary_experiments_by_purpose ), 1 )
361
+
302
362
def test_saving_with_aux_exp_not_in_db (self ) -> None :
303
363
aux_experiment = Experiment (
304
364
name = "aux_experiment_not_in_db" , search_space = get_search_space ()
0 commit comments