Skip to content

Commit

Permalink
Automatic OS for condor submission
Browse files Browse the repository at this point in the history
  • Loading branch information
mseidel42 committed Feb 2, 2024
1 parent 4baed94 commit 7717403
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 21 deletions.
5 changes: 5 additions & 0 deletions bin/Powheg/dag_wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# cannot submit condor DAG from within CMSSW environment
eval `scram unsetenv -sh`
condor_submit_dag $1
36 changes: 20 additions & 16 deletions bin/Powheg/run_pwg_condor.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@


rootfolder = os.getcwd()

scram_arch = os.environ['SCRAM_ARCH']
scram_os = scram_arch.split('_')[0]
want_os = { # https://batchdocs.web.cern.ch/local/submit.html#os-selection-via-containers
'slc6': 'el7',
'slc7': 'el7',
'el8': 'el8',
'el9': 'el9',
}

def runCommand(command, printIt = False, doIt = 1) :
if args.fordag and 'condor_submit' in command:
Expand All @@ -42,11 +49,8 @@ def runCommand(command, printIt = False, doIt = 1) :

# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----

def prepareCondorScript( tag, i, folderName, queue, SCALE = '0', njobs = 0, runInBatchDir = False, slc6 = 0):
def prepareCondorScript( tag, i, folderName, queue, SCALE = '0', njobs = 0, runInBatchDir = False):
'''prepare the Condor submission script'''

if (slc6):
print('Preparing to run in slc6 using singularity')

