Coverage for mlos_bench/mlos_bench/tests/environments/local/__init__.py: 100%

11 statements  

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

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5""" 

6Tests for mlos_bench.environments.local. 

7Used to make mypy happy about multiple conftest.py modules. 

8""" 

9 

10from typing import Any, Dict, List 

11 

12from mlos_bench.environments.composite_env import CompositeEnv 

13from mlos_bench.environments.local.local_env import LocalEnv 

14from mlos_bench.services.config_persistence import ConfigPersistenceService 

15from mlos_bench.services.local.local_exec import LocalExecService 

16from mlos_bench.tunables.tunable_groups import TunableGroups 

17 

18 

19def create_local_env(tunable_groups: TunableGroups, config: Dict[str, Any]) -> LocalEnv: 

20 """ 

21 Create a LocalEnv with the given configuration. 

22 

23 Parameters 

24 ---------- 

25 tunable_groups : TunableGroups 

26 Tunable parameters (usually come from a fixture). 

27 config : Dict[str, Any] 

28 Environment configuration. 

29 

30 Returns 

31 ------- 

32 env : LocalEnv 

33 A new instance of the local environment. 

34 """ 

35 return LocalEnv(name="TestLocalEnv", config=config, tunables=tunable_groups, 

36 service=LocalExecService(parent=ConfigPersistenceService())) 

37 

38 

39def create_composite_local_env(tunable_groups: TunableGroups, 

40 global_config: Dict[str, Any], 

41 params: Dict[str, Any], 

42 local_configs: List[Dict[str, Any]]) -> CompositeEnv: 

43 """ 

44 Create a CompositeEnv with several LocalEnv instances. 

45 

46 Parameters 

47 ---------- 

48 tunable_groups : TunableGroups 

49 Tunable parameters (usually come from a fixture). 

50 global_config : Dict[str, Any] 

51 Global configuration parameters. 

52 params: Dict[str, Any] 

53 Additional config params for the CompositeEnv. 

54 local_configs: List[Dict[str, Any]] 

55 Configurations of the local environments. 

56 

57 Returns 

58 ------- 

59 env : CompositeEnv 

60 A new instance of the local environment. 

61 """ 

62 return CompositeEnv( 

63 name="TestCompositeEnv", 

64 config={ 

65 **params, 

66 "children": [ 

67 { 

68 "name": f"TestLocalEnv{i}", 

69 "class": "mlos_bench.environments.local.local_env.LocalEnv", 

70 "config": config, 

71 } 

72 for (i, config) in enumerate(local_configs) 

73 ] 

74 }, 

75 tunables=tunable_groups, 

76 global_config=global_config, 

77 service=LocalExecService(parent=ConfigPersistenceService()), 

78 )