Skip to content

Commit

Permalink
Add rerun confirmation in cfpq_eval
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaMuravjov committed Apr 15, 2024
1 parent 843f6a0 commit 1b34aab
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions cfpq_eval/eval_all_pairs_cflr.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,22 @@ def run_experiment(
return

try:
result = run_appropriate_all_pairs_cflr_tool(
algo_settings=algo_settings,
graph_path=graph_path,
grammar_path=grammar_path,
timeout_sec=timeout_sec
)
s_edges = result.s_edges
ram_kb = result.ram_kb
time_sec = result.time_sec
running_file_path = result_file_path.with_suffix('.unfinished')
if os.path.isfile(running_file_path) and not user_confirms_rerun():
s_edges, ram_kb, time_sec = "-", "-", "-"
else:
with open(running_file_path, 'w', encoding="utf-8") as running_file:
running_file.write("CFPQ solver started, but has not finished")
result = run_appropriate_all_pairs_cflr_tool(
algo_settings=algo_settings,
graph_path=graph_path,
grammar_path=grammar_path,
timeout_sec=timeout_sec
)
s_edges = result.s_edges
ram_kb = result.ram_kb
time_sec = result.time_sec
os.remove(running_file_path)
except IncompatibleCflrToolError:
s_edges, ram_kb, time_sec = "-", "-", "-"
except subprocess.CalledProcessError as e:
Expand All @@ -93,6 +100,20 @@ def run_experiment(
])


def user_confirms_rerun() -> bool:
while True:
print(
"Last time you run this CFPQ solver on this input experiment was stopped abruptly "
"either because you stopped it manually or because container has crashed. "
"Do you want to rerun the CFPQ solver on this input? (y/n)"
)
user_confirm = input().lower()
if user_confirm == "y":
return True
if user_confirm == "n":
return False


def round_to_significant_digits(x: float, digits: int = 2) -> float:
if x == 0.0:
return 0.0
Expand Down

0 comments on commit 1b34aab

Please sign in to comment.