@@ -55,7 +55,7 @@ def test_outdated_data_check(
55
55
time .sleep (3 )
56
56
_ems_monitor .estimate_co2_emissions (** _measure_params )
57
57
58
- assert _spy .call_count == 2 if refresh else 1 , f"{ _spy .call_count } != { 2 if refresh else 1 } "
58
+ assert _spy .call_count == ( 2 if refresh else 1 ) , f"{ _spy .call_count } != { 2 if refresh else 1 } "
59
59
60
60
61
61
def test_co2_monitor_properties (mock_co2_signal ) -> None :
@@ -65,20 +65,37 @@ def test_co2_monitor_properties(mock_co2_signal) -> None:
65
65
thermal_design_power_per_gpu = 130 ,
66
66
local_data_directory = tempd ,
67
67
intensity_refresh_interval = None ,
68
- co2_intensity = None ,
68
+ co2_intensity = 40 ,
69
69
co2_signal_api_token = None
70
70
)
71
71
_measure_params = {
72
72
"process_id" : "test_co2_monitor_properties" ,
73
73
"cpu_percent" : 20 ,
74
74
"gpu_percent" : 40 ,
75
- "measure_interval" : 1
75
+ "measure_interval" : 2
76
76
}
77
+
77
78
_ems_monitor .estimate_co2_emissions (** _measure_params )
79
+
78
80
assert _ems_monitor .current_carbon_intensity
81
+ assert _ems_monitor .n_cores_per_cpu == 4
79
82
assert _ems_monitor .process_data ["test_co2_monitor_properties" ]
80
- assert _ems_monitor .total_power_usage
81
- assert _ems_monitor .total_co2_emission
82
- assert _ems_monitor .total_co2_delta
83
- assert _ems_monitor .total_energy
84
- assert _ems_monitor .total_energy_delta
83
+
84
+ # Will use this equation
85
+ # Power used = (TDP_cpu * cpu_percent / num_cores) + (TDP_gpu * gpu_percent)
86
+ assert _ems_monitor .total_power_usage == (80 * 0.2 * 1 / 4 ) + (130 * 0.4 * 1 )
87
+
88
+ # Energy used = power used * measure interval
89
+ assert _ems_monitor .total_energy == _ems_monitor .total_power_usage * 2
90
+
91
+ # CO2 emission = energy * CO2 intensity
92
+ # Need to convert CO2 intensity from g/kWh to kg/kWs
93
+ # So divide by 1000 (g -> kg)
94
+ # And divide by 60*60 (kWh -> kws)
95
+ assert _ems_monitor .total_co2_emission == _ems_monitor .total_energy * 40 / (60 * 60 * 1000 )
96
+
97
+ _ems_monitor .estimate_co2_emissions (** _measure_params )
98
+ # Check delta is half of total, since we've now called this twice
99
+ assert _ems_monitor .total_co2_delta == _ems_monitor .total_co2_emission / 2
100
+ assert _ems_monitor .total_energy_delta == _ems_monitor .total_energy / 2
101
+
0 commit comments