Skip to content

unavailable

An Evidence instance for a problem in the measurement process that resulted in unavailable evidence.

Unavailable

Bases: Evidence

Implements the Evidence interface for evidence that could not be obtained due to a problem.

Source code in mlte/evidence/unavailable.py
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
class Unavailable(Evidence):
    """
    Implements the Evidence interface for evidence that could not be obtained due to a problem.
    """

    def __init__(self, details: str, traceback: str | None):
        """
        Initialize an instance.
        :param details: The failure details.
        """
        assert isinstance(details, str), "Argument must be `string`."
        super().__init__()

        self.details = details
        """The details."""

        self.traceback = traceback
        """Detailed traceback."""

    def to_model(self) -> ArtifactModel:
        """
        Convert a value artifact to its corresponding model.
        :return: The artifact model
        """
        return self._to_artifact_model(
            value_model=UnavailableValueModel(
                details=self.details, traceback=self.traceback
            )
        )

    @classmethod
    def from_model(cls, model: BaseModel) -> Unavailable:
        """
        Convert a value model to its corresponding artifact.
        :param model: The model representation
        :return: The failed value
        """
        body = cls._check_proper_types(model, EvidenceType.UNAVAILABLE)
        return Unavailable(
            details=body.value.details,  # type: ignore
            traceback=body.value.traceback,  # type: ignore
        ).with_metadata(body.metadata)

    def __eq__(self, other: object) -> bool:
        """Comparison between values."""
        if not isinstance(other, Unavailable):
            return False
        return self._equal(other)

    def __str__(self) -> str:
        """Return a string representation of this Evidence."""
        return f"{self.details}"

    # Overriden.
    @classmethod
    def load(cls, identifier: str | None = None) -> Unavailable:
        evidence = super().load(identifier)
        return typing.cast(Unavailable, evidence)

details = details instance-attribute

The details.

traceback = traceback instance-attribute

Detailed traceback.

__eq__(other)

Comparison between values.

Source code in mlte/evidence/unavailable.py
70
71
72
73
74
def __eq__(self, other: object) -> bool:
    """Comparison between values."""
    if not isinstance(other, Unavailable):
        return False
    return self._equal(other)

__init__(details, traceback)

Initialize an instance.

Parameters:

Name Type Description Default
details str

The failure details.

required
Source code in mlte/evidence/unavailable.py
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(self, details: str, traceback: str | None):
    """
    Initialize an instance.
    :param details: The failure details.
    """
    assert isinstance(details, str), "Argument must be `string`."
    super().__init__()

    self.details = details
    """The details."""

    self.traceback = traceback
    """Detailed traceback."""

__str__()

Return a string representation of this Evidence.

Source code in mlte/evidence/unavailable.py
76
77
78
def __str__(self) -> str:
    """Return a string representation of this Evidence."""
    return f"{self.details}"

from_model(model) classmethod

Convert a value model to its corresponding artifact.

Parameters:

Name Type Description Default
model BaseModel

The model representation

required

Returns:

Type Description
Unavailable

The failed value

Source code in mlte/evidence/unavailable.py
57
58
59
60
61
62
63
64
65
66
67
68
@classmethod
def from_model(cls, model: BaseModel) -> Unavailable:
    """
    Convert a value model to its corresponding artifact.
    :param model: The model representation
    :return: The failed value
    """
    body = cls._check_proper_types(model, EvidenceType.UNAVAILABLE)
    return Unavailable(
        details=body.value.details,  # type: ignore
        traceback=body.value.traceback,  # type: ignore
    ).with_metadata(body.metadata)

to_model()

Convert a value artifact to its corresponding model.

Returns:

Type Description
ArtifactModel

The artifact model

Source code in mlte/evidence/unavailable.py
46
47
48
49
50
51
52
53
54
55
def to_model(self) -> ArtifactModel:
    """
    Convert a value artifact to its corresponding model.
    :return: The artifact model
    """
    return self._to_artifact_model(
        value_model=UnavailableValueModel(
            details=self.details, traceback=self.traceback
        )
    )

UnavailableException

Bases: Exception

Exception raised when an unavailable evidence is found while processing evidence.

Attributes: unavailable -- the encapsulated Unavailable object

Source code in mlte/evidence/unavailable.py
15
16
17
18
19
20
21
22
23
24
class UnavailableException(Exception):
    """Exception raised when an unavailable evidence is found while processing evidence.

    Attributes:
        unavailable -- the encapsulated Unavailable object
    """

    def __init__(self, unavailable: Unavailable):
        self.unavailable = unavailable
        super().__init__(f"Evidence gathering failed: {unavailable.details}")