Skip to content

artifact

mlte/value/artifact.py

Artifact implementation for MLTE values.

Value

Bases: Artifact

The Value class serves as the base class of all semantically-enriched measurement evaluation values. The Value provides a common interface for inspecting the results of measurement evaluation, and also encapsulates the functionality required to uniquely associate evaluation results with the originating measurement.

Source code in mlte/value/artifact.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Value(Artifact, metaclass=abc.ABCMeta):
    """
    The Value class serves as the base class of all
    semantically-enriched measurement evaluation values.
    The Value provides a common interface for inspecting
    the results of measurement evaluation, and also
    encapsulates the functionality required to uniquely
    associate evaluation results with the originating measurement.
    """

    def __init__(self, instance: Value, metadata: EvidenceMetadata):
        """
        Initialize a Value instance.
        :param instance: The subclass instance
        :param metadata: Evidence metadata associated with the value
        """
        identifier = f"{metadata.identifier}.value"
        super().__init__(identifier, ArtifactType.VALUE)

        self.metadata = metadata
        """Evidence metadata associated with the value."""

        self.typename: str = type(instance).__name__
        """The type of the value itself."""

    def to_model(self) -> ArtifactModel:
        """
        Convert a value artifact to its corresponding model.
        NOTE: To cope with polymorphism, the Value artifact type
        does not define this required method itself; instead, it
        is delegated to subclasses that implement concrete types
        """
        raise NotImplementedError("Value.to_mode()")

    @classmethod
    def from_model(cls, _: ArtifactModel) -> Value:
        """
        Convert a value model to its corresponding artifact.
        NOTE: To cope with polymorphism, the Value artifact type
        does not define this required method itself; instead, it
        is delegated to subclasses that implement concrete types
        """
        raise NotImplementedError("Value.from_model()")

    @staticmethod
    def load_all() -> list[Value]:
        """Loads all artifact models of the given type for the current session."""
        value_models = Value.load_all_models(ArtifactType.VALUE)
        return Value._load_from_models(value_models)

    @staticmethod
    def load_all_with(context: Context, store: ArtifactStore) -> list[Value]:
        """Loads all artifact models of the given type for the given context and store."""
        value_models = Value.load_all_models_with(
            ArtifactType.VALUE, context, store
        )
        return Value._load_from_models(value_models)

    @staticmethod
    def _load_from_models(value_models: list[ArtifactModel]) -> list[Value]:
        """Converts a list of value models (as Artifact Models) into values."""
        values = []
        for artifact_model in value_models:
            value_model: ValueModel = typing.cast(
                ValueModel, artifact_model.body
            )
            value_type: Value = typing.cast(
                Value, load_class(value_model.value_class)
            )
            value = value_type.from_model(artifact_model)
            values.append(value)
        return values

    @classmethod
    def get_class_path(cls) -> str:
        """Returns the full path to this class, including module."""
        return get_class_path(cls)

metadata = metadata instance-attribute

Evidence metadata associated with the value.

typename = type(instance).__name__ instance-attribute

The type of the value itself.

__init__(instance, metadata)

Initialize a Value instance.

Parameters:

Name Type Description Default
instance Value

The subclass instance

required
metadata EvidenceMetadata

Evidence metadata associated with the value

required
Source code in mlte/value/artifact.py
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def __init__(self, instance: Value, metadata: EvidenceMetadata):
    """
    Initialize a Value instance.
    :param instance: The subclass instance
    :param metadata: Evidence metadata associated with the value
    """
    identifier = f"{metadata.identifier}.value"
    super().__init__(identifier, ArtifactType.VALUE)

    self.metadata = metadata
    """Evidence metadata associated with the value."""

    self.typename: str = type(instance).__name__
    """The type of the value itself."""

from_model(_) classmethod

Convert a value model to its corresponding artifact. NOTE: To cope with polymorphism, the Value artifact type does not define this required method itself; instead, it is delegated to subclasses that implement concrete types

Source code in mlte/value/artifact.py
57
58
59
60
61
62
63
64
65
@classmethod
def from_model(cls, _: ArtifactModel) -> Value:
    """
    Convert a value model to its corresponding artifact.
    NOTE: To cope with polymorphism, the Value artifact type
    does not define this required method itself; instead, it
    is delegated to subclasses that implement concrete types
    """
    raise NotImplementedError("Value.from_model()")

get_class_path() classmethod

Returns the full path to this class, including module.

Source code in mlte/value/artifact.py
96
97
98
99
@classmethod
def get_class_path(cls) -> str:
    """Returns the full path to this class, including module."""
    return get_class_path(cls)

load_all() staticmethod

Loads all artifact models of the given type for the current session.

Source code in mlte/value/artifact.py
67
68
69
70
71
@staticmethod
def load_all() -> list[Value]:
    """Loads all artifact models of the given type for the current session."""
    value_models = Value.load_all_models(ArtifactType.VALUE)
    return Value._load_from_models(value_models)

load_all_with(context, store) staticmethod

Loads all artifact models of the given type for the given context and store.

Source code in mlte/value/artifact.py
73
74
75
76
77
78
79
@staticmethod
def load_all_with(context: Context, store: ArtifactStore) -> list[Value]:
    """Loads all artifact models of the given type for the given context and store."""
    value_models = Value.load_all_models_with(
        ArtifactType.VALUE, context, store
    )
    return Value._load_from_models(value_models)

to_model()

Convert a value artifact to its corresponding model. NOTE: To cope with polymorphism, the Value artifact type does not define this required method itself; instead, it is delegated to subclasses that implement concrete types

Source code in mlte/value/artifact.py
48
49
50
51
52
53
54
55
def to_model(self) -> ArtifactModel:
    """
    Convert a value artifact to its corresponding model.
    NOTE: To cope with polymorphism, the Value artifact type
    does not define this required method itself; instead, it
    is delegated to subclasses that implement concrete types
    """
    raise NotImplementedError("Value.to_mode()")