#from runconfig import run from pylibconfig import Config from pylab import * from sys import argv from os.path import split, join from fys4460 import makedirsSilent defaultConfigFilePath = "1-equilibrated-fast-zoom/default-start.cfg" defaultEndConfigFilePath = "1-equilibrated-fast-zoom/default-end.cfg" defaultConfigDir, defaultConfigFileName = split(defaultConfigFilePath) defaultEndConfigDir, defaultEndConfigFileName = split(defaultEndConfigFilePath) temperatures = linspace(100, 600, 40) config = Config() config.addGroup("", "runConfig") config.addList("runConfig", "subConfigs") iRun = 0 for temperature in temperatures: runName = "temperature%04d" % iRun subConfigFileName = join(runName, "step0.cfg") subConfigEndFileName = join(runName, "step1.cfg") subConfigFilePath = join(defaultConfigDir, subConfigFileName) subConfigEndFilePath = join(defaultConfigDir, subConfigEndFileName) makedirsSilent(split(subConfigFilePath)[0]) subConfigStart = Config() subConfigStart.readFile(defaultConfigFilePath) oldSaveFile = subConfigStart.value("simulation.saveFileName")[0] newSaveFile = oldSaveFile.replace("$DATEDIR", "$DATEDIR/" + runName) subConfigStart.setValue("simulation.saveFileName", newSaveFile)
def run(executable, configFile, dateDir, runDir, args=None): executable = os.path.realpath(executable) temp,configFileName = os.path.split(configFile) configName = configFileName.replace(".cfg", "") config = Config() config.readFile(configFile) replaceDateDir(config, dateDir) if(config.exists("runInformation")): if args.force: config.remove("", "runInformation") else: print "Config cannot contain section runInformation already. It would be overwritten." raise Exception ### Git info ### # repo = Repo(".") # head = repo.heads[0] # commitSHA = getattr(head.commit, "id") commitSHA = "N/A" ### Run information ### config.addGroup("", "runInformation") addRunInformation(config, "hostname", socket.gethostname()) addRunInformation(config, "timestamp", datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) addRunInformation(config, "gitCommitSHA", commitSHA) addRunInformation(config, "dateDir", dateDir) addRunInformation(config, "runDir", runDir) addRunInformation(config, "configFile", configFile) config.writeFile(configFile) selectConfig(os.path.abspath(configFile)) # Input stuff to database # database = sqlite3.connect("test.db") # values = [executable, runDir] # insertID = database.execute("INSERT INTO run (executable, dir) VALUES (?, ?)", values) # printChildren(database, insertID.lastrowid, config, "") # database.commit() # database.close() # Create symlinks # createSymlink(os.getcwd() + "/" + runDir, "/tmp/latest") # saveFile = config.value("simulation.saveFileName")[0] # saveFile = expanduser(saveFile) # saveDir = os.path.dirname(saveFile) # createSymlink(saveDir, "/tmp/latestsavedir") runList = [] nProcesses = 1 if config.exists("mpi"): nProcesses = config.value("mpi.nProcesses")[0] runList = ["mpirun", "-n", str(nProcesses), "nice", "-n", "19", executable, configFileName] else: runList = ["nice", "-n", "19", executable, configFileName] logFilePath = join(runDir, "run_" + configFileName.replace(".cfg", "") + ".log") f = open(logFilePath, "w") print "RunList: " + str(runList) + "\nRunDir: " + runDir + "\nLogFile: " + logFilePath print "Starting..." # try: # progressProcessList = ["python", "progressreporter.py", configName + " " + runDir, join(runDir, "runprogress.txt")] # progressProcess = subprocess.Popen(progressProcessList) process = subprocess.Popen(runList, cwd=runDir, stdout=f, stderr=subprocess.STDOUT) process.wait() # print "Waiting for progressreporter to finish..." # progressProcess.wait() # except Exception: # process.kill() # f.close() f.close()