filename = 'run_' + folderName + '_' + tag + '.condorConf'
execname = 'run_' + tag
Expand All @@ -58,7 +62,8 @@ def prepareCondorScript( tag, i, folderName, queue, SCALE = '0', njobs = 0, runI
f = open(filename, 'w')

if (i == 'multiple') :
if (slc6) :
if (scram_os == 'slc6') :
print('Preparing to run in slc6 using singularity')
f.write('executable = %s/slc6wrapper.sh \n' % rootfolder)
f.write('arguments = ' + execname + '_$(ProcId).sh \n')
else:
Expand All @@ -76,7 +81,7 @@ def prepareCondorScript( tag, i, folderName, queue, SCALE = '0', njobs = 0, runI
f.write('initialdir = ' + rootfolder + '/' + folderName + '\n')

f.write('+JobFlavour = "'+ queue +'" \n')

f.write('MY.WantOS = "%s" \n' % want_os[scram_os])
f.write('periodic_remove = JobStatus == 5 \n')
f.write('WhenToTransferOutput = ON_EXIT_OR_EVICT \n')
f.write('transfer_output_files = "" \n')
Expand Down Expand Up @@ -203,7 +208,7 @@ def runParallelXgrid(parstage, xgrid, folderName, nEvents, njobs, powInputName,

else:
print('Submitting to condor queues: \n')
condorfile = prepareCondorScript(jobtag, 'multiple', args.folderName, QUEUE, njobs=njobs, runInBatchDir=True, slc6=args.slc6)
condorfile = prepareCondorScript(jobtag, 'multiple', args.folderName, QUEUE, njobs=njobs, runInBatchDir=True)
runCommand ('condor_submit ' + condorfile)

# ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
Expand Down Expand Up @@ -393,7 +398,7 @@ def runEvents(parstage, folderName, EOSfolder, njobs, powInputName, jobtag, proc

else:
print('Submitting to condor queues: \n')
condorfile = prepareCondorScript(jobtag, 'multiple', args.folderName, QUEUE, njobs=njobs, runInBatchDir=True, slc6=args.slc6)
condorfile = prepareCondorScript(jobtag, 'multiple', args.folderName, QUEUE, njobs=njobs, runInBatchDir=True)
runCommand ('condor_submit ' + condorfile)


Expand Down Expand Up @@ -448,7 +453,7 @@ def runhnnlo(folderName, njobs, QUEUE):

print('Submitting to condor queues \n')
tagName = 'hnnlo_%s' % scale
condorfile = prepareCondorScript(tagName, 'hnnlo', folderName, QUEUE, njobs=njobs, runInBatchDir=scale, slc6=args.slc6)
condorfile = prepareCondorScript(tagName, 'hnnlo', folderName, QUEUE, njobs=njobs, runInBatchDir=scale)
runCommand ('condor_submit ' + condorfile)


Expand Down Expand Up @@ -477,7 +482,6 @@ def runhnnlo(folderName, njobs, QUEUE):
parser.add_argument('-k', '--keepTop' , dest="keepTop", default= '0', help='Keep the validation top draw plots [0]')
parser.add_argument('-d', '--noPdfCheck' , dest="noPdfCheck", default= '0', help='If 1, deactivate automatic PDF check [0]')
parser.add_argument('--fordag' , dest="fordag", default= 0, help='If 1, deactivate submission, expect condor DAG file to be created [0]')
parser.add_argument('--slc6' , dest="slc6", default= 0, help='If 1, use slc6 singularity [0]')
parser.add_argument('--svn' , dest="svnRev", default= 0, help='SVN revision. If 0, use tarball [0]')
parser.add_argument('--ion' , dest="ion", default= '', help='Ion type. Options: Pb []')

Expand All @@ -503,7 +507,7 @@ def runhnnlo(folderName, njobs, QUEUE):
print(' EOS folder (stages 4,7,8) : ' + args.eosFolder + '/' + EOSfolder)
print(' base folder : ' + rootfolder)
print(' forDAG : ' + str(args.fordag))
print(' SLC6 : ' + str(args.slc6))
print(' scram_arch (set from environment) : ' + scram_arch)
print(' SVN : ' + str(args.svnRev))
print()

Expand Down Expand Up @@ -658,7 +662,7 @@ def runhnnlo(folderName, njobs, QUEUE):

else:
print('Submitting to condor queues \n')
condorfile = prepareCondorScript(tagName, '', '.', QUEUE, njobs=1, slc6=args.slc6)
condorfile = prepareCondorScript(tagName, '', '.', QUEUE, njobs=1)
runCommand ('condor_submit ' + condorfile)

elif args.parstage == '1' :
Expand Down Expand Up @@ -686,7 +690,7 @@ def runhnnlo(folderName, njobs, QUEUE):

else:
print('Submitting to condor queues \n')
condorfile = prepareCondorScript(tagName, '', args.folderName, QUEUE, njobs=1, runInBatchDir=True, slc6=args.slc6)
condorfile = prepareCondorScript(tagName, '', args.folderName, QUEUE, njobs=1, runInBatchDir=True)
runCommand ('condor_submit ' + condorfile)

elif args.parstage == '0123' or args.parstage == 'a' : # compile & run
Expand All @@ -709,7 +713,7 @@ def runhnnlo(folderName, njobs, QUEUE):
scriptName.split('.sh')[0]+'.log &')
else:
print('Submitting to condor queues \n')
condorfile = prepareCondorScript(tagName, '', '.', QUEUE, njobs=1, runInBatchDir=True, slc6=args.slc6)
condorfile = prepareCondorScript(tagName, '', '.', QUEUE, njobs=1, runInBatchDir=True)
runCommand ('condor_submit ' + condorfile)

elif args.parstage == '01239' or args.parstage == 'f' : # full single grid in oneshot
Expand All @@ -733,7 +737,7 @@ def runhnnlo(folderName, njobs, QUEUE):
scriptName.split('.sh')[0]+'.log')
else:
print('Submitting to condor queues \n')
condorfile = prepareCondorScript(tagName, '', '.', QUEUE, njobs=1, runInBatchDir=True, slc6=args.slc6)
condorfile = prepareCondorScript(tagName, '', '.', QUEUE, njobs=1, runInBatchDir=True)
runCommand ('condor_submit ' + condorfile)

elif args.parstage == '7' :
Expand Down
6 changes: 1 addition & 5 deletions bin/Powheg/run_pwg_parallel_condor.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def flush(self):
parser.add_argument('-m', '--prcName' , dest="prcName", default= 'DMGG', help='POWHEG process name [DMGG]')
parser.add_argument( '--step3pilot' , dest="step3pilot", default= False, help='do a pilot job to combine the grids, calculate upper bounds afterwards (otherwise afs jobs might fail)', action='store_true')
parser.add_argument( '--dry-run' , dest="dryrun", default= False, help='show commands only, do not submit', action='store_true')
parser.add_argument( '--slc' , dest="slc", default='7', help='If 6, run in slc6 using singularity')
parser.add_argument( '--svn' , dest="svnRev", default= 0, help='SVN revision. If 0, use tarball [0]')

args = parser.parse_args ()
Expand All @@ -63,7 +62,6 @@ def flush(self):
print(' powheg process name = ' + args.prcName)
print(' do step 3 pilot run = ' + str(args.step3pilot))
print(' dry run = ' + str(args.dryrun))
print(' SLC = ' + str(args.slc))
print(' SVN = ' + str(args.svnRev))
print()

Expand Down Expand Up @@ -103,8 +101,6 @@ def flush(self):

commonOpts='-i '+args.inputTemplate+' -m '+args.prcName+' -f '+args.folderName+' -j '+njobs+' --fordag 1'
commonOpts+=' --svn %i' % args.svnRev
if args.slc == '6':
commonOpts+=' --slc6 1 '
if args.eosFolder != 'NONE':
commonOpts+=' -e '+args.eosFolder
if extraOpt!='-p 0' and extraOpt!='-p 9 -k 1':
Expand Down Expand Up @@ -138,7 +134,7 @@ def flush(self):
dagfile.write('\n')
dagfile.close()

command = 'condor_submit_dag %s'%(dagfilename)
command = 'sh dag_wrapper.sh %s'%(dagfilename)
print(command)
if not args.dryrun:
command_out = subprocess.getstatusoutput(command)[1]
Expand Down

0 comments on commit 7717403

Please sign in to comment.