Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nexus: enable use of templates for job submission scripts #4344

Merged
merged 2 commits into from
Nov 30, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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