-
Notifications
You must be signed in to change notification settings - Fork 0
/
mcsimulate.py
executable file
·85 lines (68 loc) · 2.81 KB
/
mcsimulate.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
#!/usr/bin/env python
import os
import sys
USAGE_STR = """
Usage: mcsimulate INPUT_DB IND_ID OUTPUT_DB CLUSTER_ID [MAX_NUM_RND_PTS]
Locally, Monte Carlo simulates INPUT_DB's individual IND_ID (shortID), and saves results to OUTPUT_DB.
If the PS is nominal, then just simulates there.
"""
if __name__== '__main__':
#grab arguments, exit if needed
num_args = len(sys.argv)
if num_args not in [5, 6]:
print USAGE_STR
sys.exit(0)
input_db_file = sys.argv[1]
ind_ID = sys.argv[2]
output_db_file = sys.argv[3]
cluster_id = sys.argv[4]
if num_args >= 6: max_num_rnd_points = eval(sys.argv[5])
else: max_num_rnd_points = 100000
#corner cases
if not os.path.exists(input_db_file):
print "\nInput DB '%s' does not exist. Exiting.\n" % input_db_file
sys.exit(0)
if os.path.exists(output_db_file):
print "\nOutput DB '%s' already exists. Exiting.\n" % output_db_file
sys.exit(0)
#late imports
import engine.Channel as Channel
import engine.EngineUtils as EngineUtils
from engine.Master import Master
#setup logging
import logging
logging.basicConfig()
logging.getLogger('analysis').setLevel(logging.INFO)
logging.getLogger('evaluate').setLevel(logging.INFO)
logging.getLogger('engine_utils').setLevel(logging.INFO)
logging.getLogger('master').setLevel(logging.INFO)
logging.getLogger('channel').setLevel(logging.INFO)
#
print "mcsimulate: begin: INPUT_DB=%s, IND_ID=%s, OUTPUT_DB=%s, CLUSTER_ID=%s, MAX_NUM_RND_PTS=%d" % \
(input_db_file, ind_ID, output_db_file, cluster_id, max_num_rnd_points)
#objects for master
cs = Channel.ChannelStrategy('PyroBased', cluster_id)
#go!
master = Master(cs, None, None, None, input_db_file)
ind = master.state.getInd(ind_ID)
if ind is None:
ind_IDs = [ind.shortID() for ind in master.state.allInds()]
print "\nCould not find an ind with ID of %s. IDs are: %s" % (ind_ID, ind_IDs)
sys.exit(0)
print "mcsimulate: Found ind with ID %s; it has %d rnd points" % (ind_ID, len(ind.rnd_IDs))
try:
ind.clearSimulations()
task_data = Channel.TaskData()
task_data.ind = ind
task_data.ind.prepareForPickle()
task_data.num_rnd_points = min(max_num_rnd_points, len(ind.rnd_IDs))
print "mcsimulate: master-invoked simulations: begin"
inds = master.generateInds(task_data_list=[task_data], descr="Evaluate ind further")
print "mcsimulate: master-invoked simulations: done"
print "mcsimulate: save final output file %s" % output_db_file
master.saveStateToFile(output_db_file)
except:
#master.cleanup()
raise
#master.cleanup()
print "mcsimulate: done"