def parseAndRun(executable, configFile, runDir, args=None): # Build run dir name print "Parsing configuration...\nConfigFile: " + configFile + "\nRunDir: " + runDir configFileDir, configFileName = split(configFile) if runDir == "": runDir = join(configFileDir, "runs", dateDir) makedirsSilent(runDir) config = Config() config.readFile(configFile) if config.exists("runConfig.subConfigs"): print "This is a parallel config. Launching subconfigs..." for subConfigValue in config.children("runConfig.subConfigs"): subConfigFile = join(configFileDir, config.value(subConfigValue)[0]) subConfigFileDir, subConfigFileName = split(subConfigFile) subConfigRunDir = join(runDir, subConfigFileName).replace(".cfg", "") parseAndRun(executable, subConfigFile, subConfigRunDir, args) config.writeFile(join(runDir, configFileName)) else: print "This is a singular config. Launching it alone..." runConfigFile = join(runDir, configFileName) config.writeFile(runConfigFile) run(executable, runConfigFile, dateDir, runDir, args)
def selectConfig(configFilePath): if isdir(configFilePath): foundConfig = False for fileName in listdir(configFilePath): if fileName[-4:] == ".cfg": configFilePath = join(configFilePath, fileName) foundConfig = True break if not foundConfig: print "Could not find config..." raise FileIOException print "Loading config " + configFilePath + "\n" configFilePath = abspath(configFilePath) config = Config() config.readFile(configFilePath) symlinkNameConfig = "/tmp/latestconfig.cfg" print "Target: " + configFilePath print "Name: " + symlinkNameConfig createSymlink(configFilePath, symlinkNameConfig) saveFilePath, saveFileName = split(config.value("simulation.saveFileName")[0]) saveFilePath = expanduser(saveFilePath) symLinkNameSave = "/tmp/latestsavedir" print "Target: " + saveFilePath print "Name: " + symLinkNameSave createSymlink(saveFilePath, symLinkNameSave)
#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)
#!/usr/bin/env python import sys if len(sys.argv) != 2: raise SystemExit("Provide a path to the config file you wish to read") from pylibconfig import Config config = Config() try: config.readFile(sys.argv[1]) print "Config loaded" sys.exit(0) except Exception as e: print "Config failed to read :(" print e sys.exit(1)
from fys4460 import loadAtoms from glob import glob runDir = argv[1] saveDir = split(argv[1])[0] temperatureDirs = listdir(runDir) temperatureDirs.sort() saveFileNamesList = [] nFilenames = 0 for temperatureDir in temperatureDirs: if not isdir(join(runDir, temperatureDir)): continue print "Loading dir " + temperatureDir config = Config() configFileName = join(runDir, temperatureDir, "step1", "step1.cfg") print "Loading config " + configFileName config.readFile(configFileName) saveFileNames = config.value("simulation.saveFileName")[0] saveFileNames = expanduser(saveFileNames) saveFileNames = glob(saveFileNames) saveFileNames.sort() saveFileNamesSelection = saveFileNames[300:399] saveFileNamesList.append(saveFileNamesSelection) nFilenames += len(saveFileNamesSelection) pressures = zeros(nFilenames) temperatures = zeros(nFilenames) pressuresAverage = zeros(len(saveFileNamesList))
@author: svenni """ #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 = "1k-temperature/default.cfg" defaultConfigDir, defaultConfigFileName = split(defaultConfigFilePath) systemSizes = [6, 7, 8, 9, 10, 11, 12] config = Config() config.addGroup("", "runConfig") config.addList("runConfig", "subConfigs") iRun = 0 for systemSize in systemSizes: runName = "systemsize%04d" % systemSize subConfigFileName = join(runName, runName + ".cfg") subConfigFilePath = join(defaultConfigDir, subConfigFileName) print split(subConfigFilePath)[0] makedirsSilent(split(subConfigFilePath)[0]) subConfig = Config() subConfig.readFile(defaultConfigFilePath) subConfig.setValue("initialization.[0].nCells", systemSize) saveFileName = subConfig.value("simulation.saveFileName")[0] saveFileName = saveFileName.replace("$DATEDIR", "$DATEDIR/" + runName)
def test_greeting(self): config = Config() config.addString("", "test") config.addBool("test_bool", True) config.setValue("test", "value") self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) self.assert_(config.value("loose")[1] == False) self.assert_(config.value("test_bool")[0] == True) config.setValue("test_bool", False) config.writeFile("test.conf") self.assert_(os.path.exists("./test.conf") == True) config.readFile("test.conf") self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) os.remove("./test.conf")
def test_greeting ( self ): config = Config () config.addString ( "", "test" ) config.setValue ( "test", "value" ) config.addBoolean ( "", "test_bool") config.setValue ( "test_bool", True ) config.addInteger ( "", "test_int") config.setValue ( "test_int", 9 ) config.addInteger ( "", "test_unsigned_int") config.setValue ( "test_unsigned_int", -9 ) config.addFloat ( "", "test_float") config.setValue ( "test_float", 82.1002 ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) self.assert_ ( config.value ( "test_bool" )[0] == True ) self.assert_ ( config.value ( "loose" )[1] == False ) self.assert_ ( config.value ( "test_int" )[0] == 9 ) self.assert_ ( config.value ( "test_unsigned_int" )[0] == -9 ) self.assert_ ( fabs( config.value ( "test_float" )[0] - 82.1002) < 0.00001 ) config.setValue( "test_bool", False ) config.writeFile ( "test.conf" ) self.assert_ ( os.path.exists ( "./test.conf" ) == True ) config.readFile ( "test.conf" ) self.assert_ ( config.value ( "test" )[0] == "value" ) self.assert_ ( config.value ( "test" )[1] == True ) os.remove ( "./test.conf" )
def test_greeting(self): config = Config() config.addString("", "test") config.setValue("test", "value") config.addBoolean("", "test_bool") config.setValue("test_bool", True) config.addInteger("", "test_int") config.setValue("test_int", 9) config.addInteger("", "test_unsigned_int") config.setValue("test_unsigned_int", -9) config.addFloat("", "test_float") config.setValue("test_float", 82.1002) self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) self.assert_(config.value("test_bool")[0] == True) self.assert_(config.value("loose")[1] == False) self.assert_(config.value("test_int")[0] == 9) self.assert_(config.value("test_unsigned_int")[0] == -9) self.assert_(fabs(config.value("test_float")[0] - 82.1002) < 0.00001) config.setValue("test_bool", False) config.writeFile("test.conf") self.assert_(os.path.exists("./test.conf") == True) config.readFile("test.conf") self.assert_(config.value("test")[0] == "value") self.assert_(config.value("test")[1] == True) os.remove("./test.conf")
""" path = "/home/henrik/NumericalData/FYS4460/2048_diffusion3/" names = ["mdsim0002", "mdsim0005"]#, "mdsim0008"]#, "mdsim0011", "mdsim0014", "mdsim0017", "mdsim0020", "mdsim0023"]#, "mdsim0005"] """ # Long diffusion run path = "/home/henrik/NumericalData/FYS4460/2048_diffusion_long6/" names = ["mdsim0002", "mdsim0005"] fig1 = plt.figure(); fig1ax = plt.axes(); fig2 = plt.figure(); fig2ax = plt.axes(); legendstring = []; for name in names: infileVMD = open(path+name+"/out.xyz") infileData = open(path+name+"/measures.dat") config = Config() config.readFile(path+name+"/"+name+".cfg") temperature = config.value("system.temperature")[0] num_particles = int(infileVMD.readline()); print "Num particles = ", num_particles measures = infileData.readlines() vmd = infileVMD.readlines(); vmd = vmd[1:-1] n_t = int(len(measures)-1); t = np.zeros(n_t) for i in range(n_t): tmp = measures[i+1].split() t[i] = float(tmp[0]); print "Num timesteps = ", n_t particle_square_displacements = np.zeros((num_particles, n_t)) particle_initial_positions = np.zeros((num_particles, 3));
#!/usr/bin/env python import sys if len(sys.argv) != 2: raise SystemExit("Provide a path to the config file you wish to read") from pylibconfig import Config config = Config () try: config.readFile ( sys.argv[1] ) print "Config loaded" sys.exit(0) except Exception as e: print "Config failed to read :(" print e sys.exit(1)
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()
self.config.setValue("settings.sim_name", "mdsim%.4d" % self.counter) self.config.setValue("settings.output_path", self.path + self.config.value("settings.sim_name")[0] + "/"); os.makedirs(self.config.value("settings.output_path")[0]); self.config.writeFile(self.config.value("settings.output_path")[0] +"mdsim%.4d.cfg" % self.counter) self.counter += 1; def set_potential(self, p = 'lennard_jones'): if p == 'lennard_jones': self.config.setValue("system.potential", 0) else: print "No support for potential different from Lennard jones ('lennard_jones')" inPath = "/home/henrik/Dropbox/Henrik/Emner/FYS4460/project1/config/" outPath = "/home/henrik/NumericalData/FYS4460/2048_diffusion_long6/" config = Config() config.readFile(inPath+"std_cfg.cfg") cp = ConfigPusher(config, outPath) for temp in np.linspace(3.0, 10.0, 4): cp.initialize(nfcc=8, T=0.5, temperature = temp*2*3, v_dist = 0) cp.thermalize(T = 2, temperature=temp, tau = 10.0) cp.release(T=6.0) """ cp.initialize(nfcc = 8, T=0.5, temperature = 5.0, v_dist = 0) for temp in [5.0, 4.5, 4.0, 3.5, 3.0, 3.5, 3.0, 2.5, 2.0, 1.5, 1.0, 0.5, 0.25, 0.125, 0.05, 0.01, 0.0]: cp.thermalize(temperature=temp, tau = 10.0) cp.release()
from pylibconfig import Config import numpy as np import matplotlib.pyplot as plt import sys def minimumDistance(r1, r2, L): r_diff = r1-r2; for i in xrange(3): r_diff[i] = min(abs(r_diff[i]), L-abs(r_diff[i])) return np.sqrt(np.dot(r_diff, r_diff)) path = "/home/henrik/NumericalData/FYS4460/2048_longrun/" name = "mdsim0007" infile_vmd = open(path+name +"/" +"out.xyz") config = Config() config.readFile(path+name+"/"+name+".cfg") L = config.value("system.initialization.state.L")[0] V = L**3; num_particles = config.value("system.initialization.state.num_particles")[0] #num_particles = 10 particle_positions = [] n_bins = 1000; dr = L/(2*n_bins-1); distance_densities = np.zeros(n_bins) distances = np.linspace(dr, L/2+dr, n_bins) cut1 = 2 cut2 = num_particles+2