Skip to content

Commit 5416c70

Browse files
committed
Add rerun confirmation in cfpq_eval
1 parent 843f6a0 commit 5416c70

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

cfpq_eval/eval_all_pairs_cflr.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
96118
def round_to_significant_digits(x: float, digits: int = 2) -> float:
97119
if x == 0.0:
98120
return 0.0

0 commit comments

Comments
 (0)