Skip to content

Commit e493b44

Browse files
committed
2 parents 24d1eb8 + fc317ce commit e493b44

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

workflows/common/python/runner_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
import json
2+
import json, os
33

44
DATA_TYPES = {type(np.float16): 'f16', type(np.float32): 'f32', type(np.float64): 'f64'}
55

@@ -11,6 +11,9 @@ def init(param_file, instance_directory, framework, out_dir_key):
1111
with open(param_file) as f_in:
1212
hyper_parameter_map = json.load(f_in)
1313

14+
if not os.path.exists(instance_directory):
15+
os.makedirs(instance_directory)
16+
1417
hyper_parameter_map['framework'] = framework
1518
hyper_parameter_map[out_dir_key] = '{}/output'.format(instance_directory)
1619
hyper_parameter_map['instance_directory'] = instance_directory

workflows/p2b1_mlrMBO/swift/ai_workflow3.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int max_budget = toint(argv("mb", "110"));
1717
int max_iterations = toint(argv("mi", "10"));
1818
int design_size = toint(argv("ds", "10"));
1919
string param_set = argv("param_set_file");
20-
file model_script = input("%s/scripts/theta_run_model.sh" % (emews_root));
20+
file model_script = input(argv("script_file"));
2121

2222
string FRAMEWORK = "keras";
2323

workflows/p2b1_mlrMBO/swift/workflow3.swift

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@ string param_set = argv("param_set_file");
2121
string code_template =
2222
"""
2323
import p2b1_runner
24-
import json
24+
import json, os
25+
26+
outdir = '%s'
27+
28+
if not os.path.exists(outdir):
29+
os.makedirs(outdir)
2530
2631
hyper_parameter_map = json.loads('%s')
2732
hyper_parameter_map['framework'] = 'keras'
33+
hyper_parameter_map['save'] = '{}/output'.format(outdir)
34+
hyper_parameter_map['instance_directory'] = outdir
2835
29-
hyper_parameter_map['save'] = '%s/output'
30-
hyper_parameter_map['instance_directory'] = '%s'
3136
3237
validation_loss = p2b1_runner.run(hyper_parameter_map)
3338
""";
@@ -42,8 +47,8 @@ max.budget = %d, max.iterations = %d, design.size=%d, propose.points=%d, param.s
4247

4348
(string obj_result) obj(string params, string iter_indiv_id) {
4449
string outdir = "%s/run_%s" % (turbine_output, iter_indiv_id);
45-
string code = code_template % (params, outdir, outdir);
46-
make_dir(outdir) =>
50+
string code = code_template % (outdir, params);
51+
//make_dir(outdir) =>
4752
obj_result = python_persist(code, "str(validation_loss)");
4853
printf(obj_result);
4954
}

workflows/p3b1_mlrMBO/python/p3b1_runner.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ def run(hyper_parameter_map):
2727
params[k] = v
2828

2929
runner_utils.write_params(params, hyper_parameter_map)
30-
#loss_history = pkg.run(params)
31-
pkg.do_n_fold(params)
30+
avg_loss = pkg.do_n_fold(params)
3231

3332
if framework == 'keras':
3433
# works around this error:
@@ -39,8 +38,7 @@ def run(hyper_parameter_map):
3938
except AttributeError: # theano does not have this function
4039
pass
4140

42-
# TODO fix with appropriate value
43-
return 0.3
41+
return avg_loss
4442

4543
if __name__ == '__main__':
4644
param_file = sys.argv[1]

workflows/p3b1_mlrMBO/swift/workflow3.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@ string param_set = argv("param_set_file");
2121
string code_template =
2222
"""
2323
import p3b1_runner
24-
import json
24+
import json, os
25+
26+
outdir = '%s'
27+
28+
if not os.path.exists(outdir):
29+
os.makedirs(outdir)
2530
2631
hyper_parameter_map = json.loads('%s')
2732
hyper_parameter_map['framework'] = 'keras'
28-
29-
hyper_parameter_map['save'] = '%s/output'
30-
hyper_parameter_map['instance_directory'] = '%s'
33+
hyper_parameter_map['save'] = '{}/output'.format(outdir)
34+
hyper_parameter_map['instance_directory'] = outdir
3135
3236
validation_loss = p3b1_runner.run(hyper_parameter_map)
3337
""";
@@ -42,8 +46,8 @@ max.budget = %d, max.iterations = %d, design.size=%d, propose.points=%d, param.s
4246

4347
(string obj_result) obj(string params, string iter_indiv_id) {
4448
string outdir = "%s/run_%s" % (turbine_output, iter_indiv_id);
45-
string code = code_template % (params, outdir, outdir);
46-
make_dir(outdir) =>
49+
string code = code_template % (outdir, params);
50+
//make_dir(outdir) =>
4751
obj_result = python_persist(code, "str(validation_loss)");
4852
printf(obj_result);
4953
}

0 commit comments

Comments
 (0)