Kindfield
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Friends Pages
run.py
Go to the documentation of this file.
1 #!/usr/bin/python
2 import subprocess
3 import os
4 import os.path
5 import signal
6 from sys import argv
7 from argparse import ArgumentParser
8 
9 
10 parser = ArgumentParser()
11 parser.add_argument("states_file")
12 parser.add_argument("--no_mpi", action="store_true")
13 parser.add_argument("--id", nargs='?', default="tmp")
14 args = parser.parse_args()
15 
16 output_dir = os.path.abspath("tmp")
17 
18 if args.id != "tmp":
19  try:
20  from sumatra.projects import load_project
21  output_dir = os.path.join(os.path.abspath(load_project().data_store.root), args.id)
22  except ImportError:
23  pass
24 
25 current_path = os.path.dirname(os.path.realpath(__file__))
26 
27 if not os.path.exists(output_dir):
28  os.makedirs(output_dir)
29 
30 states_file = argv[1]
31 
32 output_file = os.path.join(output_dir, os.path.split(states_file)[-1])
33 
34 build_path = os.path.abspath(os.path.join(current_path, "..", "..", "..", "build"))
35 project_path = os.path.abspath(os.path.join(current_path, "..", ".."))
36 
37 print "Building in:\n", build_path
38 
39 if not os.path.exists(build_path):
40  os.makedirs(build_path)
41 subprocess.call(["qmake", project_path, "CONFIG+=nogui"], cwd=build_path)
42 subprocess.call(["make", "-j", "8"], cwd=build_path)
43 
44 staterunner_path = os.path.join(build_path, "tools", "staterunner")
45 lib_path = os.path.join("..", "..", "src")
46 
47 env = dict(os.environ)
48 env['LD_LIBRARY_PATH'] = lib_path
49 #proc = subprocess.call(["./staterunner", states_file, output_file], cwd=staterunner_path, env=env)
50 if args.no_mpi:
51  run_argument = ["./staterunner", states_file, output_file]
52 else:
53  run_argument = ["mpirun", "-n", "8", "./staterunner", states_file, output_file]
54 print " ".join(run_argument)
55 proc = subprocess.call(run_argument, cwd=staterunner_path, env=env)
56 
57 print "Results saved to this directory:\n", output_dir + "/*"