From 57747d3628b452eb496b00646808ee34002883d7 Mon Sep 17 00:00:00 2001 From: Megan <113795130+YUUU23@users.noreply.github.com> Date: Fri, 26 Jul 2024 15:31:00 -0500 Subject: [PATCH] =?UTF-8?q?feat:=20--assert=5Fall=5Fregions=5Fparallelizab?= =?UTF-8?q?le=20flag=20that=20has=20the=20same=20func=E2=80=A6=20(#722)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: --assert_all_regions_parallelizable flag that has the same function as old assert_compiler_success flag; new assert_compiler_success flag now will not exit with error when regions are unparallelizable and exit with error when general exceptions are caught Signed-off-by: YUUU23 * update flag description, variable name, more specific respose Signed-off-by: YUUU23 --------- Signed-off-by: YUUU23 --- compiler/cli.py | 7 ++++- compiler/custom_error.py | 9 +++++- .../orchestrator_runtime/pash_init_setup.sh | 5 +++ .../pash_prepare_call_compiler.sh | 21 ++++++++++++- compiler/pash_compilation_server.py | 31 ++++++++++++++----- compiler/pash_compiler.py | 2 ++ evaluation/tests/test_evaluation_scripts.sh | 2 +- 7 files changed, 66 insertions(+), 11 deletions(-) diff --git a/compiler/cli.py b/compiler/cli.py index 7f9a3db6b..bfab6c988 100644 --- a/compiler/cli.py +++ b/compiler/cli.py @@ -57,7 +57,12 @@ def add_pash_args(self): ) self.add_argument( "--assert_compiler_success", - help="assert that the compiler succeeded (used to make tests more robust)", + help="assert that the compiler succeeded with no general error occuring", + action="store_true", + ) + self.add_argument( + "--assert_all_regions_parallelizable", + help="assert that the compiler succeeded with all regions being parallelizable and no general error occuring (used to make tests more robust); more strict than --assert_compiler_success flag", action="store_true", ) self.add_argument( diff --git a/compiler/custom_error.py b/compiler/custom_error.py index eedb6f738..4b2e42444 100644 --- a/compiler/custom_error.py +++ b/compiler/custom_error.py @@ -2,4 +2,11 @@ class UnparallelizableError(Exception): pass class AdjLineNotImplementedError(Exception): - pass \ No newline at end of file + pass + +# to be raised in pash_compiler if a UnparallelizableError is caught at any point running the compiler +# primarily to differentiate +# --assert_compiler_success (exit with error only under general exceptions caught) +# --assert_all_regions_parallelizable (exit with error when regions are found not parallelizable + general exceptions) +class NotAllRegionParallelizableError(Exception): + pass \ No newline at end of file diff --git a/compiler/orchestrator_runtime/pash_init_setup.sh b/compiler/orchestrator_runtime/pash_init_setup.sh index 0bb4fae7a..966474a5c 100644 --- a/compiler/orchestrator_runtime/pash_init_setup.sh +++ b/compiler/orchestrator_runtime/pash_init_setup.sh @@ -13,6 +13,7 @@ export pash_output_time_flag=1 export pash_execute_flag=1 export pash_dry_run_compiler_flag=0 export pash_assert_compiler_success_flag=0 +export pash_assert_all_regions_parallelizable_flag=0 export pash_checking_log_file=0 export pash_checking_debug_level=0 export pash_avoid_pash_runtime_completion_flag=0 @@ -51,6 +52,10 @@ do export pash_assert_compiler_success_flag=1 fi + if [ "--assert_all_regions_parallelizable" == "$item" ]; then + export pash_assert_all_regions_parallelizable_flag=1 + fi + if [ "--log_file" == "$item" ]; then pash_checking_log_file=1 fi diff --git a/compiler/orchestrator_runtime/pash_prepare_call_compiler.sh b/compiler/orchestrator_runtime/pash_prepare_call_compiler.sh index c05faf681..22a2b37c8 100644 --- a/compiler/orchestrator_runtime/pash_prepare_call_compiler.sh +++ b/compiler/orchestrator_runtime/pash_prepare_call_compiler.sh @@ -33,6 +33,12 @@ pash_redir_output echo "$$: (2) Before asking the daemon for compilation..." msg="Compile:${pash_compiled_script_file}| Variable File:${pash_runtime_shell_variables_file}| Input IR File:${pash_input_ir_file}" daemon_response=$(pash_communicate_daemon "$msg") # Blocking step, daemon will not send response until it's safe to continue +if [[ "$daemon_response" == *"not all regions are parallelizable"* ]]; then + pash_all_region_parallelizable=1 +else + pash_all_region_parallelizable=0 +fi + if [[ "$daemon_response" == *"OK:"* ]]; then pash_runtime_return_code=0 elif [ -z "$daemon_response" ]; then @@ -51,7 +57,20 @@ response_args=($daemon_response) process_id=${response_args[1]} pash_redir_output echo "$$: (2) Compiler exited with code: $pash_runtime_return_code" -if [ "$pash_runtime_return_code" -ne 0 ] && [ "$pash_assert_compiler_success_flag" -eq 1 ]; then + +## only when --assert_all_regions_parallellizable is used do we care about all regions being parallelizable +if [ "$pash_all_region_parallelizable" -ne 0 ] && [ "$pash_assert_all_regions_parallelizable_flag" -eq 1 ]; then + pash_redir_output echo "$$: ERROR: (2) Compiler failed with error code because some regions were not parallelizable: $pash_all_region_parallelizable while assert_all_regions_parallelizable_flag was enabled! Exiting PaSh..." + exit 1 +fi + +if [ "$pash_runtime_return_code" -ne 0 ] && [ "$pash_assert_all_regions_parallelizable_flag" -eq 1 ]; then + pash_redir_output echo "$$: ERROR: (2) Compiler failed with error code: $pash_runtime_return_code while assert_all_regions_parallelizable_flag was enabled! Exiting PaSh..." + exit 1 +fi + +## for pash_assert_compiler_success_flag, exit when return code is 0 (general exception caught) and not when all regions are parallelizable +if [ "$pash_runtime_return_code" -ne 0 ] && [ "$pash_all_region_parallelizable" -eq 0 ] && [ "$pash_assert_compiler_success_flag" -eq 1 ]; then pash_redir_output echo "$$: ERROR: (2) Compiler failed with error code: $pash_runtime_return_code while assert_compiler_success was enabled! Exiting PaSh..." exit 1 fi diff --git a/compiler/pash_compilation_server.py b/compiler/pash_compilation_server.py index 51f531574..203701e3a 100644 --- a/compiler/pash_compilation_server.py +++ b/compiler/pash_compilation_server.py @@ -14,6 +14,7 @@ import server_util from cli import BaseParser +from custom_error import * ## ## A Daemon (not with the strict Unix sense) @@ -252,6 +253,7 @@ def compile_and_add(self, compiled_script_file, var_file, input_ir_file): process_id = self.get_next_id() run_parallel = False compile_success = False + current_region_parallelizable = True variable_reading_start_time = datetime.now() # Read any shell variables files if present @@ -269,9 +271,15 @@ def compile_and_add(self, compiled_script_file, var_file, input_ir_file): ## Add the process_id -> input_ir mapping self.add_proc_id_map(process_id, input_ir_file, compiler_config) - ast_or_ir = pash_compiler.compile_ir( - input_ir_file, compiled_script_file, config.pash_args, compiler_config - ) + # check if any general exceptions are caught to report to --assert_compiler_success flag + try: + ast_or_ir = pash_compiler.compile_ir( + input_ir_file, compiled_script_file, config.pash_args, compiler_config + ) + except NotAllRegionParallelizableError: + ast_or_ir = None + current_region_parallelizable = False + daemon_compile_end_time = datetime.now() print_time_delta( @@ -321,19 +329,28 @@ def compile_and_add(self, compiled_script_file, var_file, input_ir_file): else: ## Wait if we have more pipelines running than our current limit self.wait_until_limit(config.pash_args.parallel_pipelines_limit) - + if compile_success: response = server_util.success_response( f"{process_id} {compiled_script_file} {var_file} {input_ir_file}" ) + elif not current_region_parallelizable: + # send specified message to say current region is not parallelizable instead of general exception caught + response = server_util.error_response(f"{process_id} current region is not parallelizable; failed to compile") + self.unsafe_running = True else: response = server_util.error_response(f"{process_id} failed to compile") self.unsafe_running = True + - ## Do not increase the running procs if assert_compiler_success is enabled + ## Do not increase the running procs if assert_all_regions_parallelizable is enabled ## and compilation failed, since nothing will run then. - if not compile_success and config.pash_args.assert_compiler_success: - pass + ## Do not increase when compile is not successful but regions are parallelizable (in the case that general exceptions are caught), + ## nothing will run in this case also + if (not compile_success and config.pash_args.assert_all_regions_parallelizable): + pass + elif (not compile_success and current_region_parallelizable and config.pash_args.assert_compiler_success): + pass else: self.running_procs += 1 diff --git a/compiler/pash_compiler.py b/compiler/pash_compiler.py index a949457ba..68b2e8676 100644 --- a/compiler/pash_compiler.py +++ b/compiler/pash_compiler.py @@ -96,8 +96,10 @@ def compile_ir(ir_filename, compiled_script_file, args, compiler_config): ) except ExpansionError as e: log("WARNING: Exception caught because some region(s) are not expandable and therefore unparallelizable:", e) + raise NotAllRegionParallelizableError() except UnparallelizableError as e: log("WARNING: Exception caught because some region(s) are unparallelizable:", e) + raise NotAllRegionParallelizableError() # log(traceback.format_exc()) # uncomment for exact trace report (PaSh user should see informative messages for unparellizable regions) except (AdjLineNotImplementedError, NotImplementedError) as e: log("WARNING: Exception caught because some part is not implemented:", e) diff --git a/evaluation/tests/test_evaluation_scripts.sh b/evaluation/tests/test_evaluation_scripts.sh index 7deac9040..519365886 100755 --- a/evaluation/tests/test_evaluation_scripts.sh +++ b/evaluation/tests/test_evaluation_scripts.sh @@ -189,7 +189,7 @@ execute_tests() { } execute_tests "" "${script_microbenchmarks[@]}" -execute_tests "--assert_compiler_success" "${pipeline_microbenchmarks[@]}" +execute_tests "--assert_all_regions_parallelizable" "${pipeline_microbenchmarks[@]}" #cat ${results_time} | sed 's/,/./' > /tmp/a #cat /tmp/a | sed 's/@/,/' > ${results_time}