예제 #1
0
    def __init__(self, name, task_path, stm_queue = None, solver_id = None):
        # prepare communication channels
        if stm_queue is None:
            self._stm_queue = multiprocessing.Queue()
        else:
            self._stm_queue = stm_queue

        if solver_id is None:
            self._solver_id = uuid.uuid4()
        else:
            self._solver_id = solver_id

        # gather candidate runs, and select one
        runs = []
        answer_map = {"True": True, "False": False}

        with open(task_path + ".rtd.csv") as csv_file:
            reader = csv.reader(csv_file)

            for (solver_name, _, run_budget, run_cost, run_answer) in reader:
                if solver_name == name:
                    run_cost = float(run_cost)
                    run_budget = float(run_budget)

                    if run_budget >= borg.defaults.minimum_fake_run_budget:
                        runs.append((run_cost, answer_map[run_answer]))

        (self._run_cost, self._run_answer) = cargo.grab(runs)
        self._run_position = 0.0
예제 #2
0
파일: portfolios.py 프로젝트: fivejjs/borg
    def __call__(self, task, budget, cores = 1):
        queue = multiprocessing.Queue()
        solvers = []

        for _ in xrange(cores):
            solver_id = uuid.uuid4()
            solver = cargo.grab(self._domain.solvers.values())(task, queue, solver_id)

            solvers.append(solver)

        try:
            for solver in solvers:
                solver.unpause_for(borg.unicore_cpu_budget(budget))

            remaining = len(solvers)

            while remaining > 0:
                (solver_id, run_cpu_cost, answer, _) = queue.get()

                remaining -= 1

                borg.get_accountant().charge_cpu(run_cpu_cost)

                if self._domain.is_final(task, answer):
                    return answer

            return None
        finally:
            for solver in solvers:
                solver.stop()