Commit 710f659b authored by Antoine Kaufmann's avatar Antoine Kaufmann
Browse files

experiments: move mkdirs into runtime to avoid special casing for slurm

parent 32fd378d
import tarfile import tarfile
import io import io
import pathlib
class NodeConfig(object): class NodeConfig(object):
sim = 'qemu' sim = 'qemu'
......
...@@ -37,10 +37,13 @@ class LocalSimpleRuntime(Runtime): ...@@ -37,10 +37,13 @@ class LocalSimpleRuntime(Runtime):
def start(self): def start(self):
for run in self.runnable: for run in self.runnable:
pathlib.Path(run.env.workdir).mkdir(parents=True, exist_ok=True)
run.output = exp.run_exp_local(run.experiment, run.env, run.output = exp.run_exp_local(run.experiment, run.env,
verbose=self.verbose) verbose=self.verbose)
self.complete.append(run) self.complete.append(run)
pathlib.Path(run.outpath).parent.mkdir(parents=True, exist_ok=True)
with open(run.outpath, 'w') as f: with open(run.outpath, 'w') as f:
f.write(run.output.dumps()) f.write(run.output.dumps())
...@@ -68,9 +71,13 @@ class LocalParallelRuntime(Runtime): ...@@ -68,9 +71,13 @@ class LocalParallelRuntime(Runtime):
async def do_run(self, run): async def do_run(self, run):
''' actually starts a run ''' ''' actually starts a run '''
pathlib.Path(run.env.workdir).mkdir(parents=True, exist_ok=True)
await run.experiment.prepare(run.env, verbose=self.verbose) await run.experiment.prepare(run.env, verbose=self.verbose)
print('starting run ', run.name()) print('starting run ', run.name())
run.output = await run.experiment.run(run.env, verbose=self.verbose) run.output = await run.experiment.run(run.env, verbose=self.verbose)
pathlib.Path(run.outpath).parent.mkdir(parents=True, exist_ok=True)
with open(run.outpath, 'w') as f: with open(run.outpath, 'w') as f:
f.write(run.output.dumps()) f.write(run.output.dumps())
print('finished run ', run.name()) print('finished run ', run.name())
......
...@@ -62,10 +62,6 @@ for path in args.experiments: ...@@ -62,10 +62,6 @@ for path in args.experiments:
with open(path, 'rb') as f: with open(path, 'rb') as f:
experiments.append(pickle.load(f)) experiments.append(pickle.load(f))
if args.runtime != 'slurm':
mkdir_if_not_exists(args.workdir)
mkdir_if_not_exists(args.outdir)
if args.runtime == 'parallel': if args.runtime == 'parallel':
rt = runtime.LocalParallelRuntime(cores=args.cores, mem=args.mem, rt = runtime.LocalParallelRuntime(cores=args.cores, mem=args.mem,
verbose=args.verbose) verbose=args.verbose)
...@@ -74,20 +70,15 @@ elif args.runtime == 'slurm': ...@@ -74,20 +70,15 @@ elif args.runtime == 'slurm':
else: else:
rt = runtime.LocalSimpleRuntime(verbose=args.verbose) rt = runtime.LocalSimpleRuntime(verbose=args.verbose)
for e in experiments:
workdir_base = '%s/%s' % (args.workdir, e.name)
if args.runtime != 'slurm':
mkdir_if_not_exists(workdir_base)
for e in experiments:
for run in range(args.firstrun, args.firstrun + args.runs): for run in range(args.firstrun, args.firstrun + args.runs):
outpath = '%s/%s-%d.json' % (args.outdir, e.name, run) outpath = '%s/%s-%d.json' % (args.outdir, e.name, run)
if os.path.exists(outpath): if os.path.exists(outpath):
print('skip %s run %d' % (e.name, run)) print('skip %s run %d' % (e.name, run))
continue continue
workdir = '%s/%d' % (workdir_base, run) workdir = '%s/%s/%d' % (args.workdir, e.name, run)
if args.runtime != 'slurm':
mkdir_if_not_exists(workdir)
env = exp.ExpEnv(args.repo, workdir) env = exp.ExpEnv(args.repo, workdir)
rt.add_run(runtime.Run(e, run, env, outpath)) rt.add_run(runtime.Run(e, run, env, outpath))
......
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