From 3f526141c46760219dbd8fef09a3ae632e44e574 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sun, 9 Aug 2009 16:33:30 +0200 Subject: [PATCH] First attempts at the evaluation overlord --- t/config | 8 +++++++ t/moe/batch.py | 10 ++++++++ t/moe/config.py | 6 ++++- t/moe/eval.py | 62 +++++++++++++++++++++++++++++++++++++++++++++++++ t/test.py | 36 +++++++++------------------- 5 files changed, 96 insertions(+), 26 deletions(-) create mode 100644 t/config create mode 100644 t/moe/batch.py diff --git a/t/config b/t/config new file mode 100644 index 0000000..910dfcb --- /dev/null +++ b/t/config @@ -0,0 +1,8 @@ +# HOME set automatically +# CONTESTANT set automatically +# TASK set automatically +TASK_DIR="${HOME}/problems/${TASK}" +SOL_DIR="${HOME}/solutions/${CONTESTANT}/${TASK}" +TEST_DIR="${HOME}/testing/${CONTESTANT}/${TASK}" + +TASK_TYPE=batch diff --git a/t/moe/batch.py b/t/moe/batch.py new file mode 100644 index 0000000..7fcfd7a --- /dev/null +++ b/t/moe/batch.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python + +def compile(e): + pass + +def tests(e): + pass + +def locate(e, file=None): + pass diff --git a/t/moe/config.py b/t/moe/config.py index 7d9da30..4baee06 100644 --- a/t/moe/config.py +++ b/t/moe/config.py @@ -28,6 +28,9 @@ class MoeConfig: else: self.load(file) + def set(self, k, v): + self.vars[k] = [("s", v)] + def parse_line(self, x): x = x.rstrip("\n").lstrip(" \t") if x=="" or x.startswith("#"): @@ -138,7 +141,8 @@ class MoeConfigStack: self.in_progress[k] = 1; v = self.do_get(k, len(self.stk)-1) del self.in_progress[k] - self.cache[k] = v + ## FIXME: This is disabled, because the immutability invariant is broken! + # self.cache[k] = v return v def do_get(self, k, pos): diff --git a/t/moe/eval.py b/t/moe/eval.py index e5d8d04..9dd4c82 100644 --- a/t/moe/eval.py +++ b/t/moe/eval.py @@ -1,3 +1,65 @@ #!/usr/bin/env python import moe.config +import moe.log +import moe.meta +import moe.pipeline +import moe.batch +import moe.util +import os.path +import shutil + +class MoeEvalErr(Exception): + pass + +class Eval: + + def __init__(self): + self.cfgs = moe.config.MoeConfigStack() + self.builtins = moe.config.MoeConfig() + self.cfgs.push(self.builtins) + self.main_pipe = moe.pipeline.MoePipeline("main") + self.meta = moe.meta.MoeMeta() + pass + + def init(self): + self.init_global() + ## FIXME: Configuration overrides + self.init_test() + ## FIXME: Initialize logging early on + self.init_task() + + def init_global(self): + main_cfg = moe.config.MoeConfig(name = os.path.join(self.cfgs['HOME'], "config")) + self.cfgs.push(main_cfg) + + def init_test(self): + test = self.cfgs['TEST_DIR'] + if os.path.isdir(test): + shutil.rmtree(test) + try: + moe.util.mkdir_tree(test) + except OSError, e: + raise MoeEvalErr, "Cannot create %s: %s" % (test, e.strerror) + + def init_task(self): + task = self.cfgs['TASK'] + task_dir = self.cfgs['TASK_DIR'] + if not os.path.isdir(task_dir): + raise MoeEvalErr, "No such task %s" % task + task_cfg = moe.config.MoeConfig(name = os.path.join(task_dir, "config")) + self.cfgs.push(task_cfg) + + type = self.cfgs['TASK_TYPE'] + if type == "batch" or type == "interactive": + self.main_pipe.insert(100, "compile", moe.batch.compile) + self.main_pipe.insert(200, "batch-tests", moe.batch.tests) + elif type == "opendata": + raise MoeEvalErr, "Opendata tasks not implemented yet" + else: + raise MoeEvalErr, "Unknown task type " + type + + def run(self): + self.main_pipe.configure(self.cfgs["HOOKS"]) + self.main_pipe.dump() + self.main_pipe.run(self) diff --git a/t/test.py b/t/test.py index 7250720..005ba39 100755 --- a/t/test.py +++ b/t/test.py @@ -7,32 +7,18 @@ import moe.meta import moe.config import moe.eval import moe.pipeline +import moe.batch -#m = moe.meta.MoeMeta() -#m['a'] = '1' -#m.write() +e = moe.eval.Eval() +e.builtins.set("HOME", ".") +e.builtins.set("TASK", "sum") +e.builtins.set("CONTESTANT", "somebody") +e.init() -c = moe.config.MoeConfig(name='/dev/stdin') -c.dump() +print "Task configuration:" +e.cfgs.dump() +print -#d = moe.config.MoeConfig(name='/dev/stdin') -#d.dump() +moe.batch.locate(e) -s = moe.config.MoeConfigStack() -s.push(c) -#s.push(d) - -s.dump_defs() - -#s.apply_overrides("x_") -#s.dump_defs() - -print "***" -s.dump() - -p = moe.pipeline.MoePipeline('test') -p.insert(10, 'brum', lambda x: p.insert(30, 'xyzzy', lambda y:y)) -p.insert(20, 'brummm', lambda x: x) -p.configure("y") -p.dump() -p.run(5) +e.run() -- 2.39.2