From 942f775425f813fc975368b6dc77719d950fe45c Mon Sep 17 00:00:00 2001 From: Mayeul Aubin Date: Mon, 17 Mar 2025 13:54:54 +0100 Subject: [PATCH] fixing progress bars with log files --- low_level.py | 4 ++++ scola.py | 11 +++++++++++ simbelmyne.py | 10 ++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/low_level.py b/low_level.py index e721508..e987cf0 100644 --- a/low_level.py +++ b/low_level.py @@ -240,6 +240,10 @@ def progress_bar_from_logfile(filename:str, desc:str="", verbose:int=1, **kwargs current_operation, total_operations = get_progress_from_logfile(filename) previous_operation = 0 + while total_operations == 0: # Wait for the simulation to be initialised, and to run the first operation + sleep(2) + current_operation, total_operations = get_progress_from_logfile(filename) + if current_operation == total_operations: # print_message("Progress bar not needed, the process is already finished.", 3, "low level", verbose=verbose) return diff --git a/scola.py b/scola.py index 87e2f43..a6156ad 100644 --- a/scola.py +++ b/scola.py @@ -22,6 +22,9 @@ def main_scola(parsed_args): tile_bar = tqdm(total=nboxes_tot, desc="sCOLA", unit="box", disable=(parsed_args.verbose!=1)) # The progress bar cannot work if there are print statements in the loop for b in range(1,nboxes_tot+1): if not isfile(card_dict["OutputTilesBase"]+str(b)+".h5") or parsed_args.force: + if isfile(log_file+f"_{b}"): # Remove the preexisting log file to allow for the progress_bar to be run normally + from os import remove + remove(log_file+f"_{b}") if parsed_args.verbose > 1: print_message(f"Running box {b}/{nboxes_tot}.", 2, "scola", verbose=parsed_args.verbose) command_args = ["scola", paramfile, log_file, "-b", str(b)] @@ -72,6 +75,10 @@ def main_scola(parsed_args): print_message(f"Submitting scola job to SLURM.", 1, "scola", verbose=parsed_args.verbose) command_args = ["sbatch", slurm_script] + for b in range(1,nboxes_tot+1): + if isfile(log_file+f"_{b}"): # Remove the preexisting log file to allow for the progress_bar to be run normally + os.remove(log_file+f"_{b}") + if parsed_args.verbose < 2: subprocess.run(command_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) else: @@ -105,6 +112,10 @@ def main_scola(parsed_args): print_message(f"Submitting scola job to SLURM.", 1, "scola", verbose=parsed_args.verbose) command_args = ["sbatch", slurm_script] + for b in range(missing_tiles[0],missing_tiles[1]+1): + if isfile(log_file+f"_{b}"): # Remove the preexisting log file to allow for the progress_bar to be run normally + os.remove(log_file+f"_{b}") + if parsed_args.verbose < 2: subprocess.run(command_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) else: diff --git a/simbelmyne.py b/simbelmyne.py index 417845d..3ef9a3f 100644 --- a/simbelmyne.py +++ b/simbelmyne.py @@ -14,7 +14,10 @@ def main_simbelmyne(parsed_args): if parsed_args.execution == "local": print_message("Running Simbelyne in local mode.", 1, "simbelmyne", verbose=parsed_args.verbose) - + if isfile(log_file): # Remove the preexisting log file to allow for the progress_bar to be run normally + from os import remove + oremove(log_file) + command_args = ["simbelmyne", paramfile, log_file] if parsed_args.verbose < 2: @@ -51,6 +54,10 @@ def main_simbelmyne(parsed_args): command_args = ["sbatch", slurm_script] + if isfile(log_file): # Remove the preexisting log file to allow for the progress_bar to be run normally + from os import remove + oremove(log_file) + if parsed_args.verbose < 2: subprocess.run(command_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) else: @@ -75,7 +82,6 @@ if __name__ == "__main__": from slurm_submission import register_arguments_slurm parser = ArgumentParser(description="Run Simbelmyne.") - # TODO: reduce the volume of arguments register_arguments_main(parser) register_arguments_timestepping(parser) register_arguments_simbelmyne(parser)