diff --git a/garlic/ds/index.nix b/garlic/ds/index.nix new file mode 100644 index 0000000..89d2907 --- /dev/null +++ b/garlic/ds/index.nix @@ -0,0 +1,13 @@ +{ + super +, self +, bsc +, garlic +, callPackage +}: + +{ + std = { + timetable = callPackage ./std/timetable.nix {}; + }; +} diff --git a/garlic/ds/std/timetable.nix b/garlic/ds/std/timetable.nix new file mode 100644 index 0000000..496dc58 --- /dev/null +++ b/garlic/ds/std/timetable.nix @@ -0,0 +1,23 @@ +{ + stdenv +, python3 +}: + +resultTree: + +stdenv.mkDerivation { + name = "timetable.json"; + preferLocalBuild = true; + src = ./timetable.py; + phases = [ "unpackPhase" "installPhase" ]; + + unpackPhase = '' + cp $src timetable.py + ''; + + buildInputs = [ python3 ]; + installPhase = '' + touch $out + python timetable.py ${resultTree} > $out + ''; +} diff --git a/garlic/ds/std/timetable.py b/garlic/ds/std/timetable.py new file mode 100644 index 0000000..d79bf13 --- /dev/null +++ b/garlic/ds/std/timetable.py @@ -0,0 +1,68 @@ +import json, re, sys, os, glob +from os import path + +def eprint(*args, **kwargs): + print(*args, file=sys.stderr, flush=True, **kwargs) + +def process_run(tree, runPath): + with open("stdout.log", "r") as f: + lines = [line.strip() for line in f.readlines()] + + time_line = None + for line in lines: + + if re.match(r'^ ?time .*', line): + time_line = line + break + + if time_line is None: + eprint("missing time line, aborting") + eprint("stdout file = {}/stdout.log".format(runPath)) + exit(1) + + time_str = time_line.split()[1] + + tree['time'] = float(time_str) + print(json.dumps(tree)) + +def process_result_tree(resultTree): + + eprint("processing resultTree: " + resultTree) + + os.chdir(resultTree) + + experiments = glob.glob(resultTree + "/*-experiment") + + for exp in glob.glob("*-experiment"): + eprint("found experiment: " + exp) + expPath = path.join(resultTree, exp) + os.chdir(expPath) + + for unit in glob.glob("*-unit"): + eprint("found unit: " + unit) + unitPath = path.join(resultTree, exp, unit) + os.chdir(unitPath) + + with open('garlic_config.json') as json_file: + garlic_conf = json.load(json_file) + + tree = {"exp":exp, "unit":unit, "config":garlic_conf} + + for i in range(garlic_conf['loops']): + run = str(i + 1) + runPath = path.join(resultTree, exp, unit, run) + if path.isdir(runPath) == False: + eprint("missing run {}, aborting".format(run)) + exit(1) + + tree["run"] = run + os.chdir(runPath) + + process_run(tree, runPath) + + +if len(sys.argv) != 2: + eprint("usage: python {} ".format(argv[0])) + exit(1) + +process_result_tree(sys.argv[1]) diff --git a/garlic/index.nix b/garlic/index.nix index 1a52a67..1902d8e 100644 --- a/garlic/index.nix +++ b/garlic/index.nix @@ -131,7 +131,10 @@ # Experiments exp = callPackage ./exp/index.nix { }; - # Figures generated from the experiments + # Dataset generators from resultTree + ds = callPackage ./ds/index.nix { }; + + # Figures generated from the datasets fig = callPackage ./fig/index.nix { }; }