]> mj.ucw.cz Git - moe.git/blob - t/moe/eval.py
Locating batch tasks
[moe.git] / t / moe / eval.py
1 #!/usr/bin/env python
2
3 import moe.config
4 import moe.log
5 import moe.meta
6 import moe.pipeline
7 import moe.batch
8 import moe.util
9 import os.path
10 import shutil
11
12 class MoeEvalErr(Exception):
13     pass
14
15 class Eval:
16
17     def __init__(self):
18         self.cfgs = moe.config.MoeConfigStack()
19         self.builtins = moe.config.MoeConfig()
20         self.cfgs.push(self.builtins)
21         self.main_pipe = moe.pipeline.MoePipeline("main")
22         self.meta = moe.meta.MoeMeta()
23         pass
24
25     def init(self):
26         self.init_global()
27         ## FIXME: Configuration overrides
28         self.init_test()
29         ## FIXME: Initialize logging early on
30         self.init_task()
31
32     def init_global(self):
33         main_cfg = moe.config.MoeConfig(name = os.path.join(self.cfgs['HOME'], "config"))
34         self.cfgs.push(main_cfg)
35
36     def init_test(self):
37         test = self.cfgs['TEST_DIR']
38         if os.path.isdir(test):
39             shutil.rmtree(test)
40         try:
41             moe.util.mkdir_tree(test)   
42         except OSError, e:
43             raise MoeEvalErr, "Cannot create %s: %s" % (test, e.strerror)
44
45     def init_task(self):
46         task = self.cfgs['TASK']
47         task_dir = self.cfgs['TASK_DIR']
48         if not os.path.isdir(task_dir):
49             raise MoeEvalErr, "No such task %s" % task
50         task_cfg = moe.config.MoeConfig(name = os.path.join(task_dir, "config"))
51         self.cfgs.push(task_cfg)
52         self.meta["task"] = task
53
54         type = self.cfgs['TASK_TYPE']
55         if type == "batch" or type == "interactive":
56             moe.batch.prepare_pipe(self)
57         elif type == "opendata":
58             raise MoeEvalErr, "Opendata tasks not implemented yet"
59         else:
60             raise MoeEvalErr, "Unknown task type " + type
61
62     def run(self):
63         self.main_pipe.configure(self.cfgs["HOOKS"])
64         self.main_pipe.dump()
65         self.main_pipe.run(self)