Permalink
Browse files

Commit before work on evolver

  • Loading branch information...
dragly committed May 15, 2012
1 parent e5f17fc commit fdca84f44aae536677bea74caccfa68fbb121241
View
@@ -0,0 +1,109 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+import subprocess
+import dircache
+import inspect, os
+import ConfigParser
+from sys import argv
+
+class bcolors:
+ HEADER = '\033[95m'
+ OKBLUE = '\033[94m'
+ OKGREEN = '\033[92m'
+ WARNING = '\033[93m'
+ FAIL = '\033[91m'
+ ENDC = '\033[0m'
+
+autoMode = argv[1]
+runLocal = False
+
+currentDirectory = os.path.split(os.path.abspath(__file__))[0]
+if len(argv) > 2:
+ runLocal = argv[2]
+
+servers = "multimeter laser geigerteller motstand signalgenerator likning kondensator spole kretskort hartreefock gran finite".split(" ")
+files = dircache.listdir("runs")
+i = 0
+
+if autoMode == "kill":
+ for server in servers:
+ print "Calling: ssh " + server + ".uio.no 'killall vmc'"
+ subprocess.call("ssh " + server + ".uio.no 'killall vmc'", shell=True)
+elif autoMode == "status":
+ for server in servers:
+ print server + ":"
+ nProcs = subprocess.check_output("ssh " + server + ".uio.no 'ps aux | grep generator.py | wc -l'", shell=True)
+ if(int(nProcs) > 2):
+ print bcolors.OKGREEN + "Running " + nProcs.replace("\n","") + bcolors.ENDC
+ users = subprocess.check_output("ssh " + server + ".uio.no 'users'", shell=True)
+ if users != "":
+ print bcolors.WARNING + users.replace("\n","") + bcolors.ENDC
+elif autoMode == "run":
+ for afile in files:
+ print "Found job in " + afile
+ configName = afile
+
+ myDir = "runs/" + configName + "/"
+
+ config = ConfigParser.ConfigParser()
+ configFileName = myDir + "config.ini"
+ config.read(configFileName)
+ mode = config.get("General", "mode")
+ fileop = open(configFileName)
+ configData = fileop.read()
+
+ prevConfigFile = myDir + "config.ini.prevrun"
+ prevConfigData = ""
+ if os.path.exists(prevConfigFile):
+ prevConfigFileOp = open(prevConfigFile)
+ prevConfigData = prevConfigFileOp.read()
+
+ if prevConfigData == configData:
+ print bcolors.WARNING + "Config is the same. No need to run again." + bcolors.ENDC
+ elif os.path.exists(myDir + "lock"):
+ lockFileOp = open(myDir + "lock")
+ lockHost = lockFileOp.read()
+ lockFileOp.close()
+ print bcolors.WARNING + "Run is already locked by process on host " + lockHost + bcolors.ENDC
+ else:
+ runCommand = "python generator.py " + configName
+ serverOccupied = True
+ while(serverOccupied):
+ nProcs = subprocess.check_output("ssh " + servers[i] + ".uio.no 'ps aux | grep generator.py | wc -l'", shell=True)
+ if(int(nProcs) < 3):
+ serverOccupied = False
+ else:
+ print bcolors.WARNING + "Server " + servers[i] + " already in use. Choosing next." + bcolors.ENDC
+ i += 1
+ if i >= len(servers):
+ print "All servers occupied. Exiting!"
+ exit(0)
+ break;
+ if runLocal:
+ print "Running " + configName + " locally"
+ subprocess.call(runCommand, shell=True)
+ else:
+ print bcolors.OKGREEN + "Launching job for config " + configName + " on " + servers[i] + bcolors.ENDC
+ subprocess.Popen("ssh " + servers[i] + ".uio.no 'cd "+ currentDirectory + " && " + runCommand + " &> output-" + configName + " && echo " + servers[i] + " done'", shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
+ i += 1
+elif autoMode == "plot":
+ minimizerList = ""
+ densityList = ""
+ for afile in files:
+ configName = afile
+ myDir = "runs/" + configName + "/"
+ config = ConfigParser.ConfigParser()
+ configFileName = myDir + "config.ini"
+ config.read(configFileName)
+ mode = config.get("General", "mode")
+ if mode == "minimizer":
+ minimizerList += myDir + " "
+ elif mode == "density":
+ densityList += myDir + " "
+ else:
+ print "Unknown mode"
+
+ subprocess.call("python minimizerplot.py " + minimizerList, shell=True)
+ subprocess.call("python densityplot.py " + densityList, shell=True)
+ print "You may watch the output from the servers in the output-* files."
+print "Automator finished."
View
@@ -0,0 +1,33 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+from sys import argv
+import inspect, os
+import time
+import ConfigParser
+import subprocess
+
+configName = argv[1]
+
+myDir = "runs/" + configName + "/"
+
+lockFile = open(myDir + "lock","w+")
+lockFile.write(os.uname()[1])
+lockFile.close()
+
+config = ConfigParser.ConfigParser()
+config.readfp(open('runs/' + configName + "/config.ini"))
+mode = config.get("General", "mode")
+nCycles = config.getint("MinimizerStandard", "nCycles")
+if not os.path.exists(myDir):
+ os.makedirs(myDir)
+print "Run started by " + os.uname()[1] + " at " + str(time.time()) + " with " + str(nCycles) + " cycles\n"
+subprocess.call("echo I am $HOSTNAME", shell=True)
+commandPrefix = ""
+if mode == "minimizer" or mode == "density":
+ commandPrefix = "'mpirun -n 4'"
+subprocess.call("./buildandrun.sh " + configName + " " + commandPrefix, shell=True)
+
+# this script is not included, but basically just calls a command that sends me an e-mail when the job is done. May be commented out
+#subprocess.call("./sendmail.script", shell=True)
+os.remove(myDir + "lock")
+print "Done " + time.strftime("%Y-%m-%d %H:%M:%S")
View
@@ -7,21 +7,61 @@
from numpy import *
from matplotlib import rc
from sys import argv
+first = True
-datapath = argv[1]
+for datapath in argv:
+ if first:
+ first = False
+ continue
-param0 = loadtxt(datapath + "/parameters0.dat")
-param1 = loadtxt(datapath + "/parameters1.dat")
-data = loadtxt(datapath + "/energies.dat")
+ param0 = loadtxt(datapath + "/parameters0.dat")
+ param1 = loadtxt(datapath + "/parameters1.dat")
+ data = loadtxt(datapath + "/energies.dat")
-surface = surf(param0, param1, data, warp_scale='auto')
-surface.actor.property.edge_visibility = True
+ fig = figure(size=(960,960))
-axes = axes(xlabel=r'$\alpha$', ylabel=r'$\beta$', zlabel=r'$E$')
-axes.title_text_property.italic = False
-axes.title_text_property.bold = False
-axes.title_text_property.font_family = 'times'
-axes.label_text_property.italic = False
-axes.label_text_property.bold = False
-axes.label_text_property.font_family = 'times'
-axes.axes.use_ranges = True
+ fig.scene.background = (1.0, 1.0, 1.0)
+ fig.scene.foreground = (0.0, 0.0, 0.0)
+
+ surface = surf(param0, param1, data, warp_scale='auto')
+ surface.actor.property.edge_visibility = True
+ surface.actor.property.lighting = False
+
+ myoutline = outline()
+
+ myaxes = axes(xlabel='a', ylabel='b', zlabel='E')
+ myaxes.title_text_property.italic = False
+ myaxes.title_text_property.bold = False
+ myaxes.title_text_property.font_family = 'times'
+ myaxes.label_text_property.italic = False
+ myaxes.label_text_property.bold = False
+ myaxes.label_text_property.font_family = 'times'
+ myaxes.axes.use_ranges = True
+ myaxes.axes.corner_offset = 0.02
+
+ # perspective view
+ fig.scene.camera.position = [21.583470159040861, -16.378051020433883, 10.231416057474506]
+ fig.scene.camera.focal_point = [5.3897238323904126, 5.434549130831372, -1.7158449313567394]
+ fig.scene.render()
+
+ savefig(datapath + "/minimizer.png")
+
+ # alpha view
+ fig.scene.x_plus_view()
+ savefig(datapath + "/minimizer-alpha.png")
+
+ # alpha view
+ fig.scene.x_plus_view()
+ fig.scene.parallel_projection = True
+ myaxes.axes.y_axis_visibility = False
+ myaxes.axes.z_axis_visibility = True
+ savefig(datapath + "/minimizer-alpha.png")
+
+ # beta view
+ fig.scene.y_plus_view()
+ fig.scene.camera.set_roll(180)
+ fig.scene.parallel_projection = True
+ myaxes.axes.x_axis_visibility = True
+ myaxes.axes.y_axis_visibility = True
+ myaxes.axes.z_axis_visibility = False
+ savefig(datapath + "/minimizer-beta.png")
View
@@ -28,7 +28,6 @@ Config::Config(int rank, int nProcesses) :
}
void Config::loadConfiguration(INIParser* settings) {
- std::cout << "CONFIGURATION LOADED" << std::endl << std::endl << std::endl;
m_nParticles = settings->GetInteger("General", "nParticles", m_nParticles);
m_nDimensions = settings->GetInteger("General", "nDimensions", m_nDimensions);
m_interactionEnabled = settings->GetBoolean("General", "interactionEnabled", m_interactionEnabled);
View
@@ -1,5 +1,5 @@
[General]
-mode=minimizer
+mode=density
nParticles=2
nDimensions=2
charge=1.0
@@ -8,7 +8,7 @@ omega=1.0
interactionEnabled=1
[MinimizerStandard]
-nCycles=500000
+nCycles=5000
nVariations=11
;alphaStart=0.89
;alphaEnd=0.94
View
@@ -79,7 +79,6 @@ void DensityPlotter::makePlot()
double **probability = 0;
double **myProbability = 0;
if(m_config->rank() == 0) {
- plotFile.open("plot.dat");
probability = (double**)matrix(aSteps, bSteps, sizeof(double));
}
StepConfig myStepConfig;
@@ -126,14 +125,21 @@ void DensityPlotter::makePlot()
}
if(m_config->rank() == 0) {
+ plotFile.open("density.dat");
+ params0File.open("params0.dat");
+ params1File.open("params1.dat");
for(int aStep = 0; aStep < aSteps; aStep++) {
for(int bStep = 0; bStep < bSteps; bStep++) {
plotFile << probability[aStep][bStep] << "\t";
- // printf("%.4f ", probability[aStep][bStep]);
+ params0File << aMin + aStep * da << "\t";
+ params1File << bMin + bStep * db << "\t";
}
plotFile << "\n";
- // printf("\n");
+ params0File << "\n";
+ params1File << "\n";
}
plotFile.close();
+ params0File.close();
+ params1File.close();
}
}
View
@@ -58,6 +58,8 @@ class DensityPlotter
int bSteps;
int m_nCycles;
ofstream plotFile;
+ ofstream params0File;
+ ofstream params1File;
};
#endif // DENSITYPLOTTER_H
View
@@ -0,0 +1 @@
+
View
@@ -42,41 +42,43 @@ MainApplication::MainApplication(int* argc, char*** argv) :
void MainApplication::loadConfiguration()
{
- std::cout << "Loading ini reader" << std::endl;
- m_settings = new INIParser("config.ini");
+ // Make sure the config is loaded by one processor at the time
+ for(int i = 0; i < m_nProcesses; i++) {
+ if(i == m_rank) {
+ std::cout << "Loading ini reader for rank " << m_rank << std::endl;
+ m_settings = new INIParser("config.ini");
- std::cout << "Checking for parse errors" << std::endl;
- if(!m_settings->Good()) {
- cerr << "Warning: " << __PRETTY_FUNCTION__ << ": Could not load configuration file 'config.ini'. Does it exist?" << endl;
- }
- std::cout << "Creating config object" << std::endl;
+ if(!m_settings->Good()) {
+ cerr << "Warning: " << __PRETTY_FUNCTION__ << ": Could not load configuration file 'config.ini'. Does it exist?" << endl;
+ }
- m_config = new Config(m_rank, m_nProcesses);
- m_config->loadConfiguration(m_settings);
+ m_config = new Config(m_rank, m_nProcesses);
+ m_config->loadConfiguration(m_settings);
- string modeString = m_settings->Get("General","mode","minimizer");
- if(modeString == "minimizer") {
- m_mode = MinimizerMode;
- } else if(modeString == "density") {
- m_mode = DensityMode;
- } else if(modeString == "blocking") {
- m_mode = BlockingMode;
- } else {
- cerr << __PRETTY_FUNCTION__ << ": Unknown mode '" << modeString << "'" << endl;
- exit(460);
- }
- if(m_rank == 0) {
- cout << __PRETTY_FUNCTION__ << ": Config loaded. Mode is " << modeString << "." << endl;
- cout << __PRETTY_FUNCTION__ << ": Running with " << m_nProcesses << " process(es)." << endl;
- flush(cout);
+ string modeString = m_settings->Get("General","mode","minimizer");
+ if(modeString == "minimizer") {
+ m_mode = MinimizerMode;
+ } else if(modeString == "density") {
+ m_mode = DensityMode;
+ } else if(modeString == "blocking") {
+ m_mode = BlockingMode;
+ } else {
+ cerr << __PRETTY_FUNCTION__ << ": Unknown mode '" << modeString << "'" << endl;
+ exit(460);
+ }
+ if(m_rank == 0) {
+ cout << __PRETTY_FUNCTION__ << ": Config loaded. Mode is " << modeString << "." << endl;
+ cout << __PRETTY_FUNCTION__ << ": Running with " << m_nProcesses << " process(es)." << endl;
+ flush(cout);
+ }
+ }
+ MPI_Barrier(MPI_COMM_WORLD);
}
}
void MainApplication::runConfiguration()
{
- std::cout << "Loading config" << std::endl;
loadConfiguration();
- std::cout << "Config loaded" << std::endl;
if(m_mode == MinimizerMode) {
runMinimizer();
} else if(m_mode== DensityMode) {
@@ -113,8 +115,5 @@ void MainApplication::runDensity()
}
void MainApplication::finalize() {
-#ifdef USE_MPI
- // End MPI
MPI_Finalize ();
-#endif
}
@@ -13,7 +13,6 @@ using namespace arma;
general as possible with regards to the problem and could hopefully
be used for a completely different problem.
*/
-
class MinimizerEvolutionary : Minimizer
{
public:
@@ -15,6 +15,9 @@ MonteCarloMetropolisHastings::MonteCarloMetropolisHastings(Config *config) :
// allocate matrices which contain the position of the particles
rOld = new vec2[ nParticles];
rNew = new vec2[ nParticles];
+
+ forceVectorNew = zeros<vec>(nParticles * nDimensions);
+ forceVectorOld = zeros<vec>(nParticles * nDimensions);
}
MonteCarloMetropolisHastings::~MonteCarloMetropolisHastings()
@@ -41,7 +44,7 @@ void MonteCarloMetropolisHastings::sample(int nCycles)
}
}
wave->initialize(rOld);
- wave->gradient(rOld, 0, waveGradientOld); // TODO add particle number
+// wave->gradient(rOld, 0, waveGradientOld); // TODO add particle number
quantumForce(rOld, forceVectorOld);
// loop over monte carlo cycles
for (int cycle = 1; cycle <= nCycles; cycle++){
Oops, something went wrong.

0 comments on commit fdca84f

Please sign in to comment.