def main( solvers_path, tasks_root, budget, discard = False, runs = 4, only_solver = None, suffix = ".runs.csv", workers = 0, ): """Collect solver running-time data.""" cargo.enable_default_logging() def yield_runs(): bundle = borg.load_solvers(solvers_path) paths = list(cargo.files_under(tasks_root, bundle.domain.extensions)) if not paths: raise ValueError("no paths found under specified root") if only_solver is None: solver_names = bundle.solvers.keys() else: if only_solver not in bundle.solvers: raise ArgumentError("no such solver") solver_names = [only_solver] for _ in xrange(runs): for solver_name in solver_names: for path in paths: yield (run_solver_on, [solvers_path, solver_name, path, budget]) def collect_run(task, row): if not discard: # unpack run outcome (solver_name, budget, cost, succeeded, answer) = row if answer is None: answer_text = None else: answer_text = base64.b64encode(zlib.compress(pickle.dumps(answer))) # write it to disk (_, _, cnf_path, _) = task.args csv_path = cnf_path + suffix existed = os.path.exists(csv_path) with open(csv_path, "a") as csv_file: writer = csv.writer(csv_file) if not existed: writer.writerow(["solver", "budget", "cost", "succeeded", "answer"]) writer.writerow([solver_name, budget, cost, succeeded, answer_text]) cargo.do_or_distribute(yield_runs(), workers, collect_run)
with domain.task_from_path(task_path) as task: return domain.compute_features(task) @plac.annotations( domain_name=("name of the problem domain",), tasks_root=("path to task files", "positional", None, os.path.abspath), workers=("submit jobs?", "option", "w", int), ) def main(domain_name, tasks_root, workers=0): """Collect task features.""" cargo.enable_default_logging() def yield_runs(): domain = borg.get_domain(domain_name) paths = list(cargo.files_under(tasks_root, domain.extensions)) for path in paths: yield (features_for_path, [domain, path]) def collect_run(task, (names, values)): (_, cnf_path) = task.args csv_path = cnf_path + ".features.csv" with open(csv_path, "w") as csv_file: csv.writer(csv_file).writerow(names) csv.writer(csv_file).writerow(values) cargo.do_or_distribute(yield_runs(), workers, collect_run)