Skip to content

Commit

Permalink
Disable logging for individual jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Jan 4, 2024
1 parent 81047bf commit e64cd48
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
12 changes: 4 additions & 8 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ def submit(self, job_name, script, add_dep=None):
def create_sbatch_script(self, job_name, log_file):
script_lines = [
'#!/usr/bin/env bash',
f'#SBATCH --job-name="{job_name}"',
f'#SBATCH --job-name="{job_name}_{self.job_id}"',
f'#SBATCH --nodes=1',
f'#SBATCH --output={log_file}',
f'#SBATCH --open-mode=append',
Expand All @@ -475,7 +475,7 @@ def create_sbatch_script(self, job_name, log_file):
f'cd {self.chain_src_dir}',
'eval "$(conda shell.bash hook)"',
'conda activate proc-chain',
f'./run_chain.py {self.casename} -j {job_name} -c {self.job_id} -f -s',
f'./run_chain.py {self.casename} -j {job_name} -c {self.job_id} -f -s --no-logging',
'',
]

Expand All @@ -496,8 +496,8 @@ def wait_for_previous(self):
for ids in self.job_ids['previous'].values():
dep_ids.extend(ids)
if dep_ids:
job_file = self.chain_root / 'submit.wait.slurm'
log_file = self.chain_root / 'wait.log'
job_file = self.case_root / 'submit.wait.slurm'
log_file = self.case_root / 'wait.log'
dep_str = ':'.join(map(str, dep_ids))
script_lines = [
'#!/usr/bin/env bash', f'#SBATCH --job-name="wait"',
Expand All @@ -513,10 +513,6 @@ def wait_for_previous(self):

subprocess.run(['sbatch', '--wait', job_file], check=True)

# Remove sbatch script and log file after execution
os.remove(job_file)
os.remove(log_file)


class InvalidWorkflowType(Exception):
pass
25 changes: 18 additions & 7 deletions run_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ def parse_arguments():
action='store_true',
help=sync_help)

no_logging_help = ("Disable logging for chain_status.log.")
parser.add_argument("--no-logging",
action='store_false',
dest="enable_logging",
default=True,
help=no_logging_help)

force_help = ("Force the processing chain to redo all specified jobs,"
" even if they have been started already or were finished"
" previously. WARNING: Only logfiles get deleted,"
Expand Down Expand Up @@ -232,7 +239,6 @@ def run_chunk(cfg, force, resume):
cfg.log_job_status(job, 'START', job_launch_time)

# Submit the job
#getattr(jobs, job).main(cfg)
script = cfg.create_sbatch_script(job, logfile)
job_id = cfg.submit(job, script)

Expand Down Expand Up @@ -451,6 +457,9 @@ def main():
# Make ntry a Config variable
cfg.ntry = args.ntry

# Check logging settings
cfg.logging = args.enable_logging

# Convert relative to absolute paths
cfg.convert_paths_to_absolute()

Expand Down Expand Up @@ -481,13 +490,14 @@ def main():
# Print config before chain starts
cfg.print_config()

tools.create_dir(cfg.case_root, "case_root")
print(
f"Starting chain for case {casename} and workflow {cfg.workflow_name}"
)

launch_time = datetime.now()
tools.create_dir(cfg.case_root, "case_root")
cfg.log_job_status('chain', 'START', launch_time)
if cfg.logging:
launch_time = datetime.now()
cfg.log_job_status('chain', 'START', launch_time)

# Check for restart compatibility and spinup
if 'restart' in cfg.workflow['features']:
Expand All @@ -505,9 +515,10 @@ def main():
cfg.enddate_sim = cfg.enddate
run_chunk(cfg=cfg, force=args.force, resume=args.resume)

end_time = datetime.now()
duration = end_time - launch_time
cfg.log_job_status('chain', 'FINISH', end_time, duration)
if cfg.logging:
end_time = datetime.now()
duration = end_time - launch_time
cfg.log_job_status('chain', 'FINISH', end_time, duration)
print('>>> Finished the processing chain successfully <<<')


Expand Down

0 comments on commit e64cd48

Please sign in to comment.