11################################################################################
22# Script that executes ../../../bin/causalize 10 times and calculates the
3- # average times for the algebraic loops and complete causalization phases. It
4- # repeats these for different values of N = 100, 1000, 10000, 100000 and 1000000
5- # for each model: TestRL1.mo, TestRL2.mo and TestRL3.mo.
3+ # average times all of the causalization phases, and also the compilation of
4+ # the C generated file. It repeats these for different values of
5+ # N = 100, 1000, 10000, 100000 and 1000000 for each model: TestRL1.mo,
6+ # TestRL2.mo and TestRL3.mo.
67################################################################################
78
89import sys
1112import os
1213from collections import defaultdict
1314from pathlib import Path
15+ import sys
16+ import time
17+
18+ # TODO: erase dummy functions and import QSS actual functions
19+ def mmoc_compile_model (filename ):
20+ time .sleep (15 / 1000.0 )
21+
22+ def compile_c_model (filename ):
23+ time .sleep (15 / 1000.0 )
1424
1525def run_modelicacc_benchmarks (filename , valores_n , runs = 10 ):
1626 try :
@@ -24,6 +34,12 @@ def run_modelicacc_benchmarks(filename, valores_n, runs=10):
2434 print (f"Values of N: { valores_n } " )
2535 print (f"Number of runs: { runs } \n " )
2636
37+ modelicacc_stages = ["Horizontal sorting SBG builder" , "Horizontal sorting"
38+ , "Algebraic loops SBG builder" , "Algebraic loops detection"
39+ , "Tearing SBG builder" , "Tearing"
40+ , "Vertical sorting SBG builder" , "Vertical sorting"
41+ , "GiNaC solve" , "Causalization" ]
42+ qss_stages = ["ModelicaCC compilation" , "C compilation" ]
2743 resultados_totales = {}
2844
2945 for n in valores_n :
@@ -41,59 +57,76 @@ def run_modelicacc_benchmarks(filename, valores_n, runs=10):
4157 pattern = re .compile (r"^(.+?):\s*([\d.]+)\s*ms" , re .MULTILINE )
4258 fases_tiempos = defaultdict (list )
4359
44- resultados_totales [n ] = { "loops builder" : None , "loops" : None , "causalize" : None }
60+ resultados_totales [n ] = dict . fromkeys ( modelicacc_stages ) | dict . fromkeys ( qss_stages )
4561 error_en_este_n = False
4662
4763 for i in range (1 , runs + 1 ):
4864 print (f"Run { i } /{ runs } ..." , end = "\r " )
65+ # ModelicaCC causalization
4966 try :
5067 result = subprocess .run (command , capture_output = True , text = True , check = True )
5168 output = result .stdout + result .stderr
5269
5370 matches = pattern .findall (output )
5471 for fase , tiempo_str in matches :
55- if "Algebraic loops SBG builder" in fase :
56- fases_tiempos ["loops builder" ].append (float (tiempo_str ))
57- elif "Algebraic loops detection" in fase :
58- fases_tiempos ["loops" ].append (float (tiempo_str ))
59- elif "Causalization" in fase :
60- fases_tiempos ["causalize" ].append (float (tiempo_str ))
72+ fase_clean = fase .strip ()
73+ if fase_clean in modelicacc_stages :
74+ fases_tiempos [fase_clean ].append (float (tiempo_str ))
6175
6276 except subprocess .CalledProcessError as e :
6377 print (f"\n Error: ModelicaCC with N={ n } , run { i } :" )
6478 print (e .stderr )
6579 error_en_este_n = True
6680 break
6781
82+ # QSS compilation
83+ start_time = time .perf_counter ()
84+ mmoc_compile_model (filename )
85+ end_time = time .perf_counter ()
86+ execution_time = end_time - start_time
87+ fases_tiempos [qss_stages [0 ]].append (float (execution_time ))
88+
89+ start_time = time .perf_counter ()
90+ compile_c_model (filename )
91+ end_time = time .perf_counter ()
92+ execution_time = end_time - start_time
93+ fases_tiempos [qss_stages [1 ]].append (float (execution_time ))
94+
6895 if os .path .exists (temp_filename ):
6996 os .remove (temp_filename )
7097
71- if error_en_este_n and not fases_tiempos [ "loops builder" ] and not fases_tiempos [ "loops" ] and not fases_tiempos [ "causalize" ] :
98+ if error_en_este_n and not any ( fases_tiempos . values ()) :
7299 print (f"Skipping N={ n } ." )
73100 continue
74101
75- for fase in ["loops builder" , "loops" , "causalize" ]:
76- tiempos = fases_tiempos [fase ]
102+ for stage in modelicacc_stages :
103+ tiempos = fases_tiempos [stage ]
104+ if tiempos :
105+ resultados_totales [n ][stage ] = sum (tiempos ) / len (tiempos )
106+
107+ for stage in qss_stages :
108+ tiempos = fases_tiempos [stage ]
77109 if tiempos :
78- resultados_totales [n ][fase ] = sum (tiempos ) / len (tiempos )
110+ resultados_totales [n ][stage ] = sum (tiempos ) / len (tiempos )
79111
80112 print ("Finished. " )
81113
82114 print (f"\n \n ============================== TIME MEASURES: { filename } ==============================" )
83- print (f"{ 'N' :<10} | { 'SBG loops builder (ms) ' :<15 } | { 'SBG loops detection (ms)' :<15 } | { 'SBG Causalization (ms)' :<15 } " )
84- print ("-" * 87 )
115+ print (f"{ 'N' :<10} | { 'Stage Name ' :<35 } | { 'Average Time (ms)' :<20 } " )
116+ print ("-" * 73 )
85117
86118 for n in valores_n :
87- fases = resultados_totales .get (n , {"loops builder" : None , "loops" : None , "causalize" : None })
88- b_time = fases ["loops builder" ]
89- l_time = fases ["loops" ]
90- c_time = fases ["causalize" ]
91-
92- b_str = f"{ b_time :.4e} " if b_time and b_time < 0.001 else (f"{ b_time :.6f} " if b_time else "N/A" )
93- l_str = f"{ l_time :.4e} " if l_time and l_time < 0.001 else (f"{ l_time :.6f} " if l_time else "N/A" )
94- c_str = f"{ c_time :.4e} " if c_time and c_time < 0.001 else (f"{ c_time :.6f} " if c_time else "N/A" )
95-
96- print (f"{ n :<10} | { b_str :<22} | { l_str :<24} | { c_str :<25} " )
119+ fases = resultados_totales .get (n , {})
120+ for stage in modelicacc_stages + qss_stages :
121+ tiempo = fases .get (stage )
122+
123+ if tiempo is not None :
124+ t_str = f"{ tiempo :.4e} " if tiempo < 0.001 else f"{ tiempo :.6f} "
125+ else :
126+ t_str = "N/A"
127+
128+ print (f"{ n :<10} | { stage :<35} | { t_str :<20} " )
129+ print ("-" * 73 )
97130 print ("=======================================================================================" )
98131
99132if __name__ == "__main__" :
@@ -104,7 +137,7 @@ def run_modelicacc_benchmarks(filename, valores_n, runs=10):
104137
105138 input_runs = int (sys .argv [1 ])
106139
107- lista_n = [100 , 1000 , 10000 , 100000 , 1000000 ]
140+ lista_n = [10 ** i for i in range ( 2 , 7 ) ]
108141
109142 model_list = ["TestRL1.mo" , "TestRL2.mo" , "TestRL3.mo" ]
110143 for model in model_list :
@@ -113,16 +146,12 @@ def run_modelicacc_benchmarks(filename, valores_n, runs=10):
113146
114147 directorio_actual = Path ("." )
115148
116- # Contador para saber cuántos archivos se borraron
117- archivos_eliminados = 0
118-
119149 # Iteramos sobre todos los archivos del directorio
120150 for archivo in directorio_actual .iterdir ():
121151 # Verificamos que sea un archivo y que contenga alguno de los dos textos en el nombre
122152 if archivo .is_file () and ("_sbg_input" in archivo .name or "_causalized" in archivo .name ):
123153 try :
124154 archivo .unlink () # Elimina el archivo
125155 print (f"Deleted: { archivo .name } " )
126- archivos_eliminados += 1
127156 except Exception as e :
128157 print (f"Unable to delete { archivo .name } : { e } " )
0 commit comments