Skip to content

Commit

Permalink
Merge pull request #4344 from jtkrogel/nx_job_template
Browse files Browse the repository at this point in the history
Nexus: enable use of templates for job submission scripts
  • Loading branch information
ye-luo authored Nov 30, 2022
2 parents 6a1ac72 + 17b69e3 commit 44d4999
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions nexus/lib/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def write(self):
default_cpus_per_task = False, # optionally bypass typical nexus processing for supermucng
ntasks_per_core = None,
cpus_per_task = None,
template = None,
)

# these are not assigned directly
Expand Down Expand Up @@ -264,6 +265,11 @@ def __init__(self,**kwargs):
# assign fake job
self.fake_job = fake

# check template
if self.template is not None and not isinstance(self.template,str):
self.error('template must be a string\nReceived type: {}'.format(self.template.__class__.__name__))
#end if

# initialize other internal variables
self.app_options = Options()
self.run_options = Options()
Expand Down Expand Up @@ -331,6 +337,7 @@ def __init__(self,**kwargs):
#end if

self.normalize_time()

#end def __init__


Expand All @@ -340,6 +347,9 @@ def get_machine(self):


def process(self,machine=None):
if self.template is not None:
return
#end if
if machine is None:
machine = self.get_machine()
#end if
Expand All @@ -349,6 +359,9 @@ def process(self,machine=None):

# test needed
def process_options(self,machine=None):
if self.template is not None:
return
#end if
if machine is None:
machine = self.get_machine()
#end if
Expand Down Expand Up @@ -523,6 +536,9 @@ def reenter_queue(self):


def run_command(self,launcher=None,redirect=False,serial=False):
if self.template is not None:
return ''
#end if
machine = self.get_machine()
if launcher is None:
launcher = machine.app_launcher
Expand Down Expand Up @@ -853,7 +869,9 @@ def restore_default_settings(self):

def add_job(self,job):
if isinstance(job,Job):
self.process_job(job)
if job.template is None:
self.process_job(job)
#end if
self.write_job(job)
jid = job.internal_id
self.jobs[jid] = job
Expand Down Expand Up @@ -1803,17 +1821,21 @@ def setup_environment(self,job):

def write_job(self,job,file=False):
job.subfile = job.name+'.'+self.sub_launcher+'.in'
env = self.setup_environment(job)
command = job.run_command(self.app_launcher,serial=job.serial)
if job.template is None:
env = self.setup_environment(job)
command = job.run_command(self.app_launcher,serial=job.serial)

c = self.write_job_header(job)+'\n'
if len(job.presub)>0:
c+=job.presub+'\n'
#end if
c+=env
c+=command+'\n'
if len(job.postsub)>0:
c+=job.postsub+'\n'
c = self.write_job_header(job)+'\n'
if len(job.presub)>0:
c+=job.presub+'\n'
#end if
c+=env
c+=command+'\n'
if len(job.postsub)>0:
c+=job.postsub+'\n'
#end if
else:
c = job.template
#end if
if file:
filepath = os.path.join(job.directory,job.subfile)
Expand Down

0 comments on commit 44d4999

Please sign in to comment.