summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-03-01 11:01:06 +0100
committerDaniel Friesel <derf@finalrewind.org>2018-03-01 11:01:06 +0100
commita5e5cf1f9708cdd20122b4e267551272ea260d4f (patch)
treedd86c68897265da9b3f2fc1b5b6dcc6dea85ac0a
parent25b4281ef57486b925fd86f2ce9d8a0fff608d29 (diff)
re-add argument support, starting with --ignored-trace-indexes
-rwxr-xr-xbin/analyze-archive.py32
-rwxr-xr-xlib/dfatool.py35
2 files changed, 46 insertions, 21 deletions
diff --git a/bin/analyze-archive.py b/bin/analyze-archive.py
index 8c81d35..e3a44bf 100755
--- a/bin/analyze-archive.py
+++ b/bin/analyze-archive.py
@@ -1,7 +1,12 @@
#!/usr/bin/env python3
+import getopt
+import plotter
+import re
import sys
-from dfatool import EnergyModel, RawData
+from dfatool import EnergyModel, RawData, soft_cast_int
+
+opts = {}
def print_model_quality(results):
for state_or_tran in results.keys():
@@ -33,11 +38,30 @@ def model_quality_table(result_lists, info_list):
print(buf)
if __name__ == '__main__':
- filenames = sys.argv[1:]
- raw_data = RawData(filenames)
+
+ ignored_trace_indexes = None
+
+ try:
+ raw_opts, args = getopt.getopt(sys.argv[1:], "",
+ 'plot ignored-trace-indexes='.split(' '))
+
+ for option, parameter in raw_opts:
+ optname = re.sub(r'^--', '', option)
+ opts[optname] = parameter
+
+ if 'ignored-trace-indexes' in opts:
+ ignored_trace_indexes = list(map(int, opts['ignored-trace-indexes'].split(',')))
+ if 0 in ignored_trace_indexes:
+ print('[E] arguments to --ignored-trace-indexes start from 1')
+
+ except getopt.GetoptError as err:
+ print(err)
+ sys.exit(2)
+
+ raw_data = RawData(args)
preprocessed_data = raw_data.get_preprocessed_data()
- model = EnergyModel(preprocessed_data)
+ model = EnergyModel(preprocessed_data, ignore_trace_indexes = ignored_trace_indexes)
print('--- simple static model ---')
static_model = model.get_static()
diff --git a/lib/dfatool.py b/lib/dfatool.py
index 40cacef..422b838 100755
--- a/lib/dfatool.py
+++ b/lib/dfatool.py
@@ -29,7 +29,7 @@ def is_numeric(n):
except ValueError:
return False
-def _soft_cast_int(n):
+def soft_cast_int(n):
if n == None or n == '':
return None
try:
@@ -48,9 +48,9 @@ def float_or_nan(n):
def _elem_param_and_arg_list(elem):
param_dict = elem['parameter']
paramkeys = sorted(param_dict.keys())
- paramvalue = [_soft_cast_int(param_dict[x]) for x in paramkeys]
+ paramvalue = [soft_cast_int(param_dict[x]) for x in paramkeys]
if arg_support_enabled and 'args' in elem:
- paramvalue.extend(map(_soft_cast_int, elem['args']))
+ paramvalue.extend(map(soft_cast_int, elem['args']))
return paramvalue
def _arg_name(arg_index):
@@ -269,13 +269,13 @@ class RawData:
online_trace_part['offline'].append(offline_trace_part)
paramkeys = sorted(online_trace_part['parameter'].keys())
- paramvalue = [_soft_cast_int(online_trace_part['parameter'][x]) for x in paramkeys]
+ paramvalue = [soft_cast_int(online_trace_part['parameter'][x]) for x in paramkeys]
# NB: Unscheduled transitions do not have an 'args' field set.
# However, they should only be caused by interrupts, and
# interrupts don't have args anyways.
if arg_support_enabled and 'args' in online_trace_part:
- paramvalue.extend(map(_soft_cast_int, online_trace_part['args']))
+ paramvalue.extend(map(soft_cast_int, online_trace_part['args']))
if not 'offline_aggregates' in online_trace_part:
online_trace_part['offline_aggregates'] = {
@@ -437,8 +437,7 @@ class AnalyticFunction:
X[i].extend([np.nan] * len(val[model_attribute]))
elif key[0] == state_or_tran and len(key[1]) != dimension:
print('[W] Invalid parameter key length while gathering fit data for {}/{}. is {}, want {}.'.format(state_or_tran, model_attribute, len(key[1]), dimension))
- for i in range(dimension):
- X[i] = np.array(X[i])
+ X = np.array(X)
Y = np.array(Y)
return X, Y, num_valid, num_total
@@ -711,7 +710,7 @@ def _mean_std_by_param(by_param, state_or_tran, key, param_index):
class EnergyModel:
- def __init__(self, preprocessed_data):
+ def __init__(self, preprocessed_data, ignore_trace_indexes = None):
self.traces = preprocessed_data
self.by_name = {}
self.by_param = {}
@@ -720,13 +719,15 @@ class EnergyModel:
np.seterr('raise')
self._parameter_names = sorted(self.traces[0]['trace'][0]['parameter'].keys())
self._num_args = {}
- for runidx, run in enumerate(self.traces):
- # if opts['ignore-trace-idx'] != runidx
- for i, elem in enumerate(run['trace']):
- if elem['name'] != 'UNINITIALIZED':
- self._load_run_elem(i, elem)
- if elem['isa'] == 'transition' and not elem['name'] in self._num_args and 'args' in elem:
- self._num_args[elem['name']] = len(elem['args'])
+ for run in self.traces:
+ if ignore_trace_indexes == None or int(run['id']) not in ignore_trace_indexes:
+ for i, elem in enumerate(run['trace']):
+ if elem['name'] != 'UNINITIALIZED':
+ self._load_run_elem(i, elem)
+ if elem['isa'] == 'transition' and not elem['name'] in self._num_args and 'args' in elem:
+ self._num_args[elem['name']] = len(elem['args'])
+ else:
+ print('[I] ignored trace index #{:d}'.format(int(run['id'])))
self._aggregate_to_ndarray(self.by_name)
self._compute_all_param_statistics()
@@ -851,7 +852,7 @@ class EnergyModel:
lut_model = self._get_model_from_dict(self.by_param, np.median)
def lut_median_getter(name, key, param, arg = [], **kwargs):
- param.extend(map(_soft_cast_int, arg))
+ param.extend(map(soft_cast_int, arg))
return lut_model[(name, tuple(param))][key]
return lut_median_getter
@@ -911,7 +912,7 @@ class EnergyModel:
state_or_tran, model_attribute, result['key'][2], fit_result['best_rmsd'],
fit_result['mean_rmsd'], fit_result['median_rmsd']))
elif fit_result['best_rmsd'] >= 0.5 * min(fit_result['mean_rmsd'], fit_result['median_rmsd']):
- print('[I] Not modeling {} {} as function o {}: best ({:.0f}) is not much better than ({:.0f}, {:.0f})'.format(
+ print('[I] Not modeling {} {} as function of {}: best ({:.0f}) is not much better than ({:.0f}, {:.0f})'.format(
state_or_tran, model_attribute, result['key'][2], fit_result['best_rmsd'],
fit_result['mean_rmsd'], fit_result['median_rmsd']))
else: