@@ -57,16 +57,22 @@ def run_experiment(
5757 if is_enough_data_collected (result_file_path , rounds ):
5858 return
5959
60+ running_file_path = result_file_path .with_suffix ('.unfinished' )
6061 try :
61- result = run_appropriate_all_pairs_cflr_tool (
62- algo_settings = algo_settings ,
63- graph_path = graph_path ,
64- grammar_path = grammar_path ,
65- timeout_sec = timeout_sec
66- )
67- s_edges = result .s_edges
68- ram_kb = result .ram_kb
69- time_sec = result .time_sec
62+ if os .path .isfile (running_file_path ) and not user_confirms_rerun ():
63+ s_edges , ram_kb , time_sec = "-" , "-" , "-"
64+ else :
65+ with open (running_file_path , 'w' , encoding = "utf-8" ) as running_file :
66+ running_file .write ("CFPQ solver started, but has not finished" )
67+ result = run_appropriate_all_pairs_cflr_tool (
68+ algo_settings = algo_settings ,
69+ graph_path = graph_path ,
70+ grammar_path = grammar_path ,
71+ timeout_sec = timeout_sec
72+ )
73+ s_edges = result .s_edges
74+ ram_kb = result .ram_kb
75+ time_sec = result .time_sec
7076 except IncompatibleCflrToolError :
7177 s_edges , ram_kb , time_sec = "-" , "-" , "-"
7278 except subprocess .CalledProcessError as e :
@@ -79,6 +85,8 @@ def run_experiment(
7985 f" (interpreting as out of memory error)"
8086 )
8187 s_edges , ram_kb , time_sec = "OOM" , "OOM" , "OOM"
88+ finally :
89+ os .remove (running_file_path )
8290
8391 with open (result_file_path , 'a' , newline = '' , encoding = "utf-8" ) as csvfile :
8492 print (f" SEdges: { s_edges } \t \t RAM KB: { ram_kb } \t \t TIME SEC: { time_sec } " )
@@ -93,6 +101,20 @@ def run_experiment(
93101 ])
94102
95103
104+ def user_confirms_rerun () -> bool :
105+ while True :
106+ print (
107+ "Last time you run this CFPQ solver on this input experiment was stopped abruptly "
108+ "either because you stopped it manually or because container has crashed. "
109+ "Do you want to rerun the CFPQ solver on this input? (y/n)"
110+ )
111+ user_confirm = input ().lower ()
112+ if user_confirm == "y" :
113+ return True
114+ if user_confirm == "n" :
115+ return False
116+
117+
96118def round_to_significant_digits (x : float , digits : int = 2 ) -> float :
97119 if x == 0.0 :
98120 return 0.0
0 commit comments