Coverage for tests/simulator/test_simulator_utils.py: 100%

38 statements  

« prev     ^ index     » next       coverage.py v7.15.4, created at 2026-08-09 04:47 +0000

1import sys 

2import os 

3 

4# Add current path 

5sys.path.append(os.getcwd()) 

6 

7from tests.test_utils import temp_sys_path 

8 

9with temp_sys_path("simulator", "streamwise"): 

10 from sim_types import Model 

11 from sim_types import GPUType 

12 from sim_types import ModelAllocation 

13 from sim_types import ProvisioningResult 

14 

15 from utils import get_pareto_frontier 

16 from utils import find_most_cost_effective_provisioning 

17 from utils import find_most_energy_efficient_provisioning 

18 from utils import find_pareto_frontier 

19 from utils import coalesce_models 

20 

21 from models import FTModelAllocation 

22 

23 

24def test_get_pareto_frontier() -> None: 

25 """Create a Pareto frontier.""" 

26 # 1 point 

27 paretor_frontier = get_pareto_frontier( 

28 [1], 

29 [1], 

30 ) 

31 assert paretor_frontier.tolist() == [ 

32 [1, 1], 

33 ] 

34 

35 # 3 points 

36 paretor_frontier = get_pareto_frontier( 

37 [1, 2, 3], # TTFF 

38 [1, 2, 2], # Cost 

39 ) 

40 assert paretor_frontier.tolist() == [ 

41 [1, 2], 

42 [1, 1], 

43 [3, 1], 

44 ] 

45 

46 # 4 points 

47 paretor_frontier = get_pareto_frontier( 

48 [1, 2, 3, 2], # TTFF 

49 [1, 2, 2, 3], # Cost 

50 ) 

51 assert paretor_frontier.tolist() == [ 

52 [1, 3], 

53 [1, 1], 

54 [3, 1], 

55 ] 

56 

57 # 5 points with maxes 

58 paretor_frontier = get_pareto_frontier( 

59 [1, 2, 3, 3, 2], # TTFF 

60 [1, 2, 2, 3, 3], # Cost 

61 max_x=100, 

62 max_y=200, 

63 ) 

64 assert paretor_frontier.tolist() == [ 

65 [1, 100], 

66 [1, 3], 

67 [1, 1], 

68 [3, 1], 

69 [200, 1], 

70 ] 

71 

72 

73def test_find_most() -> None: 

74 provisioning = ProvisioningResult( 

75 latencies=[10.0, 20.0, 15.0], 

76 costs=[100.0, 80.0, 90.0], 

77 energies=[500.0, 400.0, 450.0], 

78 ttffs=[5.0, 10.0, 7.5], 

79 tbfs=[0.1, 0.2, 0.15], 

80 actual_provision=[ 

81 {"A100": 8, "H100": 0}, 

82 {"A100": 0, "H100": 8}, 

83 {"A100": 4, "H100": 4}, 

84 ], 

85 config_provision=[ 

86 {"A100": 8, "H100": 0}, 

87 {"A100": 0, "H100": 8}, 

88 {"A100": 4, "H100": 4}, 

89 ], 

90 model_provision=[], 

91 ) 

92 

93 idx = find_most_cost_effective_provisioning(provisioning) 

94 assert 0 <= idx < 3 

95 

96 idx = find_most_energy_efficient_provisioning(provisioning) 

97 assert 0 <= idx < 3 

98 

99 find_pareto_frontier([1], [1], [1]) 

100 

101 

102def test_coalesce_models() -> None: 

103 models: dict[GPUType, dict[Model, list[ModelAllocation]]] = {} 

104 coalesced_models = coalesce_models(models) 

105 assert coalesced_models == {} 

106 

107 models = { 

108 GPUType.A100: { 

109 Model.FT: [ 

110 FTModelAllocation(gpu_type=GPUType.A100, devices=2, replicas=1), 

111 FTModelAllocation(gpu_type=GPUType.A100, devices=2, replicas=1), 

112 ], 

113 }, 

114 } 

115 coalesced_models = coalesce_models(models) 

116 assert coalesced_models[GPUType.A100][Model.FT] == [ 

117 FTModelAllocation(gpu_type=GPUType.A100, devices=2, replicas=2), 

118 ]