-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtempRangeSubmit.py
More file actions
131 lines (113 loc) · 4.63 KB
/
Copy pathtempRangeSubmit.py
File metadata and controls
131 lines (113 loc) · 4.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# =============================================================================
# Script for submitting multiple jobs over range of temperatures for Ising
# model in order to simulate phase transition.
#
# Author: Max Graves
# Last Revision: 21-MAR-2013
# =============================================================================
import subprocess, os, sys, argparse, glob
import pylab as pl
# =============================================================================
def parseCMD():
"""
parse the command line.
"""
desc= ('Ising 2D phase transition script. Submits jobs to '+
'generate data to plot macroscopic magnetization vs temp. '+
'This script will submit jobs over a range of temperatures '+
'and then move them to a new directory in ../data/"uniqueID"/ '+
'The companion script to this one will create the desired plot '+
'from the data generated.')
parser = argparse.ArgumentParser(description=desc)
parser.add_argument("-i", "--TMin", type=float,
default=1.0,
help="Minimum value of temperature")
parser.add_argument("-f", "--TMax", type=float,
default=5.0,
help="Maximum value of temperature")
parser.add_argument("-A", "--align", action="store_true",
dest="align", default=False,
help="Start all spins in the up state")
parser.add_argument("-E", "--evolve", action="store_true",
dest="evolve", default=False,
help="save images to disk of algorithm (for video)")
parser.add_argument("-e", "--step", type=float,
default=0.1,
help="increment to increase temp. each time")
parser.add_argument("-N", "--nodes", type=int,
default=15,
help="Number of Nodes in Network")
parser.add_argument("-J", "--Coupling", type=float,
default=1.0,
help="Coupling Constant, J")
parser.add_argument("-s", "--mcSweeps", type=int,
default=20000,
help="Number of MC sweeps to perform")
return parser.parse_args()
# =============================================================================
def findExe():
"""
checks for Ising model code
"""
if os.path.isfile('./netIsingDriver.py'):
print "Ising Driver was found"
pass
else:
print 'Could not find Ising Driver\n'
print 'Maybe you are in the wrong directory?'
print '...find the file and try again.'
sys.exit("quitting\n")
def checkDataDir():
"""
checks whether the ./data/ directory has .dat files.
Exits if it does.
"""
inDir = glob.glob('./data/*dat*')
if inDir != []:
print ' ===== ERROR ====='
print ' The ./data/ directory needs to have no .dat files.\n'
print ' It may contain subdirectories with .dat files,'
print ' but not within its top level. Move into ./data/'
print ' and move any .dat files into another directory.\n'
sys.exit()
# =============================================================================
def main():
# make sure PIGS.e exists where it should
findExe()
# check if the data directory has other data files
checkDataDir()
# parse cmd line
args = parseCMD()
# create array of number of imaginary time step
temps = pl.arange(args.TMin, (args.TMax+args.step), args.step)
# submit the executable the correct amount of times
for temp in temps:
command = ("python netIsingDriver.py"+" -J "+str(args.Coupling)+ " -s "+
str(args.mcSweeps)+" -N "+str(args.nodes)+ " -T "+
str(temp))
if args.align:
command += ' -A'
print command
subprocess.check_call(command, shell=True)
print "finished for temp: ",temp
print "Now moving files to new directory..."
# create /output/dwEnergy subdirectory if it doesn't exist
dirName = ('./data/T%s-%s_N%s_s%s/'%(args.TMin,args.TMax,
args.nodes, args.mcSweeps))
if not os.path.exists(dirName):
os.mkdir(dirName)
# move all files created into this new directory we just created
files = glob.glob("./data/*dat*")
curD = os.getcwd()
print curD
for f in files:
fN = f[7:]
#print dirName+str(f)
os.rename(f, (dirName+str(fN)))
outputStr = ("\nThe tempRangeAnalyze.py script existing in this "+
"directory will crunch all of this data into one numpy " +
"array and and plot.")
print outputStr
# =============================================================================
if __name__=='__main__':
main()