예제 #1
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
예제 #2
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
예제 #3
0
    def post(copy_id=None, edit_id=None):
        try:
            if not request.form:
                abort(403, message='missing form')

            orig_exp = es.get_experiment(edit_id or copy_id)
            if edit_id:
                experiment_id = edit_id
                success = es.edit_experiment(
                    edit_id, request.form['experiment_name'],
                    request.form['markdown'],
                    int(request.form['experiment_priority']))

            else:
                experiment_id = es.new_experiment(
                    request.form['experiment_name'], request.form['markdown'],
                    int(request.form['experiment_priority']), copy_id)

            if experiment_id:
                return redirect(
                    url_for('manage_experiment', hash=experiment_id))

            abort(403, message="Couldn't save to elastic")

        except Exception as e:
            if config.debug_mode:
                abort(400, message=str(e))

            else:
                abort(404, message="Page not found")
예제 #4
0
    def get(self, copy_id=None, edit_id=None):
        try:
            if copy_id or edit_id:
                exp = es.get_experiment(copy_id or edit_id)
                return self.make_response("copy" if copy_id else "edit",
                                          exp.name, exp.markdown, exp.priority)

            return self.make_response("new", "", "", Priority.NORMAL)

        except Exception as e:
            if config.debug_mode:
                abort(400, message=str(e))

            else:
                abort(404, message="Page not found")
예제 #5
0
    def post():
        try:
            e = es.get_experiment(request.json['hash'])
            change = e.remove_config(request.json['id'])
            if change:
                es_id = es.update_experiment(change, request.json['hash'])
                if es_id:
                    return make_response(request.json['id'])

            return make_response('', 200)

        except Exception as e:
            if config.debug_mode:
                abort(400, message=str(e))

            else:
                abort(404, message="Page not found")
예제 #6
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)
                parents = ts.get_assembling_parents(
                    task_id
                ) if job_type == "assembling" else ts.get_learning_parents(
                    task_id)
                for p_task_id, p_task in parents:
                    change = p_task.completed(task_id)
                    success = ts.update_task(change, p_task_id) and success
                    if p_task.experiment_id in experiments:
                        exp_sum = experiments[p_task.experiment_id]

                    else:
                        if p_task.learn_task_id:
                            exp = es.get_experiment(p_task.experiment_id)
                            if exp:
                                scheduler.check_experiment(
                                    p_task.experiment_id, exp.priority)

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

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

                    else:
                        exp_change = exp_sum.set_learn_result(
                            p_task_id, result) if exp_sum else None

                    if exp_change:
                        success = ess.update_experiment_summary(
                            exp_change, p_task.experiment_id) and success

                return bool(success)

        except Exception as e:
            return False
예제 #7
0
    def get(self, hash):
        try:
            experiment = es.get_experiment(hash)
            return make_response(
                render_template(
                    'experiment/manage.j2',
                    hash=hash,
                    experiment=self.load_experiment(experiment)
                ),
                200,
                {'Content-Type': 'text/html'}
            )

        except Exception as e:
            if config.debug_mode:
                abort(400, message=str(e))

            else:
                abort(404, message="Page not found")
    def post(hash):
        try:
            if not request.form:
                abort(403, message='missing form')

            learn_config_list = cb.generate_learn_configs(
                form_data=request.form)
            learn_config_id_list = [
                scs.new_config(c) for c in learn_config_list
            ]
            e = es.get_experiment(hash)
            changes = e.add_learn_config_list(learn_config_id_list)
            success = es.update_experiment(changes, hash)
            if success:
                return redirect(url_for('manage_experiment', hash=hash))

            abort(403, message="Couldn't save to elastic")

        except Exception as e:
            if config.debug_mode:
                abort(400, message=str(e))

            else:
                abort(400, message="something went wrong")
예제 #9
0
def _remove_task(worker_id, worker):
    try:
        a_task = ats.get_task_by_id(worker.current_task_id)
        if not a_task:
            l_task = lts.get_task_by_id(worker.current_task_id)

        task_changes = (a_task or l_task).revoke_assign_from(worker_id)
        success = ats.update_task(
            task_changes,
            worker.current_task_id) if a_task else lts.update_task(
                task_changes, worker.current_task_id)
        parents = ts.get_assembling_parents(
            worker.current_task_id) if a_task else ts.get_learning_parents(
                worker.current_task_id)
        for pt_id, parent in parents:
            t_change = parent.make_runnable(True)
            success = ts.update_task(t_change, pt_id) and success
            exp = es.get_experiment(parent.experiment_id)
            scheduler.add_experiment(parent.experiment_id, exp.priority)

        return success

    except Exception as e:
        return None
예제 #10
0
    def post(self, hash):
        try:
            experiment = es.get_experiment(hash)
            if request.json['command'] == 'generate_tasks':
                success = self.generate_tasks(experiment, hash)
                return make_response("generate_tasks_success" if success else "generate_tasks_need_assembling", 200)

            elif request.json['command'] == 'run_all':
                success = self.run_all_tasks(experiment)
                if success:
                    scheduler.add_experiment(hash, experiment.priority)

                return make_response("run_success" if success else "run_failed", 200)

            elif request.json['command'] == 'run_task':
                success = self.run_task(request.json['id'])
                if success:
                    scheduler.add_experiment(hash, experiment.priority)

                return make_response("run_success" if success else "run_failed", 200)

            elif request.json['command'] == 'rerun_all':
                success = self.rerun_all_tasks(experiment, hash)
                if success:
                    scheduler.add_experiment(hash, experiment.priority)

                return make_response("rerun_success" if success else "rerun_failed", 200)

            elif request.json['command'] == 'rerun_task':
                success = self.rerun_task(hash, request.json['id'])
                if success:
                    scheduler.add_experiment(hash, experiment.priority)

                return make_response("rerun_success" if success else "rerun_failed", 200)

            elif request.json['command'] == 'stop_all':
                success = self.stop_all_tasks(experiment)
                if success:
                    scheduler.remove_experiment(hash)

                return make_response("stop_success" if success else "stop_failed", 200)

            elif request.json['command'] == 'stop_task':
                success = self.stop_task(request.json['id'])
                scheduler.check_experiment(hash, experiment.priority)
                return make_response("stop_success" if success else "stop_failed", 200)

            elif request.json['command'] == 'reorder_task':
                success = self.reorder_task(request.json['id'], request.json['direction'] == "up")
                return make_response("reorder_success" if success else "reorder_failed", 200)

            elif request.json['command'] == 'delete_experiment':
                success = self.stop_all_tasks(experiment)
                if success:
                    scheduler.remove_experiment(hash)

                success = success and es.delete_experiment(hash)
                success = success and ts.delete_tasks_by_experiment(hash)
                if ess.get_experiment_summary(hash):
                    success = success and ess.delete_experiment_summary(hash)

                return make_response(f"delete_success" if success else f"delete_failed", 200)

            else:
                abort(400, message="Unknown command.")

        except Exception as e:
            if config.debug_mode:
                abort(400, message=str(e))

            else:
                abort(404, message="Page not found")