Skip to content

artifact

Artifact implementation for MLTE report.

Report

Bases: Artifact

The report artifact contains the results of MLTE model evaluation.

Source code in mlte/report/artifact.py
 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
class Report(Artifact):
    """The report artifact contains the results of MLTE model evaluation."""

    type = ArtifactType.REPORT
    """Class attribute indicating type."""

    def __init__(
        self,
        identifier: Optional[str] = None,
        negotiation_card_id: str = NegotiationCard.build_full_id(),
        negotiation_card_model: Optional[NegotiationCardModel] = None,
        test_suite_id: str = TestSuite.build_full_id(),
        test_suite_model: Optional[TestSuiteModel] = None,
        test_results_id: str = TestResults.build_full_id(),
        test_results_model: Optional[TestResultsModel] = None,
        comments: List[CommentDescriptor] = [],
    ) -> None:
        """
        Creates a Report.

        :param identifier: The Report id (default value used if not provided).
        :param negotiation_card_id: The id of the negotiation card to use (defaults to default card id).
        :param negotiation_card_model: A NegotiationCardModel object; if None, NegotiationCard from the provided id will be loaded.
        :param test_suite_id: The id of the test suite to use (defaults to default suite id).
        :param test_suite_model: A TestSuiteModel object; if None, TestSuite from the provided id will be loaded.
        :param test_results_id: The id of the test results to use (defaults to default results id).
        :param test_results_model: A TestResultsModel object; if None, TestResults from the provided id will be loaded.
        :param comments: Optional comments to add.
        """
        super().__init__(identifier)

        self.negotiation_card_id = negotiation_card_id
        self.negotiation_card_model = (
            negotiation_card_model
            if negotiation_card_model
            else typing.cast(
                NegotiationCardModel,
                NegotiationCard.load(negotiation_card_id).to_model().body,
            )
        )
        """The Negotiation Card with the requirements."""

        self.test_suite_id = test_suite_id
        self.test_suite_model = (
            test_suite_model
            if test_suite_model
            else typing.cast(
                TestSuiteModel, TestSuite.load(test_suite_id).to_model().body
            )
        )
        """The test suite used to generate these results."""

        self.test_results_id = test_results_id
        self.test_results_model = (
            test_results_model
            if test_results_model
            else typing.cast(
                TestResultsModel,
                TestResults.load(test_results_id).to_model().body,
            )
        )
        """A summary of model performance evaluation."""

        self.comments = comments
        """A collection of comments for the report."""

    def to_model(self) -> ArtifactModel:
        """Convert a report artifact to its corresponding model."""
        return ArtifactModel(
            header=self.build_artifact_header(),
            body=ReportModel(
                negotiation_card_id=self.negotiation_card_id,
                negotiation_card=self.negotiation_card_model,
                test_suite_id=self.test_suite_id,
                test_suite=self.test_suite_model,
                test_results_id=self.test_results_id,
                test_results=self.test_results_model,
                comments=self.comments,
            ),
        )

    @classmethod
    def from_model(cls, model: BaseModel) -> Report:
        """Convert a report model to its corresponding artifact."""
        assert isinstance(
            model, ArtifactModel
        ), "Can't create object from non-ArtifactModel model."
        assert (
            model.header.type == ArtifactType.REPORT
        ), "Type should be Report."
        body = typing.cast(ReportModel, model.body)
        return Report(
            identifier=model.header.identifier,
            negotiation_card_id=body.negotiation_card_id,
            negotiation_card_model=body.negotiation_card,
            test_suite_id=body.test_suite_id,
            test_suite_model=body.test_suite,
            test_results_id=body.test_results_id,
            test_results_model=body.test_results,
            comments=body.comments,
        )

    # Overriden.
    @classmethod
    def load(cls, identifier: typing.Optional[str] = None) -> Report:
        """
        Load a Report from the configured global session.
        :param identifier: The identifier for the artifact. If None,
        the default id is used.
        """
        report = super().load(identifier)
        return typing.cast(Report, report)

    # Overriden.
    def pre_save_hook(self, context: Context, store: ArtifactStore) -> None:
        """
        Override Artifact.pre_save_hook(). Assigns time-stamped id to report, to ensure all have different ids.
        :param context: The context in which to save the artifact
        :param store: The store in which to save the artifact
        :raises RuntimeError: On broken invariant
        """
        self.identifier = f"{self.identifier}-{datetime.datetime.now().strftime('%Y%m%d-%H%M%S')}"

    # ----------------------------------------------------------------------------------
    # Helper methods.
    # ----------------------------------------------------------------------------------

    def __eq__(self, other: object) -> bool:
        if not isinstance(other, Report):
            return False
        return self._equal(other)

comments = comments instance-attribute

A collection of comments for the report.

negotiation_card_model = negotiation_card_model if negotiation_card_model else typing.cast(NegotiationCardModel, NegotiationCard.load(negotiation_card_id).to_model().body) instance-attribute

The Negotiation Card with the requirements.

test_results_model = test_results_model if test_results_model else typing.cast(TestResultsModel, TestResults.load(test_results_id).to_model().body) instance-attribute

A summary of model performance evaluation.

test_suite_model = test_suite_model if test_suite_model else typing.cast(TestSuiteModel, TestSuite.load(test_suite_id).to_model().body) instance-attribute

The test suite used to generate these results.

type = ArtifactType.REPORT class-attribute instance-attribute

Class attribute indicating type.

__init__(identifier=None, negotiation_card_id=NegotiationCard.build_full_id(), negotiation_card_model=None, test_suite_id=TestSuite.build_full_id(), test_suite_model=None, test_results_id=TestResults.build_full_id(), test_results_model=None, comments=[])

Creates a Report.

Parameters:

Name Type Description Default
identifier Optional[str]

