aboutsummaryrefslogtreecommitdiff
path: root/src/mlia/core/common.py
blob: 5fbad42fa5fc59d7999d8b2786b3e2937d60cde9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# SPDX-FileCopyrightText: Copyright 2022, Arm Limited and/or its affiliates.
# SPDX-License-Identifier: Apache-2.0
"""Common module.

This module contains common interfaces/classess shared across
core module.
"""
from abc import ABC
from abc import abstractmethod
from enum import Enum
from typing import Any

# This type is used as type alias for the items which are being passed around
# in advisor workflow. There are no restrictions on the type of the
# object. This alias used only to emphasize the nature of the input/output
# arguments.
DataItem = Any


class AdviceCategory(Enum):
    """Advice category.

    Enumeration of advice categories supported by ML Inference Advisor.
    """

    OPERATORS = 1
    PERFORMANCE = 2
    OPTIMIZATION = 3
    ALL = 4

    @classmethod
    def from_string(cls, value: str) -> "AdviceCategory":
        """Resolve enum value from string value."""
        category_names = [item.name for item in AdviceCategory]
        if not value or value.upper() not in category_names:
            raise Exception(f"Invalid advice category {value}")

        return AdviceCategory[value.upper()]


class NamedEntity(ABC):
    """Entity with a name and description."""

    @classmethod
    @abstractmethod
    def name(cls) -> str:
        """Return name of the entity."""