Page MenuHomec4science

launchRuns.py
No OneTemporary

File Metadata

Created
Wed, Oct 2, 17:26

launchRuns.py

#!/usr/bin/env python
import BlackDynamite as BD
import os, sys
import socket
from types import ModuleType
def main(argv = None):
if (type(argv) == str):
argv = argv.split()
parser = BD.BDParser()
parser.register_params(
group = "launchRuns.py",
params = {
"outpath": str,
"generator": ModuleType,
"nruns": int,
"state": str,
"machine_name": str },
defaults = {
"machine_name": socket.gethostname(),
"nruns": -1,
"generator": "bashCoat" })
parser.help.update({
"nruns":"Specify the number of runs to launch. This is useful when we want to launch only the first run from the stack.",
"generator":"Specify the launcher generator"
})
params = parser.parseBDParameters(argv = argv)
mybase = BD.Base(**params)
if (not "outpath" in params):
print ("A directory where to create temp files should be provided. use --outpath ")
sys.exit(-1)
mydir = os.path.join(params["outpath"], "BD-" + params["study"] + "-runs")
if not os.path.exists(mydir):
os.makedirs(mydir)
os.chdir(mydir)
run_constraints = []
job_constraints = []
runSelector = BD.RunSelector(mybase)
if ("run_constraints" in params):
run_constraints = params["run_constraints"]
def item_matcher(name, item):
return item.lower().lstrip().startswith(name)
if not any([item_matcher("state", item) for item in run_constraints]):
run_constraints.append("state = CREATED")
if not any([item_matcher("machine_name", item) for item in run_constraints]):
run_constraints.append("machine_name = {0}".format(params["machine_name"]))
run_list = runSelector.selectRuns(run_constraints,params)
if (params["nruns"] > 0):
run_list = [run_list[i] for i in range(0,min(params["nruns"],len(run_list)))]
if (len(run_list) == 0):
print "No runs to be launched"
for r,j in run_list:
print("Dealing with job {0.id}, run {1.id}".format(j,r))
r["run_path"] = os.path.join(mydir, "run-" + str(r.id))
j.update()
if not os.path.exists("run-" + str(r.id)):
os.makedirs("run-" + str(r.id))
os.chdir("run-" + str(r.id))
conffiles = r.getConfigFiles()
for conf in conffiles:
print ("create file " + conf["filename"])
f = open(conf["filename"], 'w')
f.write(conf["file"])
f.close()
print ("launch in '" + mydir + "/" + "run-" + str(r.id) + "/'")
mymod = params["generator"]
print (mymod)
mymod.launch(r,params)
os.chdir("../")
if (params["truerun"] == True):
mybase.commit()
if __name__ == '__main__':
main()

Event Timeline