The Report id (default value used if not provided).

None
negotiation_card_id str

The id of the negotiation card to use (defaults to default card id).

build_full_id()
negotiation_card_model Optional[NegotiationCardModel]

A NegotiationCardModel object; if None, NegotiationCard from the provided id will be loaded.

None
test_suite_id str

The id of the test suite to use (defaults to default suite id).

build_full_id()
test_suite_model Optional[TestSuiteModel]

A TestSuiteModel object; if None, TestSuite from the provided id will be loaded.

None
test_results_id str

The id of the test results to use (defaults to default results id).

build_full_id()
test_results_model Optional[TestResultsModel]

A TestResultsModel object; if None, TestResults from the provided id will be loaded.

None
comments List[CommentDescriptor]

Optional comments to add.

[]
Source code in mlte/report/artifact.py
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
def __init__(
    self,
    identifier: Optional[str] = None,
    negotiation_card_id: str = NegotiationCard.build_full_id(),
    negotiation_card_model: Optional[NegotiationCardModel] = None,
    test_suite_id: str = TestSuite.build_full_id(),
    test_suite_model: Optional[TestSuiteModel] = None,
    test_results_id: str = TestResults.build_full_id(),
    test_results_model: Optional[TestResultsModel] = None,
    comments: List[CommentDescriptor] = [],
) -> None:
    """
    Creates a Report.

    :param identifier: The Report id (default value used if not provided).
    :param negotiation_card_id: The id of the negotiation card to use (defaults to default card id).
    :param negotiation_card_model: A NegotiationCardModel object; if None, NegotiationCard from the provided id will be loaded.
    :param test_suite_id: The id of the test suite to use (defaults to default suite id).
    :param test_suite_model: A TestSuiteModel object; if None, TestSuite from the provided id will be loaded.
    :param test_results_id: The id of the test results to use (defaults to default results id).
    :param test_results_model: A TestResultsModel object; if None, TestResults from the provided id will be loaded.
    :param comments: Optional comments to add.
    """
    super().__init__(identifier)

    self.negotiation_card_id = negotiation_card_id
    self.negotiation_card_model = (
        negotiation_card_model
        if negotiation_card_model
        else typing.cast(
            NegotiationCardModel,
            NegotiationCard.load(negotiation_card_id).to_model().body,
        )
    )
    """The Negotiation Card with the requirements."""

    self.test_suite_id = test_suite_id
    self.test_suite_model = (
        test_suite_model
        if test_suite_model
        else typing.cast(
            TestSuiteModel, TestSuite.load(test_suite_id).to_model().body
        )
    )
    """The test suite used to generate these results."""

    self.test_results_id = test_results_id
    self.test_results_model = (
        test_results_model
        if test_results_model
        else typing.cast(
            TestResultsModel,
            TestResults.load(test_results_id).to_model().body,
        )
    )
    """A summary of model performance evaluation."""

    self.comments = comments
    """A collection of comments for the report."""

from_model(model) classmethod

Convert a report model to its corresponding artifact.

Source code in mlte/report/artifact.py
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
@classmethod
def from_model(cls, model: BaseModel) -> Report:
    """Convert a report model to its corresponding artifact."""
    assert isinstance(
        model, ArtifactModel
    ), "Can't create object from non-ArtifactModel model."
    assert (
        model.header.type == ArtifactType.REPORT
    ), "Type should be Report."
    body = typing.cast(ReportModel, model.body)
    return Report(
        identifier=model.header.identifier,
        negotiation_card_id=body.negotiation_card_id,
        negotiation_card_model=body.negotiation_card,
        test_suite_id=body.test_suite_id,
        test_suite_model=body.test_suite,
        test_results_id=body.test_results_id,
        test_results_model=body.test_results,
        comments=body.comments,
    )

load(identifier=None) classmethod

Load a Report from the configured global session.

Parameters:

Name Type Description Default
identifier Optional[str]

The identifier for the artifact. If None, the default id is used.

None
Source code in mlte/report/artifact.py
127
128
129
130
131
132
133
134
135
@classmethod
def load(cls, identifier: typing.Optional[str] = None) -> Report:
    """
    Load a Report from the configured global session.
    :param identifier: The identifier for the artifact. If None,
    the default id is used.
    """
    report = super().load(identifier)
    return typing.cast(Report, report)

pre_save_hook(context, store)

Override Artifact.pre_save_hook(). Assigns time-stamped id to report, to ensure all have different ids.

Parameters:

Name Type Description Default
context Context

The context in which to save the artifact

required
store ArtifactStore

The store in which to save the artifact

required

Raises:

Type Description
RuntimeError

On broken invariant

Source code in mlte/report/artifact.py
138
139
140
141
142
143
144
145
def pre_save_hook(self, context: Context, store: ArtifactStore) -> None:
    """
    Override Artifact.pre_save_hook(). Assigns time-stamped id to report, to ensure all have different ids.
    :param context: The context in which to save the artifact
    :param store: The store in which to save the artifact
    :raises RuntimeError: On broken invariant
    """
    self.identifier = f"{self.identifier}-{datetime.datetime.now().strftime('%Y%m%d-%H%M%S')}"

to_model()

Convert a report artifact to its corresponding model.

Source code in mlte/report/artifact.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def to_model(self) -> ArtifactModel:
    """Convert a report artifact to its corresponding model."""
    return ArtifactModel(
        header=self.build_artifact_header(),
        body=ReportModel(
            negotiation_card_id=self.negotiation_card_id,
            negotiation_card=self.negotiation_card_model,
            test_suite_id=self.test_suite_id,
            test_suite=self.test_suite_model,
            test_results_id=self.test_results_id,
            test_results=self.test_results_model,
            comments=self.comments,
        ),
    )