def create_job(config, name, work_dir, train_file, model_file, test_file, classif_file, memory=MEMORY): """\ Save configuration to a pickle file, create a corresponding cluster job and run it. """ train_file = os.path.abspath(train_file) cfg_file = append_name('config.pickle', name) model_file = append_name(model_file, name) if test_file is not None and classif_file is not None: test_file = os.path.abspath(test_file) classif_file = append_name(classif_file, name) test_str = "'{0}', '{1}'".format(test_file, classif_file) else: test_str = 'None, None' # save unfolded config file fh = open(os.path.join(work_dir, cfg_file), mode='wb') marshal_lambda(config, 'filter_attr') marshal_lambda(config, 'postprocess') pickle.dump(config, fh, pickle.HIGHEST_PROTOCOL) fh.close() # create the training job job = Job(name=name, work_dir=work_dir) job.header = "from flect.experiment.train_model import run_training\n" job.code = "run_training('{0}', '{1}',".format(work_dir, cfg_file) + \ "'{0}', '{1}', {2})\n".format(train_file, model_file, test_str) job.submit(memory=memory) print 'Job', job, 'submitted.'