Example #1
0
        def _cmp(obj1: LineageObj, obj2: LineageObj):
            value1 = obj1.get_value_by_key(sorted_name)
            value2 = obj2.get_value_by_key(sorted_name)

            if value1 is None and value2 is None:
                cmp_result = 0
            elif value1 is None:
                cmp_result = -1
            elif value2 is None:
                cmp_result = 1
            else:
                cmp_result = (value1 > value2) - (value1 < value2)

            return cmp_result
Example #2
0
    def _parse_summary_log(self, log_path, index: int, is_save_fail_path=True):
        """
        Parse the single summary log.

        Args:
            log_path (str): The single summary log path.
            index (int): TrainInfo instance index in the train info list.
            is_save_fail_path (bool): Set whether to save the failed summary
                path. Default: True.

        Returns:
            bool, `True` if parse summary log success, else `False`.
        """
        log_dir = os.path.dirname(log_path)
        try:
            lineage_info = LineageSummaryAnalyzer.get_summary_infos(log_path)
            lineage_obj = LineageObj(
                log_dir,
                train_lineage=lineage_info.train_lineage,
                evaluation_lineage=lineage_info.eval_lineage,
                dataset_graph=lineage_info.dataset_graph)
            self._lineage_objects.append(lineage_obj)
            self._add_dataset_mark()
            self._index_map[log_dir] = index
            return True
        except (LineageSummaryAnalyzeException, LineageEventNotExistException,
                LineageEventFieldNotExistException):
            if is_save_fail_path:
                self._parse_failed_paths.append(log_path)
            return False
Example #3
0
    def setUp(self):
        """Initialization before test case execution."""
        lineage_info = create_lineage_info(event_data.EVENT_TRAIN_DICT_0,
                                           event_data.EVENT_EVAL_DICT_0,
                                           event_data.EVENT_DATASET_DICT_0)
        self.summary_dir = '/path/to/summary0'
        self.lineage_obj = LineageObj(
            self.summary_dir,
            train_lineage=lineage_info.train_lineage,
            evaluation_lineage=lineage_info.eval_lineage,
            dataset_graph=lineage_info.dataset_graph,
        )

        lineage_info = create_lineage_info(event_data.EVENT_TRAIN_DICT_0, None,
                                           None)
        self.lineage_obj_no_eval = LineageObj(
            self.summary_dir,
            train_lineage=lineage_info.train_lineage,
            evaluation_lineage=lineage_info.eval_lineage)
Example #4
0
    def test_init_fail(self):
        """Test the function of init with exception."""
        with self.assertRaises(LineageEventNotExistException):
            LineageObj(self.summary_dir)

        lineage_info = create_lineage_info(
            event_data.EVENT_TRAIN_DICT_EXCEPTION, None, None)
        with self.assertRaises(LineageEventFieldNotExistException):
            self.lineage_obj = LineageObj(
                self.summary_dir,
                train_lineage=lineage_info.train_lineage,
                evaluation_lineage=lineage_info.eval_lineage)

        lineage_info = create_lineage_info(
            event_data.EVENT_TRAIN_DICT_0,
            event_data.EVENT_EVAL_DICT_EXCEPTION,
            event_data.EVENT_DATASET_DICT_0)
        with self.assertRaises(LineageEventFieldNotExistException):
            self.lineage_obj = LineageObj(
                self.summary_dir,
                train_lineage=lineage_info.train_lineage,
                evaluation_lineage=lineage_info.eval_lineage)
Example #5
0
 def _update_lineage_obj(self, lineage_info, user_defined_info):
     """Update lineage object."""
     if self._super_lineage_obj is None:
         lineage_obj = LineageObj(
             self._summary_dir,
             train_lineage=lineage_info.train_lineage,
             evaluation_lineage=lineage_info.eval_lineage,
             dataset_graph=lineage_info.dataset_graph,
             user_defined_info=user_defined_info)
         self._super_lineage_obj = SuperLineageObj(lineage_obj,
                                                   self.update_time,
                                                   self._added_info)
     else:
         self._super_lineage_obj.lineage_obj.parse_and_update_lineage(
             train_lineage=lineage_info.train_lineage,
             evaluation_lineage=lineage_info.eval_lineage,
             dataset_graph=lineage_info.dataset_graph,
             user_defined_info=user_defined_info)
Example #6
0
        def _filter(lineage_obj: LineageObj):
            for condition_key, condition_value in condition.items():
                if ConditionParam.is_condition_type(condition_key):
                    continue
                if self._is_valid_field(condition_key):
                    raise LineageQuerierParamException(
                        'condition',
                        'The field {} not supported'.format(condition_key))

                value = lineage_obj.get_value_by_key(condition_key)
                for exp_key, exp_value in condition_value.items():
                    if not ExpressionType.is_valid_exp(exp_key):
                        raise LineageQuerierParamException(
                            'condition',
                            'The expression {} not supported.'.format(exp_key))
                    if not ExpressionType.is_match(exp_key, exp_value, value):
                        return False
            return True
