Coverage for mlos_bench/mlos_bench/tests/storage/tunable_config_data_test.py: 100%

20 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-06 00:35 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5""" 

6Unit tests for loading the TunableConfigData. 

7""" 

8 

9from mlos_bench.storage.base_experiment_data import ExperimentData 

10from mlos_bench.tunables.tunable_groups import TunableGroups 

11 

12 

13def test_trial_data_tunable_config_data(exp_data: ExperimentData, 

14 tunable_groups: TunableGroups) -> None: 

15 """ 

16 Check expected return values for TunableConfigData. 

17 """ 

18 trial_id = 1 

19 expected_config_id = 1 

20 trial = exp_data.trials[trial_id] 

21 tunable_config = trial.tunable_config 

22 assert tunable_config.tunable_config_id == expected_config_id 

23 # The first should be the defaults. 

24 assert tunable_config.config_dict == tunable_groups.get_param_values() 

25 assert trial.tunable_config_trial_group.tunable_config == tunable_config 

26 

27 

28def test_trial_data_no_tunables_config_data(exp_no_tunables_data: ExperimentData) -> None: 

29 """ 

30 Check expected return values for TunableConfigData. 

31 """ 

32 empty_config: dict = {} 

33 for _trial_id, trial in exp_no_tunables_data.trials.items(): 

34 assert trial.tunable_config.config_dict == empty_config 

35 

36 

37def test_mixed_numerics_exp_trial_data( 

38 mixed_numerics_exp_data: ExperimentData, 

39 mixed_numerics_tunable_groups: TunableGroups) -> None: 

40 """ 

41 Tests that data type conversions are retained when loading experiment data with 

42 mixed numeric tunable types. 

43 """ 

44 trial = next(iter(mixed_numerics_exp_data.trials.values())) 

45 config = trial.tunable_config.config_dict 

46 for (tunable, _group) in mixed_numerics_tunable_groups: 

47 assert isinstance(config[tunable.name], tunable.dtype)