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

Updating to Python 3 #4

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 20 additions & 21 deletions mcgeneration/configure_gridpack.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import os
import subprocess
import shutil
import itertools
import random
import time

Expand Down Expand Up @@ -142,7 +141,7 @@
def cmsconnect_chain_submit(gridpack,dofs,proc_list,tag_postfix,rwgt_pts,runs,stype,scan_files=[],proc_run_wl={},attempt_resubmit=False):
#NOTE: The proc_run_wl is only use for SLINSPACE mode
if runs == 0:
print "ERROR: For Batch jobs, need to specify at least 1 run!"
print("ERROR: For Batch jobs, need to specify at least 1 run!")
return

tracker = JobTracker(fdir=os.getcwd())
Expand All @@ -163,7 +162,7 @@ def cmsconnect_chain_submit(gridpack,dofs,proc_list,tag_postfix,rwgt_pts,runs,st
tracker.update()
tracker.showJobs(wl=[JobTracker.CODEGEN,JobTracker.INTEGRATE])
tracker.checkProgress()
print ""
print("")
max_submits = min(
max_gen - len(tracker.codegen),
max_int - len(tracker.intg_filter),
Expand Down Expand Up @@ -263,16 +262,16 @@ def cmsconnect_chain_submit(gridpack,dofs,proc_list,tag_postfix,rwgt_pts,runs,st
)
if submitted >= max_submits:
break
print ""
print("")
if not submitted and len(tracker.running) == 0:
# Nothing left to submit and all jobs have finished running
# Note: A kill command sent to the parent still wont kill the children processes
done = True
else:
time.sleep(delay)
print "Done submitting jobs!"
print "IMPORTANT: Make sure to check the condor_q for any held jobs!"
#print "IMPORTANT: There could still be (soon to be orphaned) running jobs, make sure to check that they complete properly!"
print("Done submitting jobs!")
print("IMPORTANT: Make sure to check the condor_q for any held jobs!")
#print("IMPORTANT: There could still be (soon to be orphaned) running jobs, make sure to check that they complete properly!")

# Creates 1-D gridpacks at multiple linspaced starting points for each WC specified
def submit_1dim_jobs(gp,dofs,npts,runs,tag_postfix='',max_submits=-1,run_wl={}):
Expand Down Expand Up @@ -308,12 +307,12 @@ def submit_1dim_jobs(gp,dofs,npts,runs,tag_postfix='',max_submits=-1,run_wl={}):
)
if not gp.exists():
gp.setup()
print gp.baseSettings(),
print(gp.baseSettings())
submitted += gp.submit()
time.sleep(delay)
print ""
print("")
else:
print "Skipping gridpack: %s" % (gp.getSetupString())
print("Skipping gridpack: %s" % (gp.getSetupString()))
if max_submits > 0 and submitted >= max_submits:
return submitted
return submitted
Expand All @@ -330,7 +329,7 @@ def submit_ndim_jobs(gp,dofs,npts,runs,tag,start_pts=[],max_submits=-1):
dof.setLimits(0,None,None)
pt = {}
if idx < len(start_pts):
for k,v in start_pts[idx].iteritems(): pt[k] = v
for k,v in start_pts[idx].items(): pt[k] = v
gp.configure(
tag=tag,
run=idx,
Expand All @@ -340,12 +339,12 @@ def submit_ndim_jobs(gp,dofs,npts,runs,tag,start_pts=[],max_submits=-1):
)
if not gp.exists():
gp.setup()
print gp.baseSettings(),
print(gp.baseSettings())
submitted += gp.submit()
time.sleep(delay)
print ""
print("")
else:
print "Skipping gridpack: %s" % (gp.getSetupString())
print("Skipping gridpack: %s" % (gp.getSetupString()))
if max_submits > 0 and submitted >= max_submits:
return submitted
return submitted
Expand All @@ -366,12 +365,12 @@ def submit_scanfile_jobs(gp,dofs,tag,scan_files,max_submits=-1):
)
if not gp.exists():
gp.setup()
print gp.baseSettings(),
print(gp.baseSettings())
submitted += gp.submit()
time.sleep(delay)
print ""
print("")
else:
print "Skipping gridpack: %s" % (gp.getSetupString())
print("Skipping gridpack: %s" % (gp.getSetupString()))
if max_submits > 0 and submitted >= max_submits:
return submitted
return submitted
Expand Down Expand Up @@ -535,12 +534,12 @@ def main():
gridpack.configure(tag=tag,run=0,dofs=dof_list,num_pts=npts,start_pt=start_pt)
if not gridpack.exists():
gridpack.setup()
print gridpack.baseSettings(),
print(gridpack.baseSettings())
submitted += gridpack.submit()
print ""
print("")
else:
print "Skipping gridpack: %s" % (gridpack.getSetupString())
print("Skipping gridpack: %s" % (gridpack.getSetupString()))

