Skip to content

Commit

Permalink
Some code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaehn committed Jan 9, 2024
1 parent 767ec08 commit fd8b603
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
15 changes: 7 additions & 8 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import subprocess
import os
import yaml
import logging

from jobs import tools
from pathlib import Path
Expand Down Expand Up @@ -408,13 +407,13 @@ def get_dep_ids(self, job_name, add_dep=None):
"""Get dependency job ids for `job_name`"""
# Initial list of dependencies
if add_dep is not None:
if type(add_dep) is int:
if isinstance(add_dep, int):
dep_id_list = [add_dep]
else:
try:
dep_id_list = list(add_dep)
except TypeError:
print(f'add_dep must be an iterable')
print("add_dep must be an iterable")
else:
dep_id_list = []

Expand Down Expand Up @@ -461,7 +460,7 @@ def submit(self, job_name, script, add_dep=None, logfile=None):
job_id = int(result.stdout)
print(f' └── Submitted batch job {job_id}')

if not job_name in self.job_ids['current']:
if job_name not in self.job_ids['current']:
self.job_ids['current'][job_name] = [job_id]
else:
self.job_ids['current'][job_name].append(job_id)
Expand Down Expand Up @@ -490,9 +489,9 @@ def create_sbatch_script(self, job_name, log_file):
script_lines = [
'#!/usr/bin/env bash',
f'#SBATCH --job-name="{job_name}_{self.job_id}"',
f'#SBATCH --nodes=1',
'#SBATCH --nodes=1',
f'#SBATCH --output={log_file}',
f'#SBATCH --open-mode=append',
'#SBATCH --open-mode=append',
f'#SBATCH --account={self.compute_account}',
f'#SBATCH --partition={self.compute_queue}',
f'#SBATCH --constraint={self.constraint}',
Expand Down Expand Up @@ -524,8 +523,8 @@ def wait_for_previous(self):
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"',
f'#SBATCH --nodes=1', f'#SBATCH --output={log_file}',
'#!/usr/bin/env bash', '#SBATCH --job-name="wait"',
'#SBATCH --nodes=1', f'#SBATCH --output={log_file}',
f'#SBATCH --account={self.compute_account}',
f'#SBATCH --partition={self.compute_queue}',
f'#SBATCH --constraint={self.constraint}',
Expand Down
6 changes: 3 additions & 3 deletions jobs/prepare_art_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import subprocess
from . import tools
from pathlib import Path
from .tools.interpolate_data import create_oh_for_restart, create_oh_for_inicond
from .tools.interpolate_data import create_oh_for_restart, create_oh_for_inicond # noqa: F401
from .tools.fetch_external_data import fetch_era5, fetch_era5_nudging


Expand Down Expand Up @@ -153,8 +153,8 @@ def main(cfg):
else:

# -- Check the extension of tracer variables in the restart file
ds_restart = xr.open_dataset(cfg.restart_file)
tracer_name = cfg.species2restart[0]
ds_restart = xr.open_dataset(cfg.restart_file) # noqa: F841
tracer_name = cfg.species2restart[0] # noqa: F841
# FIXME:
# var_restart = [
# IndexError: list index out of range
Expand Down
4 changes: 2 additions & 2 deletions run_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def run_chunk(cfg, force, resume):

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

# wait for previous chunk to be done
cfg.wait_for_previous()
Expand Down Expand Up @@ -295,7 +295,7 @@ def run_chunk(cfg, force, resume):

exitcode = 0
try_count = 0
except:
except Exception:
subject = "ERROR or TIMEOUT in job '%s' for chain '%s'" % (
job, cfg.job_id)
logging.exception(subject)
Expand Down

0 comments on commit fd8b603

Please sign in to comment.