@@ -57,16 +57,22 @@ def run_experiment(
57
57
if is_enough_data_collected (result_file_path , rounds ):
58
58
return
59
59
60
+ running_file_path = result_file_path .with_suffix ('.unfinished' )
60
61
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
70
76
except IncompatibleCflrToolError :
71
77
s_edges , ram_kb , time_sec = "-" , "-" , "-"
72
78
except subprocess .CalledProcessError as e :
@@ -79,6 +85,8 @@ def run_experiment(
79
85
f" (interpreting as out of memory error)"
80
86
)
81
87
s_edges , ram_kb , time_sec = "OOM" , "OOM" , "OOM"
88
+ finally :
89
+ os .remove (running_file_path )
82
90
83
91
with open (result_file_path , 'a' , newline = '' , encoding = "utf-8" ) as csvfile :
84
92
print (f" SEdges: { s_edges } \t \t RAM KB: { ram_kb } \t \t TIME SEC: { time_sec } " )
@@ -93,6 +101,20 @@ def run_experiment(
93
101
])
94
102
95
103
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
+
96
118
def round_to_significant_digits (x : float , digits : int = 2 ) -> float :
97
119
if x == 0.0 :
98
120
return 0.0
0 commit comments