if __name__ == "__main__":
main()
print "\nFinished!"
print("\nFinished!")
26 changes: 13 additions & 13 deletions mcgeneration/helpers/CardEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
import re

from helper_tools import run_process
from helpers.helper_tools import run_process

class BaseCard(object):
def __init__(self,card_dir,card_name):
Expand Down Expand Up @@ -47,12 +47,12 @@ def copy(self,dst,force=False):
s = "{src} and {dst} refer to the same file!".format(src=src,dst=dst)
raise RuntimeError(s)
if force:
print "Removing existing file {dst}...".format(dst=dst)
print("Removing existing file {dst}...".format(dst=dst))
os.remove(dst)
else:
s = "{file} already exists!".format(file=dst)
raise RuntimeError(s)
print "Copying to {dst}...".format(dst=dst)
print("Copying to {dst}...".format(dst=dst))
shutil.copyfile(src,dst)

def getFilePath(self):
Expand All @@ -66,7 +66,7 @@ def hasOption(self,k):
Checks if the option exists or not
k: The name of the option as it appears in the card
"""
return self.__ops.has_key(k)
return k in self.__ops

def setOption(self,k,v):
"""
Expand Down Expand Up @@ -98,7 +98,7 @@ def dump(self):
"""
for k in self.list():
v = self.__ops[k]
print "{0:>{w1}} = {1:<{w2}}".format(k,v,w1=self.key_width,w2=self.val_width)
print("{0:>{w1}} = {1:<{w2}}".format(k,v,w1=self.key_width,w2=self.val_width))

def parse(self):
"""
Expand Down Expand Up @@ -154,12 +154,12 @@ def dump(self):
w2=self.val_width,
w3=self.line_width
)
print h
print "-"*(len(h))
print(h)
print("-"*(len(h)))
for k in self.list():
v = self.getOption(k)
l = self.__line_map[k]
print "{0:>{w1}} = {1:<{w2}} -- {2}".format(k,v,l,w1=self.key_width,w2=self.val_width)
print("{0:>{w1}} = {1:<{w2}} -- {2}".format(k,v,l,w1=self.key_width,w2=self.val_width))

def save(self,dst,force=False):
self.copy(dst,force=force)
Expand All @@ -179,7 +179,7 @@ def save(self,dst,force=False):
old = old.replace('\\','\\\\').replace('*','\\*')
new = new.replace('\\','\\\\').replace('*','\\*')

#print "{old:<{w}} --> {new}".format(old=old,new=new,w=self.line_width)
#print("{old:<{w}} --> {new}".format(old=old,new=new,w=self.line_width))

sed_cmd = "s|{old}|{new}|g".format(old=old,new=new)
run_process(['sed','-i','-e',sed_cmd,dst])
Expand Down Expand Up @@ -209,7 +209,7 @@ def setOption(self,l):
def dump(self):
for k in self.list():
v = self.getOption(k)
print "[{0:>{w1}}] {1:<{w2}}".format(k,v,w1=self.key_width,w2=self.val_width)
print("[{0:>{w1}}] {1:<{w2}}".format(k,v,w1=self.key_width,w2=self.val_width))

def save(self,dst,force=False,indent=0):
indent_str = " "*4*indent
Expand All @@ -218,12 +218,12 @@ def save(self,dst,force=False,indent=0):
s = "{ind}{dst} is not a file!".format(dst=dst,ind=indent_str)
raise RuntimeError(s)
if force:
print "{ind}Removing {dst}...".format(dst=dst,ind=indent_str)
print("{ind}Removing {dst}...".format(dst=dst,ind=indent_str))
os.remove(dst)
else:
s = "{ind}{file} already exists!".format(file=dst,ind=indent_str)
raise RuntimeError(s)
print "{ind}Saving to {dst}...".format(dst=dst,ind=indent_str)
print("{ind}Saving to {dst}...".format(dst=dst,ind=indent_str))
with open(dst,'w') as f:
for k in self.list():
v = self.getOption(k)
Expand Down Expand Up @@ -261,4 +261,4 @@ def test_customize_card():

if __name__ == "__main__":
test_run_card()
test_customize_card()
test_customize_card()
6 changes: 3 additions & 3 deletions mcgeneration/helpers/DegreeOfFreedom.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def getName(self):
return self.name

def getCoefficients(self):
return self.relations.keys()
return list(self.relations.keys())

def getStart(self):
return self.limits[0]
Expand All @@ -37,7 +37,7 @@ def popCoefficient(self,wc_name):

def eval(self,x):
output = {}
for wc,scale in self.relations.iteritems():
for wc,scale in self.relations.items():
if x*scale == 0.0:
output[wc] = 0.0
else:
Expand All @@ -46,7 +46,7 @@ def eval(self,x):

def getCouplingString(self):
s = "FCNC=0 DIM6^2==1"
for k in self.relations.keys():
for k in list(self.relations.keys()):
s += " DIM6_%s^2==1" % (k)
return s

Expand Down
Loading