def do_search(problem, configname, timeout, memory, debug=False): # TODO: Currently, do_search returns an error msg on error and # None on no error, while do_translate/do_preprocess return # True/False for success/no success. This should be unified. # Maybe throw exceptions if something goes wrong? Also, # maybe we should allow for warnings in addition to errors. # The "skipped -- dir exists" stuff should maybe just be a # warning. outdir = search_dir(problem, configname) if not debug: if os.path.exists(outdir): return "skipped [%s] %s -- dir exists" % (configname, problem) elif not os.path.exists(translate_dir(problem)): return "Translated files for %s not available." % problem elif not os.path.exists(preprocess_dir(problem)): return "Preprocessed files for %s not available." % problem if debug and not os.path.exists(translate_dir(problem)): # Do not abort if translation does not exist. Don't store search output. # (Instead, translate if necessary and always search.) print "Translating and Preprocessing..." success = do_translate(problem) if not success: return "Translating %s failed." % problem success = do_preprocess(problem) if not success: return "Preprocessing %s failed." % problem copy_files(TRANSLATE_OUTPUTS, ".", src_dir=translate_dir(problem)) copy_files(PREPROCESS_OUTPUTS, ".", src_dir=preprocess_dir(problem)) if debug: # Write planner output to screen instead of file. planner = planner_debug_executable() success = benchmark.run( cmd=[planner]+planner_configurations.get_config(configname), timeout=timeout, memory=memory, status="status.log", stdin="output", ) if success: delete_files(["sas_plan"]) delete_files(["status.log"]) else: planner = planner_executable() success = benchmark.run( cmd=[planner]+planner_configurations.get_config(configname), timeout=timeout, memory=memory, status="status.log", stdin="output", stdout="search.log", stderr="search.err", ) if success: move_files(["sas_plan"], outdir) move_files(["search.log", "status.log"], outdir) move_optional_files(["search.err"], outdir) delete_files(PREPROCESS_OUTPUTS) delete_files(TRANSLATE_OUTPUTS) return None
def do_search(problem, configname, timeout, memory, debug=False): # TODO: Currently, do_search returns an error msg on error and # None on no error, while do_translate/do_preprocess return # True/False for success/no success. This should be unified. # Maybe throw exceptions if something goes wrong? Also, # maybe we should allow for warnings in addition to errors. # The "skipped -- dir exists" stuff should maybe just be a # warning. outdir = search_dir(problem, configname) if not debug: if os.path.exists(outdir): return "skipped [%s] %s -- dir exists" % (configname, problem) elif not os.path.exists(translate_dir(problem)): return "Translated files for %s not available." % problem elif not os.path.exists(preprocess_dir(problem)): return "Preprocessed files for %s not available." % problem if debug and not os.path.exists(translate_dir(problem)): # Do not abort if translation does not exist. Don't store search output. # (Instead, translate if necessary and always search.) print "Translating and Preprocessing..." success = do_translate(problem) if not success: return "Translating %s failed." % problem success = do_preprocess(problem) if not success: return "Preprocessing %s failed." % problem copy_files(TRANSLATE_OUTPUTS, ".", src_dir=translate_dir(problem)) copy_files(PREPROCESS_OUTPUTS, ".", src_dir=preprocess_dir(problem)) if debug: # Write planner output to screen instead of file. planner = planner_debug_executable() success = benchmark.run( cmd=[planner] + planner_configurations.get_config(configname), timeout=timeout, memory=memory, status="status.log", stdin="output", ) if success: delete_files(["sas_plan"]) delete_files(["status.log"]) else: planner = planner_executable() success = benchmark.run( cmd=[planner] + planner_configurations.get_config(configname), timeout=timeout, memory=memory, status="status.log", stdin="output", stdout="search.log", stderr="search.err", ) if success: move_files(["sas_plan"], outdir) move_files(["search.log", "status.log"], outdir) move_optional_files(["search.err"], outdir) delete_files(PREPROCESS_OUTPUTS) delete_files(TRANSLATE_OUTPUTS) return None
def do_translate(problem, generate_relaxed_problem=False): executable = translator_executable(relaxed=generate_relaxed_problem) benchmark.run( cmd=[executable, problem.domain_file(), problem.problem_file()], status="status.log", stdout="translate.log", stderr="translate.err", ) outdir = translate_dir(problem) move_files(["translate.log", "status.log"], outdir) if move_optional_files(["translate.err"], outdir): # There was an error. return False else: move_files(TRANSLATE_OUTPUTS, outdir) return True
def do_preprocess(problem): copy_files(TRANSLATE_OUTPUTS, ".", src_dir=translate_dir(problem)) executable = preprocessor_executable() benchmark.run( cmd=[executable], status="status.log", stdin="output.sas", stdout="preprocess.log", stderr="preprocess.err", ) outdir = preprocess_dir(problem) move_files(["preprocess.log", "status.log"], outdir) delete_files(TRANSLATE_OUTPUTS) if move_optional_files(["preprocess.err"], outdir): # There was an error. return False else: move_files(PREPROCESS_OUTPUTS, outdir) return True