Example #7
0
class TestLineageObj(TestCase):
    """Test the class of `LineageObj`."""
    def setUp(self):
        """Initialization before test case execution."""
        lineage_info = create_lineage_info(event_data.EVENT_TRAIN_DICT_0,
                                           event_data.EVENT_EVAL_DICT_0,
                                           event_data.EVENT_DATASET_DICT_0)
        self.summary_dir = '/path/to/summary0'
        self.lineage_obj = LineageObj(
            self.summary_dir,
            train_lineage=lineage_info.train_lineage,
            evaluation_lineage=lineage_info.eval_lineage,
            dataset_graph=lineage_info.dataset_graph,
        )

        lineage_info = create_lineage_info(event_data.EVENT_TRAIN_DICT_0, None,
                                           None)
        self.lineage_obj_no_eval = LineageObj(
            self.summary_dir,
            train_lineage=lineage_info.train_lineage,
            evaluation_lineage=lineage_info.eval_lineage)

    def test_property(self):
        """Test the function of getting property."""
        self.assertEqual(self.summary_dir, self.lineage_obj.summary_dir)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['algorithm'],
            self.lineage_obj.algorithm)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['model'],
            self.lineage_obj.model)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['train_dataset'],
            self.lineage_obj.train_dataset)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['hyper_parameters'],
            self.lineage_obj.hyper_parameters)
        self.assertDictEqual(event_data.METRIC_0, self.lineage_obj.metric)
        self.assertDictEqual(
            event_data.EVENT_EVAL_DICT_0['evaluation_lineage']
            ['valid_dataset'], self.lineage_obj.valid_dataset)

    def test_property_eval_not_exist(self):
        """Test the function of getting property with no evaluation event."""
        self.assertEqual(self.summary_dir, self.lineage_obj.summary_dir)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['algorithm'],
            self.lineage_obj_no_eval.algorithm)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['model'],
            self.lineage_obj_no_eval.model)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['train_dataset'],
            self.lineage_obj_no_eval.train_dataset)
        self.assertDictEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['hyper_parameters'],
            self.lineage_obj_no_eval.hyper_parameters)
        self.assertDictEqual({}, self.lineage_obj_no_eval.metric)
        self.assertDictEqual({}, self.lineage_obj_no_eval.valid_dataset)

    def test_get_summary_info(self):
        """Test the function of get_summary_info."""
        filter_keys = ['algorithm', 'model']
        expected_result = {
            'summary_dir':
            self.summary_dir,
            'algorithm':
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['algorithm'],
            'model':
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['model']
        }
        result = self.lineage_obj.get_summary_info(filter_keys)
        self.assertDictEqual(expected_result, result)

    def test_to_filtration_dict(self):
        """Test the function of to_filtration_dict."""
        expected_result = create_filtration_result(
            self.summary_dir, event_data.EVENT_TRAIN_DICT_0,
            event_data.EVENT_EVAL_DICT_0, event_data.METRIC_0,
            event_data.DATASET_DICT_0)
        expected_result['dataset_mark'] = None
        result = self.lineage_obj.to_filtration_dict()
        self.assertDictEqual(expected_result, result)

    def test_get_value_by_key(self):
        """Test the function of get_value_by_key."""
        result = self.lineage_obj.get_value_by_key('model_size')
        self.assertEqual(
            event_data.EVENT_TRAIN_DICT_0['train_lineage']['model']['size'],
            result)

    def test_init_fail(self):
        """Test the function of init with exception."""
        with self.assertRaises(LineageEventNotExistException):
            LineageObj(self.summary_dir)

        lineage_info = create_lineage_info(
            event_data.EVENT_TRAIN_DICT_EXCEPTION, None, None)
        with self.assertRaises(LineageEventFieldNotExistException):
            self.lineage_obj = LineageObj(
                self.summary_dir,
                train_lineage=lineage_info.train_lineage,
                evaluation_lineage=lineage_info.eval_lineage)

        lineage_info = create_lineage_info(
            event_data.EVENT_TRAIN_DICT_0,
            event_data.EVENT_EVAL_DICT_EXCEPTION,
            event_data.EVENT_DATASET_DICT_0)
        with self.assertRaises(LineageEventFieldNotExistException):
            self.lineage_obj = LineageObj(
                self.summary_dir,
                train_lineage=lineage_info.train_lineage,
                evaluation_lineage=lineage_info.eval_lineage)