Beispiel #1
0
    def run_math(self, pool: futures.ThreadPoolExecutor):
        ''' Run diffcrash math

        Parameters
        ----------
        pool : `concurrent.futures.ThreadPoolExecutor`
            multiprocessing pool
        '''

        msg = "Running Math ... \r"
        print(str_running(msg), end='', flush=True)
        self.logger.info(msg)

        start_time = time.time()
        return_code_future = pool.submit(run_subprocess, [
            os.path.join(self.diffcrash_home, "DFC_Math_" + self.crash_code),
            self.project_dir
        ])
        returnCode = return_code_future.result()

        # check return code
        if returnCode != 0:

            msg = "Running Math ... done in {0:.2f}s   ".format(time.time() -
                                                                start_time)
            print(str_error(msg))
            self.logger.error(msg)

            err_msg = "Caught a nonzero return code '{0}'".format(returnCode)
            self.logger.error(err_msg)
            raise RuntimeError(str_error(err_msg))

        # check logs
        messages = self.check_if_logfiles_show_success("DFC_MATH*.log")
        if messages:

            # print failure
            msg = "Running Math ... done in {0:.2f}s   ".format(time.time() -
                                                                start_time)
            print(str_error(msg))
            self.logger.error(msg)

            # print failed logs
            for msg in messages:
                print(str_error(msg))
                self.logger.error(msg)

            err_msg = "Logfile does indicate a failure. Please check the log files in '{0}'.".format(
                self.logfile_dir)
            self.logger.error(err_msg)
            raise RuntimeError(str_error(err_msg))

        # print success
        msg = "Running Math ... done in {0:.2f}s   ".format(time.time() -
                                                            start_time)
        print(str_success(msg))
        self.logger.info(msg)
    def run_merge(self, pool: futures.ThreadPoolExecutor):
        ''' Run diffcrash merge

        Parameters
        ----------
        pool : `concurrent.futures.ThreadPoolExecutor`
            multiprocessing pool
        '''

        msg = "Running Merge ... "
        print(str_running(msg) + '\r', end='', flush=True)
        self.logger.info(msg)

        # create ionput file for merge
        merge_inputfile = self._create_merge_input_file(self.project_dir)

        # clear previous merges
        for filepath in glob.glob(os.path.join(self.project_dir, "mode_*")):
            if os.path.isfile(filepath):
                os.remove(filepath)

        # run the thing
        start_time = time.time()
        return_code_future = pool.submit(run_subprocess,
                                         [os.path.join(self.diffcrash_home, "DFC_Merge_All_" + self.crash_code), self.project_dir, merge_inputfile])
        return_code = return_code_future.result()

        # check return code
        if return_code != 0:
            msg = "Running Merge ... done in {0:.2f}s   ".format(time.time() - start_time)
            print(str_error(msg))
            self.logger.info(msg)
            
            msg = "The process failed somehow."
            self.logger.error(msg)
            raise RuntimeError(str_error(msg))

        # check logfiles
        messages = self.check_if_logfiles_show_success("DFC_Merge_All.log")
        if messages:
            msg = "Running Merge ... done in {0:.2f}s   ".format(time.time() - start_time)
            print(str_error(msg))
            self.logger.error(msg)

            for msg in messages:
                print(str_error(msg))
                self.logger.info(msg)

            msg = "DFC_Merge_All failed. Please check the log files in '{0}'.".format(
                self.logfile_dir)
            self.logger.error(msg)
            raise RuntimeError(str_error(msg))

        # print success
        msg = "Running Merge ... done in {0:.2f}s   ".format(time.time() - start_time)
        print(str_success(msg))
        self.logger.info(msg)
    def run_eigen(self, pool: futures.ThreadPoolExecutor):
        ''' Run diffcrash eigen

        Parameters
        ----------
        pool : `concurrent.futures.ThreadPoolExecutor`
            multiprocessing pool
        '''

        msg = "Running Eigen ... "
        print(str_running(msg) + '\r', end='', flush=True)
        self.logger.info(msg)

        # create input file for process
        eigen_inputfile = self._create_eigen_input_file(self.project_dir)

        # run the thing
        start_time = time.time()
        return_code_future = pool.submit(run_subprocess,
                                         [os.path.join(self.diffcrash_home, "DFC_Eigen_" + self.crash_code), self.project_dir, eigen_inputfile])

        # please hold the line ...
        return_code = return_code_future.result()

        # check return code
        if return_code != 0:
            msg  ="Running Eigen ... done in {0:.2f}s   ".format(time.time() - start_time)
            print(str_error(msg))
            self.logger.error(msg)

            msg = "The process failed somehow."
            self.logger.error(msg)
            raise RuntimeError(str_error(msg))

        # check log file
        messages = self.check_if_logfiles_show_success("DFC_Matrix_*")
        if messages:

            # print failure
            msg = "Running Eigen ... done in {0:.2f}s   ".format(time.time() - start_time)
            print(str_error(msg))
            self.logger.error(msg)

            # print why
            for msg in messages:
                print(str_error(msg))
                self.logger.error(msg)

            msg = "DFC_Eigen failed. Please check the log files in '{0}'.".format(self.logfile_dir)
            self.logger.error(msg)
            raise RuntimeError(str_error(msg))

        # print success
        msg = "Running Eigen ... done in {0:.2f}s   ".format(time.time() - start_time)
        print(str_success(msg))
        self.logger.info(msg)
