Commit c5bb0692 authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

experiments: checkpoint for python scripts

parent 62c6bed2
...@@ -169,7 +169,7 @@ class ExpOutput(object): ...@@ -169,7 +169,7 @@ class ExpOutput(object):
self.start_time = time.time() self.start_time = time.time()
def set_end(self): def set_end(self):
self.end = time.time() self.end_time = time.time()
def set_failed(self): def set_failed(self):
self.success = False self.success = False
...@@ -189,9 +189,5 @@ class ExpOutput(object): ...@@ -189,9 +189,5 @@ class ExpOutput(object):
def run_exp_local(exp, env): def run_exp_local(exp, env):
if os.path.exists(env.workdir):
raise Exception('Workdir already exists')
os.mkdir(env.workdir)
asyncio.run(exp.prepare(env)) asyncio.run(exp.prepare(env))
return asyncio.run(exp.run(env)) return asyncio.run(exp.run(env))
...@@ -32,6 +32,5 @@ for i in range (0, 2): ...@@ -32,6 +32,5 @@ for i in range (0, 2):
host_b.add_nic(nic_b) host_b.add_nic(nic_b)
e.add_host(host_b) e.add_host(host_b)
env = exp.ExpEnv('..', './work') experiments = [e]
out = exp.run_exp_local(e, env)
print(out.dumps())
import argparse
import sys
import os
import importlib
import modes.experiments as exp
def mkdir_if_not_exists(path):
if not os.path.exists(path):
os.mkdir(path)
parser = argparse.ArgumentParser()
parser.add_argument('experiments', metavar='EXP', type=str, nargs='+',
help='An experiment file to run')
parser.add_argument('--runs', metavar='N', type=int, default=1,
help='Number of runs')
parser.add_argument('--repo', metavar='DIR', type=str,
default='..', help='Repo directory')
parser.add_argument('--workdir', metavar='DIR', type=str,
default='./out/', help='Work directory base')
parser.add_argument('--outdir', metavar='DIR', type=str,
default='./out/', help='Output directory base')
args = parser.parse_args()
experiments = []
for path in args.experiments:
modname = os.path.splitext(os.path.basename(path))[0]
spec = importlib.util.spec_from_file_location(modname, path)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
experiments += mod.experiments
mkdir_if_not_exists(args.workdir)
mkdir_if_not_exists(args.outdir)
for e in experiments:
workdir_base = '%s/%s' % (args.workdir, e.name)
mkdir_if_not_exists(workdir_base)
for run in range(0, args.runs):
outpath = '%s/%s-%d.json' % (args.outdir, e.name, run)
if os.path.exists(outpath):
print('skip %s run %d' % (e.name, run))
continue
workdir = '%s/%d' % (workdir_base, run)
mkdir_if_not_exists(workdir)
env = exp.ExpEnv(args.repo, workdir)
out = exp.run_exp_local(e, env)
with open(outpath, 'w') as f:
f.write(out.dumps())
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment