Example #1
0
 def get_job_metrics(self, request, context):
     with self._app.app_context():
         job = self._check_metrics_public(request, context)
         metrics = JobMetricsBuilder(job).plot_metrics()
         return service_pb2.GetJobMetricsResponse(
             status=common_pb2.Status(code=common_pb2.STATUS_SUCCESS),
             metrics=json.dumps(metrics))
Example #2
0
    def get(self, job_id):
        job = _get_job(job_id)

        metrics = JobMetricsBuilder(job).plot_metrics()

        # Metrics is a list of dict. Each dict can be rendered by frontend with
        #   mpld3.draw_figure('figure1', json)
        return {'data': metrics}
Example #3
0
 def get(self, job_id):
     job = _get_job(job_id)
     try:
         metrics = JobMetricsBuilder(job).plot_metrics()
         # Metrics is a list of dict. Each dict can be rendered by frontend
         # with mpld3.draw_figure('figure1', json)
         return {'data': metrics}
     except Exception as e:  # pylint: disable=broad-except
         abort(400, message=repr(e))
Example #4
0
    def get(self, job_id):
        job = Job.query.filter_by(id=job_id).first()
        if job is None:
            raise NotFoundException()

        metrics = JobMetricsBuilder(job).plot_metrics()

        # Metrics is a list of dict. Each dict can be rendered by frontend with
        #   mpld3.draw_figure('figure1', json)
        return {'data': metrics}
Example #5
0
 def get_job_metrics(self, request, context):
     with self._app.app_context():
         project, party = self.check_auth_info(request.auth_info, context)
         job = Job.query.filter_by(name=request.job_name,
                                   project_id=project.id).first()
         assert job is not None, f'Job {request.job_name} not found'
         workflow = job.workflow
         if not workflow.metric_is_public:
             raise UnauthorizedException('Metric is private!')
         metrics = JobMetricsBuilder(job).plot_metrics()
         return service_pb2.GetJobMetricsResponse(
             status=common_pb2.Status(code=common_pb2.STATUS_SUCCESS),
             metrics=json.dumps(metrics))
Example #6
0
 def on_job_update(self, job):
     model = Model.query.filter_by(job_name=job.name).one()
     # https://code.byted.org/data/fedlearner_web_console_v2/merge_requests/101
     state = job.get_result_state()
     if model.state != ModelState.RUNNING and state == 'RUNNING':
         model.version += 1
     model.state = self.job_state_map[state]
     model.commit()
     if model.state in [
             ModelState.FINISHED, ModelState.SUCCEEDED, ModelState.FAILED
     ]:
         try:
             metrics = JobMetricsBuilder(job).plot_metrics()
             model.metrics = json.dumps(metrics)
             model.commit()
         except Exception as e:
             logging.warning('Error building metrics: %s', repr(e))
Example #7
0
    def query(self, model_id, detail_level=0):
        """
        Query a model

        Args:
            model_id: model id
            detail_level: 0, return basic info; 1, query the es
        Returns:
            return model json
        """
        model = Model.query.filter_by(id=model_id).one()
        model_json = model.to_dict()
        model_json['detail_level'] = detail_level
        if detail_level == 0:
            return model_json
        try:
            job = Job.query.filter_by(name=model.job_name).one()
            metrics = JobMetricsBuilder(job).plot_metrics()
            model_json['metrics'] = json.dumps(metrics)
        except Exception as e:
            logging.warning('Error building metrics: %s', repr(e))
        return model_json
Example #8
0
    def get_job_metrics(self, request, context):
        with self._app.app_context():
            project, party = self.check_auth_info(request.auth_info, context)
            workflow = Workflow.query.filter_by(
                name=request.workflow_name).first()
            assert workflow is not None, \
                f'Workflow {request.workflow_name} not found'
            if not workflow.metric_is_public:
                raise UnauthorizedException('Metric is private!')

            job = None
            for i in workflow.get_jobs():
                if i.get_config().name == request.job_name:
                    job = i
                    break

            assert job is not None, f'Job {request.job_name} not found'

            metrics = JobMetricsBuilder(job).plot_metrics()

            return service_pb2.GetJobMetricsResponse(
                status=common_pb2.Status(code=common_pb2.STATUS_SUCCESS),
                metrics=json.dumps(metrics))
Example #9
0
 def test_nn_metrics(self):
     job = Job(name='automl-2782410011',
               job_type=JobType.NN_MODEL_TRANINING)
     print(JobMetricsBuilder(job).plot_metrics())
Example #10
0
 def test_data_join_metrics(self):
     job = Job(name='multi-indices-test27', job_type=JobType.DATA_JOIN)
     import json
     print(json.dumps(JobMetricsBuilder(job).plot_metrics()))
Example #11
0
 def plot_metrics(self, model, job=None):
     try:
         return JobMetricsBuilder(job or model.job).plot_metrics()
     except Exception as e:
         return repr(e)