97 lines
No EOL
4.6 KiB
Python
97 lines
No EOL
4.6 KiB
Python
def main_simbelmyne(parsed_args):
|
|
from args_main import parse_arguments_main
|
|
from low_level import print_starting_module, print_message, print_ending_module, progress_bar_from_logfile
|
|
from os.path import isfile
|
|
import subprocess
|
|
|
|
print_starting_module("simbelmyne", verbose=parsed_args.verbose)
|
|
main_dict = parse_arguments_main(parsed_args)
|
|
paramfile=parsed_args.paramfile
|
|
if paramfile is None:
|
|
paramfile = main_dict["paramdir"]+"parameters_"+main_dict["simname"]+".sbmy"
|
|
log_file = main_dict["logdir"]+main_dict["simname"]+".log"
|
|
|
|
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:
|
|
subprocess.Popen(command_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) # Use Popen instead of run to be able to display the progress bar
|
|
if not main_dict["mode"] in ["pre_sCOLA", "post_sCOLA", "allsCOLA"]: # No progress bar for pre/post sCOLA
|
|
progress_bar_from_logfile(log_file, desc=main_dict["simname"], verbose=parsed_args.verbose, leave=False)
|
|
else:
|
|
subprocess.run(command_args)
|
|
|
|
print_message("Simbelyne finished.", 1, "simbelmyne", verbose=parsed_args.verbose)
|
|
|
|
elif parsed_args.execution == "slurm":
|
|
from slurm_submission import create_slurm_script, parse_arguments_slurm
|
|
from args_main import parse_arguments_main
|
|
print_message("Running simbelmyne in slurm mode.", 1, "simbelmyne", verbose=parsed_args.verbose)
|
|
slurm_dict=parse_arguments_slurm(parsed_args)
|
|
main_dict=parse_arguments_main(parsed_args)
|
|
slurm_script = slurm_dict["scripts"]+"simbelmyne_"+main_dict["simname"]+".sh"
|
|
|
|
if not isfile(slurm_script) or parsed_args.force:
|
|
print_message(f"SLURM script {slurm_script} does not exist (or forced). Creating it.", 2, "simbelmyne", verbose=parsed_args.verbose)
|
|
create_slurm_script(
|
|
slurm_template=slurm_dict["simbelmyne_template"],
|
|
slurm_script=slurm_script,
|
|
job="simbelmyne",
|
|
job_config_file=paramfile,
|
|
job_log=log_file,
|
|
job_name=main_dict["simname"],
|
|
)
|
|
print_message(f"SLURM script written to {slurm_script}.", 3, "simbelmyne", verbose=parsed_args.verbose)
|
|
else:
|
|
print_message(f"SLURM script {slurm_script} exists.", 2, "simbelmyne", verbose=parsed_args.verbose)
|
|
|
|
print_message(f"Submitting simbelmyne job to SLURM.", 1, "simbelmyne", verbose=parsed_args.verbose)
|
|
|
|
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
|
|
remove(log_file)
|
|
|
|
if parsed_args.verbose < 2:
|
|
subprocess.run(command_args, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
|
else:
|
|
subprocess.run(command_args)
|
|
|
|
print_message("Simbelmyne job submitted.", 2, "simbelmyne", verbose=parsed_args.verbose)
|
|
if not main_dict["mode"] in ["pre_sCOLA", "post_sCOLA", "allsCOLA"]: # No progress bar for pre/post sCOLA
|
|
progress_bar_from_logfile(log_file, desc=main_dict["simname"], verbose=parsed_args.verbose)
|
|
|
|
else:
|
|
raise ValueError(f"Execution mode {parsed_args.execution} not recognized.")
|
|
|
|
print_ending_module("simbelmyne", verbose=parsed_args.verbose)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
from argparse import ArgumentParser
|
|
from args_main import register_arguments_main
|
|
from timestepping import register_arguments_timestepping, main_timestepping
|
|
from parameters_card import register_arguments_card, main_parameter_card
|
|
from cosmo_params import register_arguments_cosmo
|
|
from parameters_simbelmyne import register_arguments_simbelmyne
|
|
from slurm_submission import register_arguments_slurm
|
|
|
|
parser = ArgumentParser(description="Run Simbelmyne.")
|
|
register_arguments_main(parser)
|
|
register_arguments_timestepping(parser)
|
|
register_arguments_simbelmyne(parser)
|
|
register_arguments_slurm(parser)
|
|
register_arguments_card(parser)
|
|
register_arguments_cosmo(parser)
|
|
parsed_args = parser.parse_args()
|
|
|
|
main_parameter_card(parsed_args)
|
|
main_timestepping(parsed_args)
|
|
main_simbelmyne(parsed_args) |