-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrun_full.py
152 lines (124 loc) · 4.57 KB
/
run_full.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
# -*- coding: utf-8 -*-
"""Performs all analysis steps for all cases specified in the
configuration file.
"""
# Standard modules
import json
import logging
import multiprocessing
from pathlib import Path
from faultmap import config_setup
from faultmap.data_processing import result_reconstruction, trend_extraction
from faultmap.graphreduce import reduce_graph_scenarios
from faultmap.noderank import noderankcalc
from faultmap.type_definitions import RunModes
from faultmap.weightcalc import weight_calc
from plotting.plotter import draw_plot
logger = logging.getLogger(__name__)
logging.basicConfig(level="DEBUG")
# TODO: Move to class object
# TODO: Perform analysis on scenario level inside class object
def run_weight_calc(
config_loc: Path, write_output: bool, mode: RunModes, case: str, robust: bool
) -> None:
with open(Path(config_loc, "config_weightcalc.json"), encoding="utf-8") as f:
weight_calc_config = json.load(f)
# Flag indicating whether single signal entropy values for each
# signal involved should be calculated
single_entropies = weight_calc_config["calc_single_entropies"]
# Flag indicating whether
fft_calc = weight_calc_config["fft_calc"]
do_multiprocessing = weight_calc_config["multiprocessing"]
if robust:
try:
weight_calc(
mode,
case,
write_output,
single_entropies,
fft_calc,
do_multiprocessing,
)
except Exception as exc:
raise RuntimeError(f"Weight calculation failed for case: {case}") from exc
else:
weight_calc(
mode,
case,
write_output,
single_entropies,
fft_calc,
do_multiprocessing,
)
def run_createarrays(mode: RunModes, case: str, robust: bool) -> None:
if robust:
try:
# Needs to execute twice for nosigtest cases if derived from
# sigtest cases
# TODO: Remove this requirement
result_reconstruction(mode, case)
result_reconstruction(mode, case)
except:
raise RuntimeError("Array creation failed for case: " + case)
else:
result_reconstruction(mode, case)
result_reconstruction(mode, case)
def run_trend_extraction(mode, case, robust, write_output):
"""Entry point for trend extraction."""
if robust:
try:
trend_extraction(mode, case, write_output)
except Exception as exc:
raise RuntimeError(f"Trend extraction failed for case: {case}") from exc
else:
trend_extraction(mode, case, write_output)
return None
def run_noderank(mode, case, robust, write_output):
if robust:
try:
noderankcalc(mode, case, write_output)
except:
raise RuntimeError("Node faultmap failed for case: " + case)
else:
noderankcalc(mode, case, write_output)
return None
def run_graphreduce(mode, case, robust, write_output):
if robust:
try:
reduce_graph_scenarios(mode, case, write_output)
except:
raise RuntimeError("Graph reduction failed for case: " + case)
else:
reduce_graph_scenarios(mode, case, write_output)
def run_plotting(mode, case, robust, write_output):
if robust:
try:
draw_plot(mode, case, write_output)
except:
raise RuntimeError("Plotting failed for case: " + case)
else:
draw_plot(mode, case, write_output)
return None
def run_all(mode: RunModes, robust=False):
"""Runs all cases or tests"""
_, config_loc, _, _ = config_setup.get_locations(mode)
with open(Path(config_loc, "config_full.json"), encoding="utf-8") as f:
full_run_config = json.load(f)
f.close()
# Flag indicating whether calculated results should be written to disk
write_output = full_run_config["write_output"]
# Provide the mode and case names to calculate
mode = full_run_config["mode"]
cases = full_run_config["cases"]
for case in cases:
logger.info("Now attempting case: %s", case)
run_weight_calc(config_loc, write_output, mode, case, robust)
run_createarrays(mode, case, robust)
run_trend_extraction(mode, case, robust, write_output)
run_noderank(mode, case, robust, write_output)
run_graphreduce(mode, case, robust, write_output)
run_plotting(mode, case, robust, write_output)
logger.info("Done with case: " + case)
if __name__ == "__main__":
multiprocessing.freeze_support()
run_all("cases")