Beispiel #4
0
    def run_export(self, pool: futures.ThreadPoolExecutor):
        ''' Run diffcrash export

        Parameters
        ----------
        pool : `concurrent.futures.ThreadPoolExecutor`
            multiprocessing pool
        '''

        msg = "Running Export ... "
        print(str_running(msg) + '\r', end='', flush=True)
        self.logger.info(msg)

        if self.config_file is None:
            export_item_list = []

            # check for pdmx
            pdmx_filepath_list = glob.glob(
                os.path.join(self.project_dir, "*_pdmx"))
            if pdmx_filepath_list:
                export_item_list.append(os.path.basename(
                    pdmx_filepath_list[0]))

            # check for pdij
            pdij_filepath_list = glob.glob(
                os.path.join(self.project_dir, "*_pdij"))
            if pdij_filepath_list:
                export_item_list.append(os.path.basename(
                    pdij_filepath_list[0]))

        else:
            export_item_list = self.read_config_file(self.config_file)

        # remove previous existing exports
        for export_item in export_item_list:
            export_item_filepath = os.path.join(self.project_dir,
                                                export_item + ".d3plot.fz")
            if os.path.isfile(export_item_filepath):
                os.remove(export_item_filepath)

        # do the thing
        start_time = time.time()
        return_code_futures = [
            pool.submit(run_subprocess, [
                os.path.join(self.diffcrash_home, "DFC_Export_" +
                             self.crash_code), self.project_dir, export_item
            ]) for export_item in export_item_list
        ]

        return_codes = [
            result_future.result() for result_future in return_code_futures
        ]

        # check return code
        if any(rc != 0 for rc in return_codes):
            msg = "Running Export ... done in {0:.2f}s   ".format(time.time() -
                                                                  start_time)
            print(str_error(msg))
            self.logger.error(msg)

            for i_export, export_return_code in enumerate(return_codes):
                if export_return_code != 0:
                    msg = "Return code of export '{0}' was nonzero: '{1}'".format(
                        export_item_list[i_export], export_return_code)
                    self.logger.error(msg)
                    print(str_error(msg))

            msg = "At least one export process failed."
            self.logger.error(msg)
            raise RuntimeError(str_error(msg))

        # check logs
        messages = self.check_if_logfiles_show_success("DFC_Export_*")
        if messages:

            # print failure
            msg = "Running Export ... done in {0:.2f}s   ".format(time.time() -
                                                                  start_time)
            print(str_error(msg))
            self.logger.error(msg)

            # print logs
            for msg in messages:
                print(str_error(msg))
                self.logger.error(msg)

            msg = "At least one export failed. Please check the log files in '{0}'.".format(
                self.logfile_dir)
            self.logger.error(msg)
            raise RuntimeError(str_error(msg))

        # print success
        msg = "Running Export ... done in {0:.2f}s   ".format(time.time() -
                                                              start_time)
        print(str_success(msg))
        self.logger.info(msg)
