forked from mdipierro/qcdutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcdutils_run.py
176 lines (159 loc) · 6.63 KB
/
qcdutils_run.py
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
# create by: Massimo Di Pierro<[email protected]>
# license: GPL2.0
import sys, os, re, urllib
FERMIQCD = 'http://fermiqcd.googlecode.com/hg/Libraries/'
GROUP = '[email protected]'
USAGE = """
qcdutils_run.py is a tool to help you download and use fermiqcd from
http://code.google.com/p/fermiqcd
When you run:
python qcdutils_run.py [args]
It will:
- create a folder called fermiqcd/ in the current working directory
- connect to google code and download fermiqcd.cpp + required libraries
- if -mpi in [args] compile fermiqcd with mpiCC else with g++
- if -mpi in [args] run fermiqcd.exe with mpiCC else run it normally
- pass the [args] to the compiled fermiqcd.exe
Some [args] are handled by qcdutils_run.py:
-download force downloading of the libraries
-compile force recompiling of code
-source runs and compiles a different source file
-mpi=2 for use with mpi (mpiCC and mpirun but be installed)
Other [args] are handled by fermiqcd.cpp for example
-cold make a cold gauge configuration
-load load a gauge configuration
-quark make a quark
-pion make a pion
(run it with no options for a longer list of options)
You can find the source code in fermiqcd/fermiqcd.cpp
More examples:
qcdutils_run.py -gauge:start=cold:nt=16:nx=4
qcdutils_run.py -gauge:start=hot:nt=16:nx=4
qcdutils_run.py -gauge:load=cold.mdp
qcdutils_run.py -gauge:load=cold.mdp:steps=10:beta=5.7
qcdutils_run.py -gauge:load=*.mdp -plaquette
qcdutils_run.py -gauge:load=*.mdp -plaquette-vtk
qcdutils_run.py -gauge:load=*.mdp -polyakov-vtk
qcdutils_run.py -gauge:load=*.mdp -cool:steps=20 -topcharge-vtk
qcdutils_run.py -gauge:load=*.mdp -quark:kappa=0.12:alg=minres-vtk
qcdutils_run.py -gauge:load=*.mdp -quark:kappa=0.12 -pion
qcdutils_run.py -gauge:load=*.mdp -quark:kappa=0.12 -pion-vtk
"""
def get_options_base(path):
path = os.path.join(os.path.split(path)[0],"fermiqcd.cpp")
if not os.path.exists(path): return
data=open(path,"r").read()
d = {}
regex = re.compile('arguments\.have\("(.*?)"\)')
for option in regex.findall(data):
d[option]=d.get(option,{})
regex = re.compile('arguments\.get\("(.*?)",\s*"(.*?)",\s*"?([^\"\)]*?)"?\)')
for option, attribute, values in regex.findall(data):
new_values = values.split('|')
attributes = d[option] = d.get(option,{})
values = attributes[attribute] = attributes.get(attribute,[])
for value in new_values:
if value and not value in values:
values.append(value)
return d
def get_options(path):
options = get_options_base(path)
print 'Options:'
for key in sorted(options): #['-gauge','-quark']+[a for a in sorted(options) if not a in ('-gauge','-quark')]:
print ' %s' % key
for attribute in sorted(options[key]):
values = options[key][attribute]
if values: values[0] = values[0]+' (default)'
print ' %s = %s' % (attribute,' or '.join(values))
def get_fermiqcd(path,download=False,compile=False,mpi=False,
source='fermiqcd/fermiqcd.cpp'):
path = os.path.join(path,os.path.dirname(source))
filename = os.path.basename(source).split('.')[0]
if mpi:
exe = os.path.join(path,'%s-mpi.exe' % filename)
else:
exe = os.path.join(path,'%s.exe' % filename)
if download or not os.path.exists(path):
if not os.path.exists(path):
os.mkdir(path)
print 'downloading %s' % FERMIQCD
u = urllib.urlopen(FERMIQCD).read()
for f in re.compile('\"(\w+\.\w+)\"').findall(u):
print 'downloading %s' % (FERMIQCD+f)
data = urllib.urlopen(FERMIQCD+f).read()
open(os.path.join(path,f),'wb').write(data)
if not os.path.exists(exe):
compile = True
if compile:
dir = os.getcwd()
os.chdir(path)
if mpi:
if os.system('mpiCC')!=256:
print 'mpiCC command not found on your system'
sys.exit(1)
command = 'mpiCC -lmpi -DPARALLEL -O3 -o %s-mpi.exe %s.cpp' % (filename,filename)
else:
if os.system('g++')!=256:
print 'g++ command not found on your system'
sys.exit(1)
command = 'g++ -O3 -o %s.exe %s.cpp' % (filename, filename)
print 'compiling....'
print command
if os.system(command):
print 'there were compilation errors'
print 'please ask for advice at %s' % GROUP
sys.exit(1)
os.chdir(dir)
return exe
def get_options_form(path):
options = get_options_base(path)
fields = []
for key in sorted(options):
k = key[1:].replace('-','_')
fields.append("Field('%s','boolean',default=False')" % k)
for attribute in sorted(options[key]):
values = options[key][attribute]
d = values and values[0] or ''
try:
t = 'string'
float(values[0])
t = 'double' if '.' in values[0] else 'integer'
except: pass
if len(values)>1:
v = repr(values)
fields.append("Field('%s_%s','%s',default='%s',requires=IS_IN_SET(%s))" % \
(k,attribute,t,d,v))
else:
fields.append("Field('%s_%s','%s',default='%s')" % \
(k,attribute,t,d))
return 'form = SQLFORM.factory('+',\n '.join(fields)+')'
def main():
ignore = ['-download','-compile','-mpi','-source','-h']
if '-h' in sys.argv:
print USAGE
get_options('fermiqcd/')
elif '-H' in sys.argv:
print get_options_form('fermiqcd/')
else:
source = ([x[8:] for x in sys.argv if x.startswith('-source:')]+['fermiqcd/fermiqcd'])[0]
path = get_fermiqcd(os.getcwd(),
download='-download' in sys.argv,
compile='-compile' in sys.argv,
mpi='-mpi' in sys.argv,
source=source)
if '-options' in sys.argv:
get_options(path)
else:
args = ' '.join(x for x in sys.argv[1:] if not x in ignore)
mpis = [x for x in sys.argv[1:] if x.startswith('-mpi')]
if mpis:
p = int(mpis[0][5:])
command = 'mpirun -n %s %s %s' % (p, path,args)
else:
command = '%s %s' % (path,args)
print "running..."
print command
os.system(command)
if __name__=='__main__': main()