Update calculate_memory_usage.py
Browse files- calculate_memory_usage.py +27 -3
calculate_memory_usage.py
CHANGED
@@ -1,8 +1,9 @@
|
|
1 |
import os
|
2 |
import glob
|
3 |
import argparse
|
|
|
4 |
from code_efficiency_calculator import run_model_task
|
5 |
-
|
6 |
|
7 |
def calculate_memory_usage(dat_file_path):
|
8 |
with open(dat_file_path, 'r') as file:
|
@@ -51,6 +52,7 @@ def report_max_memory_usage(dat_file_path):
|
|
51 |
return max_memory_usage
|
52 |
|
53 |
def report_results(task, model, file):
|
|
|
54 |
run_model_task(task, model, file)
|
55 |
dat_directory = f"./results/{task}_{model}"
|
56 |
canonical_solution_directory = f"./results/{task}_canonical_solution"
|
@@ -190,6 +192,17 @@ def report_results(task, model, file):
|
|
190 |
max_ntmu_lists[ntmu] = (model, idx)
|
191 |
max_tmu = max(max_tmu,completion_memory_usage[idx]/canonical_solution_memory_usage[idx])
|
192 |
total_codes+=1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
193 |
|
194 |
if len(normalized_execution_time_list)==0:
|
195 |
print(model)
|
@@ -201,12 +214,23 @@ def report_results(task, model, file):
|
|
201 |
total_memory_usage = total_memory_usage/len(normalized_execution_time_list)
|
202 |
total_max_memory_usage = total_max_memory_usage/len(normalized_execution_time_list)
|
203 |
|
204 |
-
pass1 = len(completion_memory_usage)/
|
205 |
|
206 |
total_500_net = total_500_net/len(normalized_execution_time_list)*100
|
207 |
total_500_nmu = total_500_nmu/len(normalized_execution_time_list)*100
|
208 |
total_500_tmu = total_500_tmu/len(normalized_execution_time_list)*100
|
209 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
210 |
return f"{model}&{total_execution_time:.2f}&{normalized_execution_time:.2f}&{max_net:.2f}&{total_500_net:.1f}&{total_max_memory_usage:.2f}&{normalized_max_memory_usage:.2f}&{max_nmu:.2f}&{total_500_nmu:.1f}&{total_memory_usage:.2f}&{normalized_memory_usage:.2f}&{max_tmu:.2f}&{total_500_tmu:.1f}&{pass1:.1f}\\\\"
|
211 |
|
212 |
|
|
|
1 |
import os
|
2 |
import glob
|
3 |
import argparse
|
4 |
+
import json
|
5 |
from code_efficiency_calculator import run_model_task
|
6 |
+
data_to_save = {}
|
7 |
|
8 |
def calculate_memory_usage(dat_file_path):
|
9 |
with open(dat_file_path, 'r') as file:
|
|
|
52 |
return max_memory_usage
|
53 |
|
54 |
def report_results(task, model, file):
|
55 |
+
global data_to_save
|
56 |
run_model_task(task, model, file)
|
57 |
dat_directory = f"./results/{task}_{model}"
|
58 |
canonical_solution_directory = f"./results/{task}_canonical_solution"
|
|
|
192 |
max_ntmu_lists[ntmu] = (model, idx)
|
193 |
max_tmu = max(max_tmu,completion_memory_usage[idx]/canonical_solution_memory_usage[idx])
|
194 |
total_codes+=1
|
195 |
+
data_to_save[idx] = {
|
196 |
+
"completion_memory_usage": completion_memory_usage[idx],
|
197 |
+
"execution_time": execution_time[idx],
|
198 |
+
"max_memory_usage": max_memory_usage[idx],
|
199 |
+
"canonical_solution_max_memory_usage": canonical_solution_max_memory_usage[idx],
|
200 |
+
"canonical_solution_memory_usage": canonical_solution_memory_usage[idx],
|
201 |
+
"canonical_solution_execution_time": canonical_solution_execution_time[idx],
|
202 |
+
"net": net,
|
203 |
+
"nmu": nmu,
|
204 |
+
"ntmu": ntmu
|
205 |
+
}
|
206 |
|
207 |
if len(normalized_execution_time_list)==0:
|
208 |
print(model)
|
|
|
214 |
total_memory_usage = total_memory_usage/len(normalized_execution_time_list)
|
215 |
total_max_memory_usage = total_max_memory_usage/len(normalized_execution_time_list)
|
216 |
|
217 |
+
pass1 = len(completion_memory_usage)/164*100
|
218 |
|
219 |
total_500_net = total_500_net/len(normalized_execution_time_list)*100
|
220 |
total_500_nmu = total_500_nmu/len(normalized_execution_time_list)*100
|
221 |
total_500_tmu = total_500_tmu/len(normalized_execution_time_list)*100
|
222 |
+
passing_problem_idxs = []
|
223 |
+
for idx in completion_memory_usage.keys():
|
224 |
+
if idx not in canonical_solution_memory_usage.keys():
|
225 |
+
continue
|
226 |
+
else:
|
227 |
+
passing_problem_idxs.append(idx)
|
228 |
+
|
229 |
+
with open("passing_problem_idxs.txt", "w") as file:
|
230 |
+
for problem_idx in passing_problem_idxs:
|
231 |
+
file.write(f"{problem_idx}\n")
|
232 |
+
with open("output_data.json", "w") as json_file:
|
233 |
+
json.dump(data_to_save, json_file, indent=4)
|
234 |
return f"{model}&{total_execution_time:.2f}&{normalized_execution_time:.2f}&{max_net:.2f}&{total_500_net:.1f}&{total_max_memory_usage:.2f}&{normalized_max_memory_usage:.2f}&{max_nmu:.2f}&{total_500_nmu:.1f}&{total_memory_usage:.2f}&{normalized_memory_usage:.2f}&{max_tmu:.2f}&{total_500_tmu:.1f}&{pass1:.1f}\\\\"
|
235 |
|
236 |
|