Beispiel #5
0
    def run_import(self, pool: futures.ThreadPoolExecutor):
        ''' Run diffcrash import of runs

        Parameters
        ----------
        pool : `concurrent.futures.ThreadPoolExecutor`
            multiprocessing pool
        '''

        # list of arguments to run in the command line
        import_arguments = []

        # id 1 is the reference run
        # id 2 and higher are the imported runs
        counter_offset = 2

        # assemble arguments for running the import
        # entry 0 is the reference run, thus we start at 1
        for i_filepath in range(len(self.simulation_runs)):

            # parameter file missing
            if self.parameter_file is None:
                if self.use_id_mapping:
                    args = [
                        os.path.join(self.diffcrash_home,
                                     "DFC_Import_" + self.crash_code + "_fem"),
                        "-id", self.simulation_runs[i_filepath],
                        self.project_dir,
                        str(i_filepath + counter_offset)
                    ]
                else:
                    args = [
                        os.path.join(self.diffcrash_home,
                                     "DFC_Import_" + self.crash_code + "_fem"),
                        self.simulation_runs[i_filepath], self.project_dir,
                        str(i_filepath + counter_offset)
                    ]
            # indeed there is a parameter file
            else:
                if self.use_id_mapping:
                    args = [
                        os.path.join(self.diffcrash_home,
                                     "DFC_Import_" + self.crash_code), "-ID",
                        self.simulation_runs[i_filepath], self.project_dir,
                        str(i_filepath + counter_offset)
                    ]
                else:
                    args = [
                        os.path.join(self.diffcrash_home,
                                     "DFC_Import_" + self.crash_code),
                        self.simulation_runs[i_filepath], self.project_dir,
                        str(i_filepath + counter_offset)
                    ]

            # append args to list
            import_arguments.append(args)

        # do the thing
        msg = "Running Imports ...\r"
        print(str_running(msg), end='', flush=True)
        self.logger.info(msg)
        start_time = time.time()
        return_code_futures = [
            pool.submit(run_subprocess, args) for args in import_arguments
        ]

        # wait for imports to finish (with a progressbar)
        n_imports_finished = sum(return_code_future.done()
                                 for return_code_future in return_code_futures)
        while n_imports_finished != len(return_code_futures):

            # check again
            n_new_imports_finished = sum(
                return_code_future.done()
                for return_code_future in return_code_futures)

            # print
            percentage = n_new_imports_finished / \
                len(return_code_futures) * 100

            if n_imports_finished != n_new_imports_finished:
                msg = "Running Imports ... [{0}/{1}] - {2:3.2f}%\r".format(
                    n_new_imports_finished, len(return_code_futures),
                    percentage)
                print(str_running(msg), end='', flush=True)
                self.logger.info(msg)

            n_imports_finished = n_new_imports_finished

            # wait a little bit
            time.sleep(0.25)

        return_codes = [
            return_code_future.result()
            for return_code_future in return_code_futures
        ]

        # print failure
        if any(return_code != 0 for return_code in return_codes):

            n_failed_runs = 0
            for i_run, return_code in enumerate(return_codes):
                if return_code != 0:
                    _err_msg = str_error(
                        "Run {0} failed to import with error code '{1}'.".
                        format(i_run, return_code))
                    print(str_error(_err_msg))
                    self.logger.error(_err_msg)
                    n_failed_runs += 1

            err_msg = "Running Imports ... done in {0:.2f}s   ".format(
                time.time() - start_time)
            print(str_error(err_msg))
            self.logger.error(err_msg)

            err_msg = "Import of {0} runs failed.".format(n_failed_runs)
            self.logger.error(err_msg)
            raise RuntimeError(str_error(err_msg))

        # check log files
        messages = self.check_if_logfiles_show_success('DFC_Import_*.log')
        if messages:

            # print failure
            msg = "Running Imports ... done in {0:.2f}s   ".format(
                time.time() - start_time)
            print(str_error(msg))
            self.logger.info(msg)

            # print failed logs
            for msg in messages:
                self.logger.error(msg)
                print(str_error(msg))

            err_msg = "At least one import failed. Please check the log files in '{0}'.".format(
                self.logfile_dir)
            self.logger.error(err_msg)
            raise RuntimeError(str_error(err_msg))

        # print success
        print(
            str_success("Running Imports ... done in {0:.2f}s   ").format(
                time.time() - start_time))
