diff options
Diffstat (limited to 'parse_exps.py')
| -rwxr-xr-x[-rw-r--r--] | parse_exps.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/parse_exps.py b/parse_exps.py index e69de29..6a7d14f 100644..100755 --- a/parse_exps.py +++ b/parse_exps.py | |||
| @@ -0,0 +1,85 @@ | |||
| 1 | #!/usr/bin/env python | ||
| 2 | from __future__ import print_function | ||
| 3 | |||
| 4 | import config.config as conf | ||
| 5 | import os | ||
| 6 | |||
| 7 | import parse.ft as ft | ||
| 8 | import parse.sched as st | ||
| 9 | |||
| 10 | from collections import namedtuple | ||
| 11 | from common import load_params | ||
| 12 | from optparse import OptionParser | ||
| 13 | from parse.tuple_table import ColMap,TupleTable | ||
| 14 | from parse.point import ExpPoint | ||
| 15 | |||
| 16 | def parse_args(): | ||
| 17 | parser = OptionParser("usage: %prog [options] [data_dir]...") | ||
| 18 | |||
| 19 | parser.add_option('-o', '--out-dir', dest='out_dir', | ||
| 20 | help='directory for data output', default=os.getcwd()) | ||
| 21 | |||
| 22 | return parser.parse_args() | ||
| 23 | |||
| 24 | ExpData = namedtuple('ExpData', ['name', 'params', 'data_files']) | ||
| 25 | DataFiles = namedtuple('DataFiles', ['ft','st']) | ||
| 26 | |||
| 27 | def get_exp_params(data_dir, col_map): | ||
| 28 | param_file = "%s/%s" % (data_dir, conf.DEFAULTS['params_file']) | ||
| 29 | if not os.path.isfile: | ||
| 30 | raise Exception("No param file '%s' exists!" % param_file) | ||
| 31 | |||
| 32 | # Keep only params that uniquely identify the experiment | ||
| 33 | params = load_params(param_file) | ||
| 34 | for ignored in conf.PARAMS.itervalues(): | ||
| 35 | if ignored in params: | ||
| 36 | params.pop(ignored) | ||
| 37 | |||
| 38 | # Track all changed params | ||
| 39 | for key in params.keys(): | ||
| 40 | col_map.try_add(key) | ||
| 41 | |||
| 42 | return params | ||
| 43 | |||
| 44 | |||
| 45 | def gen_exp_data(exp_dirs, col_map): | ||
| 46 | exps = [] | ||
| 47 | for data_dir in exp_dirs: | ||
| 48 | if not os.path.isdir(data_dir): | ||
| 49 | raise IOError("Invalid experiment '%s'" % os.path.abspath(data_dir)) | ||
| 50 | |||
| 51 | tmp_dir = data_dir + "/tmp" | ||
| 52 | if not os.path.exists(tmp_dir): | ||
| 53 | os.mkdir(tmp_dir) | ||
| 54 | |||
| 55 | params = get_exp_params(data_dir, col_map) | ||
| 56 | st_output = st.get_st_output(data_dir, tmp_dir) | ||
| 57 | ft_output = ft.get_ft_output(data_dir, tmp_dir) | ||
| 58 | |||
| 59 | exp_data = ExpData(data_dir, params, DataFiles(ft_output, st_output)) | ||
| 60 | exps += [exp_data] | ||
| 61 | |||
| 62 | return exps | ||
| 63 | |||
| 64 | def main(): | ||
| 65 | opts, args = parse_args() | ||
| 66 | |||
| 67 | args = args or [os.getcwd()] | ||
| 68 | col_map = ColMap() | ||
| 69 | exps = gen_exp_data(args, col_map) | ||
| 70 | |||
| 71 | table = TupleTable(col_map) | ||
| 72 | |||
| 73 | for exp in exps: | ||
| 74 | result = ExpPoint(exp.name) | ||
| 75 | if exp.data_files.ft: | ||
| 76 | ft.get_ft_data(exp.data_files.ft, result, conf.BASE_EVENTS) | ||
| 77 | if exp.data_files.st: | ||
| 78 | st.get_sched_data(exp.data_files.st, result) | ||
| 79 | |||
| 80 | table.add_exp(exp.params, result) | ||
| 81 | |||
| 82 | table.write_result(opts.out_dir) | ||
| 83 | |||
| 84 | if __name__ == '__main__': | ||
| 85 | main() | ||
