Skip to content

Commit

Permalink
Implements the prereq argument for case.submit, allowing the user to …
Browse files Browse the repository at this point in the history
…specify jobs which should finish (not necessarily successfully) before running the current job
  • Loading branch information
mfdeakin-sandia committed Jul 20, 2017
1 parent eb839ca commit d37f2a1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 41 deletions.
13 changes: 6 additions & 7 deletions scripts/Tools/case.submit
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,23 @@ OR

args = CIME.utils.parse_args_and_handle_standard_logging_options(args, parser)

CIME.utils.expect(args.prereq is None, "--prereq not currently supported")

return args.test, args.caseroot, args.job, args.no_batch, args.resubmit, \
args.skip_preview_namelist, args.mail_user, args.mail_type, \
return args.test, args.caseroot, args.job, args.no_batch, args.prereq, \
args.resubmit, args.skip_preview_namelist, args.mail_user, args.mail_type, \
args.batch_args

###############################################################################
def _main_func(description):
###############################################################################
test, caseroot, job, no_batch, resubmit, skip_pnl, \
test, caseroot, job, no_batch, prereq, resubmit, skip_pnl, \
mail_user, mail_type, batch_args = parse_command_line(sys.argv, description)
if test:
test_results = doctest.testmod(verbose=True)
sys.exit(1 if test_results.failed > 0 else 0)

with Case(caseroot, read_only=False) as case:
submit(case, job=job, no_batch=no_batch, resubmit=resubmit, skip_pnl=skip_pnl,
mail_user=mail_user, mail_type=mail_type, batch_args=batch_args)
submit(case, job=job, no_batch=no_batch, prereq=prereq, resubmit=resubmit,
skip_pnl=skip_pnl, mail_user=mail_user, mail_type=mail_type,
batch_args=batch_args)

if __name__ == "__main__":
_main_func(__doc__)
42 changes: 19 additions & 23 deletions scripts/lib/CIME/XML/env_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def __init__(self, case_root=None, infile="env_batch.xml"):
"""
initialize an object interface to file env_batch.xml in the case directory
"""
self.prereq_jobid = None
self.batchtype = None
# This arbitrary setting should always be overwritten
self._default_walltime = "00:20:00"
Expand Down Expand Up @@ -319,9 +318,9 @@ def get_submit_args(self, case, job):

return submitargs

def submit_jobs(self, case, no_batch=False, job=None, skip_pnl=False,
mail_user=None, mail_type='never', batch_args=None,
dry_run=False):
def submit_jobs(self, case, no_batch=False, job=None, user_prereq=None,
skip_pnl=False, mail_user=None, mail_type='never',
batch_args=None, dry_run=False):
alljobs = self.get_jobs()
startindex = 0
jobs = []
Expand Down Expand Up @@ -358,25 +357,16 @@ def submit_jobs(self, case, no_batch=False, job=None, skip_pnl=False,
deps = dependency.split()
else:
deps = []
jobid = ""
if self.prereq_jobid is not None:
jobid = self.prereq_jobid
dep_jobs = []
if user_prereq is not None:
dep_jobs.append(user_prereq)
for dep in deps:
if dep in depid.keys() and depid[dep] is not None:
jobid += " " + str(depid[dep])
#TODO: doubt these will be used
# elif dep == "and":
# jobid += " && "
# elif dep == "or":
# jobid += " || "
dep_jobs.append(str(depid[dep]))


slen = len(jobid)
if slen == 0:
jobid = None

logger.warn("job is {}".format(job))
result = self._submit_single_job(case, job, jobid,
logger.info("job {} depends on {}".format(job, dep_jobs))
result = self._submit_single_job(case, job,
dep_jobs=dep_jobs,
no_batch=no_batch,
skip_pnl=skip_pnl,
mail_user=mail_user,
Expand All @@ -394,7 +384,7 @@ def submit_jobs(self, case, no_batch=False, job=None, skip_pnl=False,
else:
return sorted(list(depid.values()))

def _submit_single_job(self, case, job, depid=None, no_batch=False,
def _submit_single_job(self, case, job, dep_jobs=None, no_batch=False,
skip_pnl=False, mail_user=None, mail_type='never',
batch_args=None, dry_run=False):
logger.warn("Submit job {}".format(job))
Expand All @@ -418,9 +408,15 @@ def _submit_single_job(self, case, job, depid=None, no_batch=False,
if args_override:
submitargs = args_override

if depid is not None:
if dep_jobs is not None and len(dep_jobs) > 0:
logger.info("dependencies: {}".format(dep_jobs))
dep_string = self.get_value("depend_string", subgroup=None)
dep_string = dep_string.replace("jobid",depid.strip()) # pylint: disable=maybe-no-member
separator_string = self.get_value("depend_separator", subgroup=None)
expect("jobid" in dep_string, "depend_string is missing jobid for prerequisite jobs")
dep_ids_str = str(dep_jobs[0])
for dep_id in dep_jobs[1:]:
dep_ids_str += separator_string + str(dep_id)
dep_string = dep_string.replace("jobid",dep_ids_str.strip()) # pylint: disable=maybe-no-member
submitargs += " " + dep_string

if batch_args is not None:
Expand Down
4 changes: 2 additions & 2 deletions scripts/lib/CIME/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,11 +1236,11 @@ def create_clone(self, newcase, keepexe=False, mach_dir=None, project=None, cime

return newcase

def submit_jobs(self, no_batch=False, job=None, skip_pnl=False,
def submit_jobs(self, no_batch=False, job=None, prereq=None, skip_pnl=False,
mail_user=None, mail_type='never', batch_args=None,
dry_run=False):
env_batch = self.get_env('batch')
return env_batch.submit_jobs(self, no_batch=no_batch, job=job,
return env_batch.submit_jobs(self, no_batch=no_batch, job=job, user_prereq=prereq,
skip_pnl=skip_pnl, mail_user=mail_user,
mail_type=mail_type, batch_args=batch_args,
dry_run=dry_run)
Expand Down
20 changes: 11 additions & 9 deletions scripts/lib/CIME/case_submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

logger = logging.getLogger(__name__)

def _submit(case, job=None, resubmit=False, no_batch=False, skip_pnl=False,
mail_user=None, mail_type='never', batch_args=None):
def _submit(case, job=None, no_batch=False, prereq=None, resubmit=False,
skip_pnl=False, mail_user=None, mail_type='never', batch_args=None):
caseroot = case.get_value("CASEROOT")

if job is None:
Expand Down Expand Up @@ -65,13 +65,13 @@ def _submit(case, job=None, resubmit=False, no_batch=False, skip_pnl=False,
case.flush()

logger.warn("submit_jobs {}".format(job))
job_ids = case.submit_jobs(no_batch=no_batch, job=job, skip_pnl=skip_pnl,
mail_user=mail_user, mail_type=mail_type,
batch_args=batch_args)
job_ids = case.submit_jobs(no_batch=no_batch, job=job, prereq=prereq,
skip_pnl=skip_pnl, mail_user=mail_user,
mail_type=mail_type, batch_args=batch_args)
logger.info("Submitted job ids {}".format(job_ids))

def submit(case, job=None, resubmit=False, no_batch=False, skip_pnl=False,
mail_user=None, mail_type='never', batch_args=None):
def submit(case, job=None, no_batch=False, prereq=None, resubmit=False,
skip_pnl=False, mail_user=None, mail_type='never', batch_args=None):
if case.get_value("TEST"):
caseroot = case.get_value("CASEROOT")
casebaseid = case.get_value("CASEBASEID")
Expand All @@ -86,8 +86,10 @@ def submit(case, job=None, resubmit=False, no_batch=False, skip_pnl=False,
ts.set_status(SUBMIT_PHASE, TEST_PASS_STATUS)

try:
functor = lambda: _submit(case, job, resubmit, no_batch, skip_pnl,
mail_user, mail_type, batch_args)
functor = lambda: _submit(case, job=job, no_batch=no_batch, prereq=prereq,
resubmit=resubmit, skip_pnl=skip_pnl,
mail_user=mail_user, mail_type=mail_type,
batch_args=batch_args)
run_and_log_case_status(functor, "case.submit", caseroot=case.get_value("CASEROOT"))
except:
# If something failed in the batch system, make sure to mark
Expand Down

0 comments on commit d37f2a1

Please sign in to comment.