Beispiel #6
0
    def run_setup(self, pool: futures.ThreadPoolExecutor):
        ''' Run diffcrash setup

        Parameters
        ----------
        pool : `concurrent.futures.ThreadPoolExecutor`
            multiprocessing pool
        '''

        # SETUP
        msg = "Running Setup ... "
        print(str_running(msg) + '\r', end='', flush='')
        self.logger.info(msg)

        args = []
        if self.config_file is None and self.parameter_file is None:
            args = [
                os.path.join(self.diffcrash_home,
                             "DFC_Setup_" + self.crash_code + "_fem"),
                self.reference_run, self.project_dir
            ]
        elif self.config_file is not None and self.parameter_file is None:
            args = [
                os.path.join(self.diffcrash_home,
                             "DFC_Setup_" + self.crash_code + "_fem"),
                self.reference_run, self.project_dir, "-C", self.config_file
            ]
        elif self.config_file is None and self.parameter_file is not None:
            if ".fz" in self.reference_run:
                args = [
                    os.path.join(self.diffcrash_home,
                                 "DFC_Setup_" + self.crash_code + "_fem"),
                    self.reference_run, self.project_dir, "-P",
                    self.parameter_file
                ]
            else:
                args = [
                    os.path.join(self.diffcrash_home,
                                 "DFC_Setup_" + self.crash_code),
                    self.reference_run, self.project_dir, "-P",
                    self.parameter_file
                ]
        elif self.config_file is not None and self.parameter_file is not None:
            if ".fz" in self.reference_run:
                args = [
                    os.path.join(self.diffcrash_home,
                                 "DFC_Setup_" + self.crash_code + "_fem"),
                    self.reference_run, self.project_dir, "-C",
                    self.config_file, "-P", self.parameter_file
                ]
            else:
                args = [
                    os.path.join(self.diffcrash_home,
                                 "DFC_Setup_" + self.crash_code),
                    self.reference_run, self.project_dir, "-C",
                    self.config_file, "-P", self.parameter_file
                ]
        start_time = time.time()

        # submit task
        return_code_future = pool.submit(run_subprocess, args)
        return_code = return_code_future.result()

        # check return code
        if return_code != 0:
            err_msg = "Running Setup ... done in {0:.2f}s".format(time.time() -
                                                                  start_time)
            print(str_error(err_msg))
            self.logger.error(err_msg)

            err_msg = "Process somehow failed."
            self.logger.error(err_msg)
            raise RuntimeError(str_error(err_msg))

        # check log
        messages = self.check_if_logfiles_show_success("DFC_Setup.log")
        if messages:

            err_msg = "Running Setup ... done in {0:.2f}s".format(time.time() -
                                                                  start_time)
            print(str_error(err_msg))
            self.logger.error(err_msg)

            # print failed logs
            for msg in messages:
                print(str_error(msg))
                self.logger.error(msg)

            err_msg = "Setup failed."
            self.logger.error(err_msg)
            raise RuntimeError(str_error(err_msg))

        # print success
        msg = "Running Setup ... done in {0:.2f}s".format(time.time() -
                                                          start_time)
        print(str_success(msg))
        self.logger.info(msg)