From 2b9ad02cbe3a667f73de748695580684c548364d Mon Sep 17 00:00:00 2001 From: teopb Date: Wed, 13 Dec 2023 20:27:53 -0700 Subject: [PATCH] make prerun delete old output directories, otherwise ensemble.py won't submit new jobs --- MPAS_true_failure_testing/pre_run_script.py | 32 +++++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/MPAS_true_failure_testing/pre_run_script.py b/MPAS_true_failure_testing/pre_run_script.py index e0cb468..0be82ec 100644 --- a/MPAS_true_failure_testing/pre_run_script.py +++ b/MPAS_true_failure_testing/pre_run_script.py @@ -9,6 +9,7 @@ import f90nml import numpy as np import copy +import shutil def main(argv): @@ -61,6 +62,13 @@ def main(argv): # create empty directories for outputs output_folder = test_output_dir + f"/{test_name}" + + if os.path.exists(output_folder): + try: + shutil.rmtree(output_folder) + except OSError as e: + print("Error: %s - %s." % (e.filename, e.strerror)) + os.mkdir(output_folder) os.mkdir(output_folder + "/history_files") @@ -93,9 +101,15 @@ def main(argv): # create empty directories for outputs output_folder = test_output_dir + f"/{var_name}_perturb_neg{order}" - if not os.path.exists(output_folder): - os.mkdir(output_folder) - os.mkdir(output_folder + "/history_files") + + if os.path.exists(output_folder): + try: + shutil.rmtree(output_folder) + except OSError as e: + print("Error: %s - %s." % (e.filename, e.strerror)) + + os.mkdir(output_folder) + os.mkdir(output_folder + "/history_files") # modify namelist params mod_nml[namelist_preface][var_name] = default_var_value * (1 - 10.**order) @@ -119,9 +133,15 @@ def main(argv): # create empty directories for outputs output_folder = test_output_dir + f"/{var_name}_perturb_{order}" - if not os.path.exists(output_folder): - os.mkdir(output_folder) - os.mkdir(output_folder + "/history_files") + + if os.path.exists(output_folder): + try: + shutil.rmtree(output_folder) + except OSError as e: + print("Error: %s - %s." % (e.filename, e.strerror)) + + os.mkdir(output_folder) + os.mkdir(output_folder + "/history_files") # modify namelist params mod_nml[namelist_preface][var_name] = default_var_value * (1 + 10.**order)