From 8d4a9d10c19c6f852123ee48165b06622ed77b2e Mon Sep 17 00:00:00 2001 From: David Hendriks <davidhendriks93@gmail.com> Date: Sun, 17 Jan 2021 20:22:06 +0000 Subject: [PATCH] updated checking for error --- binarycpython/utils/grid.py | 107 ++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 53 deletions(-) diff --git a/binarycpython/utils/grid.py b/binarycpython/utils/grid.py index 483dc15fd..9c8fd0456 100644 --- a/binarycpython/utils/grid.py +++ b/binarycpython/utils/grid.py @@ -2569,68 +2569,69 @@ class Population: Function to check whether binary_c throws an error and handle accordingly. """ - - - if (binary_c_output.splitlines()[0].startswith("SYSTEM_ERROR")) or (binary_c_output.splitlines()[-1].startswith("SSYSTEM_ERROR")): - verbose_print( - "FAILING SYSTEM FOUND", - self.grid_options["verbosity"], - 0, - ) - - # Keep track of the amount of failed systems and their error codes - self.grid_options["_failed_prob"] += system_dict["probability"] - self.grid_options["_failed_count"] += 1 - self.grid_options["_errors_found"] = True - - # Try catching the error code and keep track of the unique ones. - try: - error_code = int( - binary_c_output.splitlines()[0] - .split("with error code")[-1] - .split(":")[0] - .strip() - ) - - if not error_code in self.grid_options["_failed_systems_error_codes"]: - self.grid_options["_failed_systems_error_codes"].append(error_code) - except ValueError: + if binary_c_output: + if (binary_c_output.splitlines()[0].startswith("SYSTEM_ERROR")) or (binary_c_output.splitlines()[-1].startswith("SSYSTEM_ERROR")): verbose_print( - "Failed to extract the error-code", + "FAILING SYSTEM FOUND", self.grid_options["verbosity"], - 1, + 0, ) - # Check if we have exceeded the amount of errors - if ( - self.grid_options["_failed_count"] - > self.grid_options["failed_systems_threshold"] - ): - if not self.grid_options["_errors_exceeded"]: + # Keep track of the amount of failed systems and their error codes + self.grid_options["_failed_prob"] += system_dict["probability"] + self.grid_options["_failed_count"] += 1 + self.grid_options["_errors_found"] = True + + # Try catching the error code and keep track of the unique ones. + try: + error_code = int( + binary_c_output.splitlines()[0] + .split("with error code")[-1] + .split(":")[0] + .strip() + ) + + if not error_code in self.grid_options["_failed_systems_error_codes"]: + self.grid_options["_failed_systems_error_codes"].append(error_code) + except ValueError: verbose_print( - "Process {} exceeded the maximum ({}) amount of failing systems. Stopped logging them to files now".format( - self.process_ID, - self.grid_options["failed_systems_threshold"], - ), + "Failed to extract the error-code", self.grid_options["verbosity"], 1, ) - self.grid_options["_errors_exceeded"] = True - # If not, write the failing systems to files unique to each process - else: - # Write arglines to file - argstring = self._return_argline(system_dict) - with open( - os.path.join( - self.grid_options["tmp_dir"], - "failed_systems_{}_process_{}.txt".format( - self.grid_options["_population_id"], self.process_ID - ), - ), - "a+", - ) as f: - f.write(argstring + "\n") + # Check if we have exceeded the amount of errors + if ( + self.grid_options["_failed_count"] + > self.grid_options["failed_systems_threshold"] + ): + if not self.grid_options["_errors_exceeded"]: + verbose_print( + "Process {} exceeded the maximum ({}) amount of failing systems. Stopped logging them to files now".format( + self.process_ID, + self.grid_options["failed_systems_threshold"], + ), + self.grid_options["verbosity"], + 1, + ) + self.grid_options["_errors_exceeded"] = True + # If not, write the failing systems to files unique to each process + else: + # Write arglines to file + argstring = self._return_argline(system_dict) + with open( + os.path.join( + self.grid_options["tmp_dir"], + "failed_systems_{}_process_{}.txt".format( + self.grid_options["_population_id"], self.process_ID + ), + ), + "a+", + ) as f: + f.write(argstring + "\n") + else: + verbose_print( + "binary_c had 0 output. Which is strange", self.grid_options['verbosity'], 2) ################################################################################################ -- GitLab