<commit_before>
/**
   OBJ PY SWIFT
*/

string code_template =
"""
import nt3_tc1_runner
import json, os

outdir = '%s'

if not os.path.exists(outdir):
    os.makedirs(outdir)

hyper_parameter_map = json.loads('%s')
hyper_parameter_map['framework'] = 'keras'
hyper_parameter_map['save'] = '{}/output'.format(outdir)
hyper_parameter_map['instance_directory'] = outdir
hyper_parameter_map['model_name'] = '%s'
hyper_parameter_map['experiment_id'] = '%s'
hyper_parameter_map['run_id'] = '%s'
hyper_parameter_map['timeout'] = %d

validation_loss = nt3_tc1_runner.run(hyper_parameter_map)
""";

(string obj_result) obj(string params, string iter_indiv_id) {
  string outdir = "%s/run_%s" % (turbine_output, iter_indiv_id);
  string code = code_template % (outdir, params, model_name, exp_id, iter_indiv_id, benchmark_timeout);
  obj_result = python_persist(code, "str(validation_loss)");
  printf(obj_result);
}<commit_msg>Update obj_py to use model_runner<commit_after>
/**
   OBJ PY SWIFT
*/

string code_template =
"""
try:
  import sys, traceback, json, os
  import model_runner
  import tensorflow 
  from tensorflow import keras 

  validation_loss = '-1'

  outdir = '%s'

  if not os.path.exists(outdir):
      os.makedirs(outdir)

  hyper_parameter_map = json.loads('%s')
  hyper_parameter_map['framework'] = 'keras'
  hyper_parameter_map['save'] = '{}/output'.format(outdir)
  hyper_parameter_map['instance_directory'] = outdir
  hyper_parameter_map['model_name'] = '%s'
  hyper_parameter_map['experiment_id'] = '%s'
  hyper_parameter_map['run_id'] = '%s'
  hyper_parameter_map['timeout'] = %d

  model_runner.run(hyper_parameter_map, 'val_loss')

except Exception as e:
  info = sys.exc_info()
  s = traceback.format_tb(info[2])
  print('EXCEPTION: \\n' + repr(e) + ' ... \\n' + ''.join(s))
  sys.stdout.flush()
  validation_loss = 'EXCEPTION'
""";

(string obj_result) obj(string params, string iter_indiv_id) {
  string outdir = "%s/run/%s" % (turbine_output, iter_indiv_id);
  string code = code_template % (outdir, params, model_name,
                                 exp_id, iter_indiv_id, benchmark_timeout);
  obj_result = python_persist(code, "str(validation_loss)");
  printf(obj_result);
}
{'fraction_non_alphanumeric': 0.14603174603174604, 'fraction_numerical': 0.0027210884353741495, 'mean_word_length': 5.179271708683474, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4651596', 'n_tokens_mistral': 805, 'n_tokens_neox': 791, 'n_words': 149}