Пример #1
0
    def run_task(task_id):
        task = ts.get_task_by_id(task_id)
        if not task or task.state != "generated":
            return False

        t_change = task.make_runnable()
        a_task = ats.get_task_by_id(task.assemble_task_id)
        success = True
        if a_task.is_completed():
            t_change.update(task.completed(task.assemble_task_id))

        else:
            a_task_change = a_task.make_runnable()
            success = ats.update_task(a_task_change, task.assemble_task_id)

        if success and task.learn_task_id:
            l_task = lts.get_task_by_id(task.learn_task_id)
            if l_task.is_completed():
                t_change = task.completed(task.learn_task_id)

            else:
                l_task_change = l_task.make_runnable()
                success = lts.update_task(l_task_change, task.learn_task_id)

        if success:
            success = ts.update_task(t_change, task_id)

        return success
Пример #2
0
    def load_task_from_db(task_id):
        task = ts.get_task_by_id(task_id)
        result = {
            "id": task_id,
            "state": task.state,
            "order_in_exp": task.order_in_exp,
            "status_info": "Task Completed" if task.state == "completed" else "Run task",
        }
        assemble_task = ats.get_task_by_id(task.assemble_task_id)
        if task.learn_task_id:
            learn_task = lts.get_task_by_id(task.learn_task_id)
            result["learn_config"] = learn_task.learn_config
            if task.state == "runnable" or task.state == "running":
                if learn_task.state == "runnable":
                    result["status_info"] = "Learning is waiting for worker"

                elif learn_task.state == "running":
                    result["status_info"] = "Learning is in progress"

        result["assemble_config"] = assemble_task.assemble_config
        if task.state == "runnable" or task.state == "running":
            if assemble_task.state == "runnable":
                result["status_info"] = "Assembling is waiting for worker"

            elif assemble_task.state == "running":
                result["status_info"] = "Assembling is in progress"

        return result
Пример #3
0
    def load_task(task_id):
        task = ts.get_task_by_id(task_id)
        exp = es.get_experiment(task.experiment_id)
        result = task.__dict__
        result['experiment_name'] = exp.name
        a_task = ats.get_task_by_id(task.assemble_task_id)
        result['assemble_config'] = a_task.assemble_config
        if not a_task.is_completed():
            result['assigned_to'] = a_task.assigned_to

        else:
            result['result'] = a_task.result_file_path

        result['progress'] = a_task.progress or 0.0
        result['task_in_progress'] = 'assembling'
        if task.learn_task_id:
            l_task = lts.get_task_by_id(task.learn_task_id)
            result['assemble_config'] = l_task.assemble_config
            result['learn_config'] = l_task.learn_config
            result['progress'] = round(
                (((a_task.progress or 0.0) +
                  (l_task.progress or 0.0)) / 2.0) * 100, 2)
            result[
                'task_in_progress'] = 'learning' if l_task.state == "running" or a_task.state == "completed" else 'assembling'
            result['result'] = l_task.result
            if l_task.assigned_to and not l_task.is_completed():
                result['assigned_to'] = l_task.assigned_to

        return result
Пример #4
0
    def load_experiment(exp_id):
        exp = es.get_experiment(exp_id)
        if exp:
            tasks = []
            only_assembling = True
            for task_id in exp.tasks:
                task = ts.get_task_by_id(task_id)
                if task.learn_task_id:
                    only_assembling = False
                    l_task = lts.get_task_by_id(task.learn_task_id)
                    if l_task.result:
                        tasks.append({
                            'id': task_id,
                            'name': f'{l_task.assemble_config["strategy_name"]} + {l_task.learn_config["strategy_name"]}',
                            'result': l_task.result,
                        })

            if only_assembling:
                return None, 'No learning task in experiment.'

            if tasks:
                return {'tasks': tasks}, ''

            return None, 'No task completed yet.'

        return None, None
