Skip to content

artifact

Artifact implementation for negotiation card.

NegotiationCard

Bases: Artifact

The negotiation card contains information produced at MLTE negotiation points.

Source code in mlte/negotiation/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
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
class NegotiationCard(Artifact):
    """The negotiation card contains information produced at MLTE negotiation points."""

    type_ = ArtifactType.NEGOTIATION_CARD
    """Class attribute indicating type."""

    def __init__(
        self,
        identifier: str | None = None,
        system: SystemDescriptor | None = None,
        data: list[DataDescriptor] | None = None,
        model: ModelDescriptor | None = None,
        quality_scenarios: list[QASDescriptor] | None = None,
    ) -> None:
        super().__init__(identifier)

        self.system = system if system else SystemDescriptor()
        """A descriptor for the system into which the model is integrated."""

        self.data = data if data else []
        """A collection of descriptors for relevant datasets."""

        self.model = model if model else ModelDescriptor()
        """A descriptor for the model."""

        self.quality_scenarios = quality_scenarios if quality_scenarios else []
        """A list of quality attribute scenarios."""

        self.level = ArtifactLevel.MODEL
        """Indicate that this type of artifact will exist at the model level."""

        # Add ids to QAS as needed.
        qas.add_qas_ids(self.identifier, self.quality_scenarios)

    # ----------------------------------------------------------------------------------
    # Serialization methods.
    # ----------------------------------------------------------------------------------
    # Overriden.
    def to_model(self) -> ArtifactModel:
        """Convert a negotation card artifact to its corresponding model."""
        return ArtifactModel(
            header=self.build_artifact_header(),
            body=NegotiationCardModel(
                system=self.system,
                data=self.data,
                model=self.model,
                system_requirements=self.quality_scenarios,
            ),
        )

    # Overriden.
    @classmethod
    def from_model(cls, model: BaseModel) -> NegotiationCard:
        """Convert a negotiation card model to its corresponding artifact."""
        assert isinstance(model, ArtifactModel), (
            "Can't create object from non-ArtifactModel model."
        )
        assert model.header.type == ArtifactType.NEGOTIATION_CARD, (
            "Type should be NegotiationCard."
        )
        body = typing.cast(NegotiationCardModel, model.body)
        return NegotiationCard(
            identifier=model.header.identifier,
            system=body.system,
            data=body.data,
            model=body.model,
            quality_scenarios=body.system_requirements,
        )

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

    # Overriden.
    def pre_save_hook(self, context: Context, store: ArtifactStore) -> None:
        """
        Override Artifact.pre_save_hook(). Ensures that QAS that done have ids are assigned them.
        :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
        """
        # Add ids to QAS as needed.
        qas.add_qas_ids(self.identifier, self.quality_scenarios)

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

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

    def print_quality_scenarios(self):
        """Prints the scenarios in a user-friendly way."""
        for scenario in self.quality_scenarios:
            print(scenario)

data = data if data else [] instance-attribute

A collection of descriptors for relevant datasets.

level = ArtifactLevel.MODEL instance-attribute

Indicate that this type of artifact will exist at the model level.

model = model if model else ModelDescriptor() instance-attribute

A descriptor for the model.

quality_scenarios = quality_scenarios if quality_scenarios else [] instance-attribute

A list of quality attribute scenarios.

system = system if system else SystemDescriptor() instance-attribute

A descriptor for the system into which the model is integrated.

type_ = ArtifactType.NEGOTIATION_CARD class-attribute instance-attribute

Class attribute indicating type.

from_model(model) classmethod

Convert a negotiation card model to its corresponding artifact.

Source code in mlte/negotiation/artifact.py
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@classmethod
def from_model(cls, model: BaseModel) -> NegotiationCard:
    """Convert a negotiation card model to its corresponding artifact."""
    assert isinstance(model, ArtifactModel), (
        "Can't create object from non-ArtifactModel model."
    )
    assert model.header.type == ArtifactType.NEGOTIATION_CARD, (
        "Type should be NegotiationCard."
    )
    body = typing.cast(NegotiationCardModel, model.body)
    return NegotiationCard(
        identifier=model.header.identifier,
        system=body.system,
        data=body.data,
        model=body.model,
        quality_scenarios=body.system_requirements,
    )

load(identifier=None) classmethod

Load a NegotiationCard from the configured global session.

Parameters:

Name Type Description Default
identifier str | None

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

None
Source code in mlte/negotiation/artifact.py
 93
 94
 95
 96
 97
 98
 99
100
101
@classmethod
def load(cls, identifier: str | None = None) -> NegotiationCard:
    """
    Load a NegotiationCard from the configured global session.
    :param identifier: The identifier for the artifact. If None,
    the default id is used.
    """
    card = super().load(identifier)
    return typing.cast(NegotiationCard, card)

pre_save_hook(context, store)

Override Artifact.pre_save_hook(). Ensures that QAS that done have ids are assigned them.

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/negotiation/artifact.py
104
105
106
107
108
109
110
111
112
def pre_save_hook(self, context: Context, store: ArtifactStore) -> None:
    """
    Override Artifact.pre_save_hook(). Ensures that QAS that done have ids are assigned them.
    :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
    """
    # Add ids to QAS as needed.
    qas.add_qas_ids(self.identifier, self.quality_scenarios)

print_quality_scenarios()

Prints the scenarios in a user-friendly way.

Source code in mlte/negotiation/artifact.py
124
125
126
127
def print_quality_scenarios(self):
    """Prints the scenarios in a user-friendly way."""
    for scenario in self.quality_scenarios:
        print(scenario)

to_model()

Convert a negotation card artifact to its corresponding model.

Source code in mlte/negotiation/artifact.py
61
62
63
64
65
66
67
68
69
70
71
def to_model(self) -> ArtifactModel:
    """Convert a negotation card artifact to its corresponding model."""
    return ArtifactModel(
        header=self.build_artifact_header(),
        body=NegotiationCardModel(
            system=self.system,
            data=self.data,
            model=self.model,
            system_requirements=self.quality_scenarios,
        ),
    )