diff --git a/cfpq_eval/eval_all_pairs_cflr.py b/cfpq_eval/eval_all_pairs_cflr.py index 9c288ba..11e205e 100644 --- a/cfpq_eval/eval_all_pairs_cflr.py +++ b/cfpq_eval/eval_all_pairs_cflr.py @@ -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: @@ -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