Пример #5
0
    def persist_result(job_type, task_store, task_id, get_result_func, result):
        try:
            result = get_result_func(result)
            if result:
                experiments = {}
                task = task_store.get_task_by_id(task_id)
                change = task.completed(result)
                success = task_store.update_task(change, task_id)
                parent_tasks = [(t_id, ts.get_task_by_id(t_id)) for t_id in task.parent_tasks]
                for p_task_id, p_task in parent_tasks:
                    if p_task.experiment_id in experiments:
                        exp = experiments[p_task.experiment_id]

                    else:
                        exp = ess.get_experiment_summary(p_task.experiment_id)
                        if exp:
                            experiments[p_task.experiment_id] = exp

                    if job_type == "assembling":
                        exp_change = exp.set_assemble_result(p_task_id, result)

                    else:
                        exp_change = exp.set_learn_result(p_task_id, result)

                    success = success and ess.update_experiment_summary(exp_change, p_task.experiment_id)
                    change = p_task.completed(task_id)
                    success = success and ts.update_task(change, p_task_id)

                return success

        except Exception as e:
            return False
Пример #6
0
    def _stop_task(self, task_id):
        task = ts.get_task_by_id(task_id)

        if task.state != "running":
            return None

        task_changes = task.stop()
        success = ts.update_task(task_changes, task_id)
        self._stop_sub_task(task.assemble_task_id, ats, True)
        if task.learn_task_id:
            self._stop_sub_task(task.learn_task_id, lts, False)

        return success
Пример #7
0
    def load_experiments():
        exp_list = es.list_experiments()
        result = []
        for exp_id, exp in exp_list:
            task_list = [ts.get_task_by_id(t_id) for t_id in exp.tasks]
            exp_dict = exp.__dict__
            exp_dict['tasks_running'] = len([t for t in task_list if t.state == "running"])
            exp_dict['tasks_completed'] = len([t for t in task_list if t.state == "completed"])
            exp_dict['tasks_total'] = len(task_list)
            exp_dict['progress'] = round((exp.tasks_completed / (exp.tasks_total or 1)) * 100, 2)
            result.append((exp_id, exp_dict))

        return result
Пример #8
0
    def reorder_task(task_id, direction):
        try:
            task = ts.get_task_by_id(task_id)
            task_order = task.order_in_exp
            swap_order = task_order + (-1 if direction else 1)
            swap_task_id, swap_task = ts.search_task_by_dict({
                'order_in_exp': swap_order,
                'experiment_id': task.experiment_id,
            })
            task_changes = task.set_order_in_exp(swap_order)
            success = ts.update_task(task_changes, task_id)
            swap_task_changes = swap_task.set_order_in_exp(task_order)
            return ts.update_task(swap_task_changes, swap_task_id) and success

        except Exception as e:
            pass

        return False
Пример #9
0
    def _rerun_task(task_id):
        task = ts.get_task_by_id(task_id)

        if task.state != "completed":
            return None, None, None, None

        new_a_task_id, new_a_task = ats.rerun_task(task.assemble_task_id)
        if not new_a_task:
            return None, None, None, None

        if task.learn_task_id:
            new_l_task_id, new_l_task = lts.rerun_task(task.learn_task_id, new_a_task_id)
            task_changes = task.re_run(new_a_task_id, new_l_task_id)
            return ts.update_task(task_changes, task_id), task, new_a_task, new_l_task

        else:
            task_changes = task.re_run(new_a_task_id, None)
            return ts.update_task(task_changes, task_id), task, new_a_task, None
    def load_worker(worker_id):
        worker = ws.get_worker(worker_id)
        result = worker.__dict__
        if worker.current_task_id:
            task = ats.get_task_by_id(worker.current_task_id)
            if task:
                result['is_assembling'] = True

            else:
                task = lts.get_task_by_id(worker.current_task_id)

            parent_tasks = [(t_id, ts.get_task_by_id(t_id))
                            for t_id in task.parent_tasks]
            running_task_ids = [
                t_id for t_id, t in parent_tasks if t.state == "running"
            ]
            result['task_ids'] = running_task_ids
            if len(running_task_ids) > 1:
                result['is_working_on_multiple_tasks'] = True

            result['log'] = task.log

        return result