Skip to content

factory_nc

mlte/store/artifact/underlying/rdbs/factory_nc.py

Conversions between schema and internal models.

create_negotiation_data_db_from_model(negotiation_card_data, session)

Creates the DB object from the corresponding internal model.

Source code in mlte/store/artifact/underlying/rdbs/factory_nc.py
 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
def create_negotiation_data_db_from_model(
    negotiation_card_data: NegotiationCardDataModel,
    session: Session,
) -> DBNegotiationCardData:
    """Creates the DB object from the corresponding internal model."""
    # Create intermedidate objects.
    problem_type_obj = (
        DBReader.get_problem_type(
            negotiation_card_data.system.problem_type, session
        )
        if negotiation_card_data.system.problem_type is not None
        else None
    )
    if negotiation_card_data.model.development_compute_resources:
        model_dev_resources_obj = DBModelResourcesDescriptor(
            cpu=negotiation_card_data.model.development_compute_resources.cpu,
            gpu=negotiation_card_data.model.development_compute_resources.gpu,
            memory=negotiation_card_data.model.development_compute_resources.memory,
            storage=negotiation_card_data.model.development_compute_resources.storage,
        )
    else:
        model_dev_resources_obj = None

    model_prod_resources_obj = DBModelResourcesDescriptor(
        cpu=negotiation_card_data.model.production_compute_resources.cpu,
        gpu=negotiation_card_data.model.production_compute_resources.gpu,
        memory=negotiation_card_data.model.production_compute_resources.memory,
        storage=negotiation_card_data.model.production_compute_resources.storage,
    )

    # Create the actual object.
    negotiation_card_data_obj = DBNegotiationCardData(
        sys_goals=[],
        sys_problem_type=problem_type_obj,
        sys_task=negotiation_card_data.system.task,
        sys_usage_context=negotiation_card_data.system.usage_context,
        sys_risks_fp=negotiation_card_data.system.risks.fp,
        sys_risks_fn=negotiation_card_data.system.risks.fn,
        sys_risks_other=negotiation_card_data.system.risks.other,
        model_dev_resources=model_dev_resources_obj,
        model_prod_resources=model_prod_resources_obj,
        model_prod_deployment_platform=negotiation_card_data.model.deployment_platform,
        model_prod_capability_deployment_mechanism=negotiation_card_data.model.capability_deployment_mechanism,
        model_prod_inputs=[],
        model_prod_outputs=[],
        data_descriptors=[],
        system_requirements=[],
    )

    # Create list of system goal objects.
    for goal in negotiation_card_data.system.goals:
        goal_obj = _build_goal_obj(goal)
        negotiation_card_data_obj.sys_goals.append(goal_obj)

    # Create list of data descriptor objects.
    for data_descriptor in negotiation_card_data.data:
        data_obj = _build_data_descriptor_obj(data_descriptor, session)
        negotiation_card_data_obj.data_descriptors.append(data_obj)

    # Create list of model input objects.
    for input in negotiation_card_data.model.input_specification:
        input_obj = _build_io_descriptor_obj(input)
        negotiation_card_data_obj.model_prod_inputs.append(input_obj)

    # Create list of model output objects.
    for output in negotiation_card_data.model.output_specification:
        output_obj = _build_io_descriptor_obj(output)
        negotiation_card_data_obj.model_prod_outputs.append(output_obj)

    # Create list of QAS objects.
    for qas in negotiation_card_data.system_requirements:
        qas_obj = DBQAS(
            quality=qas.quality,
            stimulus=qas.stimulus,
            source=qas.source,
            environment=qas.environment,
            response=qas.response,
            measure=qas.measure,
        )
        negotiation_card_data_obj.system_requirements.append(qas_obj)

    return negotiation_card_data_obj

create_negotiation_data_model_from_db(negotiation_card_data_obj)

Creates the internal model object from the corresponding DB object.

Source code in mlte/store/artifact/underlying/rdbs/factory_nc.py
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
def create_negotiation_data_model_from_db(
    negotiation_card_data_obj: DBNegotiationCardData,
) -> NegotiationCardDataModel:
    """Creates the internal model object from the corresponding DB object."""
    body = NegotiationCardDataModel(
        system=SystemDescriptor(
            task=negotiation_card_data_obj.sys_task,
            usage_context=negotiation_card_data_obj.sys_usage_context,
            risks=RiskDescriptor(
                fp=negotiation_card_data_obj.sys_risks_fp,
                fn=negotiation_card_data_obj.sys_risks_fn,
                other=negotiation_card_data_obj.sys_risks_other,
            ),
            problem_type=(
                ProblemType(negotiation_card_data_obj.sys_problem_type.name)
                if negotiation_card_data_obj.sys_problem_type is not None
                else None
            ),
            goals=_build_goal_descriptors(negotiation_card_data_obj.sys_goals),
        ),
        data=_build_data_descriptors(
            negotiation_card_data_obj.data_descriptors
        ),
        model=_build_model_descriptor(
            negotiation_card_data_obj.model_dev_resources,
            negotiation_card_data_obj.model_prod_deployment_platform,
            negotiation_card_data_obj.model_prod_capability_deployment_mechanism,
            negotiation_card_data_obj.model_prod_inputs,
            negotiation_card_data_obj.model_prod_outputs,
            negotiation_card_data_obj.model_prod_resources,
        ),
        system_requirements=[
            QASDescriptor(
                quality=qas.quality,
                stimulus=qas.stimulus,
                source=qas.source,
                environment=qas.environment,
                response=qas.response,
                measure=qas.measure,
            )
            for qas in negotiation_card_data_obj.system_requirements
        ],
    )
    return body

create_negotiation_db_from_model(negotiation_card, artifact_header, session)

Creates the DB object from the corresponding internal model.

Source code in mlte/store/artifact/underlying/rdbs/factory_nc.py
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def create_negotiation_db_from_model(
    negotiation_card: NegotiationCardModel,
    artifact_header: DBArtifactHeader,
    session: Session,
) -> DBNegotiationCard:
    """Creates the DB object from the corresponding internal model."""
    # Create intermedidate objects.
    negotiation_card_data_obj = create_negotiation_data_db_from_model(
        negotiation_card.nc_data, session
    )

    # Create the actual object.
    negotiation_card_obj = DBNegotiationCard(
        artifact_header=artifact_header,
        negotiation_card_data=negotiation_card_data_obj,
    )

    return negotiation_card_obj

create_negotiation_model_from_db(negotiation_card_obj)

Creates the internal model object from the corresponding DB object.

Source code in mlte/store/artifact/underlying/rdbs/factory_nc.py
207
208
209
210
211
212
213
214
215
def create_negotiation_model_from_db(
    negotiation_card_obj: DBNegotiationCard,
) -> NegotiationCardModel:
    """Creates the internal model object from the corresponding DB object."""
    return NegotiationCardModel(
        nc_data=create_negotiation_data_model_from_db(
            negotiation_card_obj.negotiation_card_data
        )
    )

create_report_db_from_model(report, artifact_header, session)

Creates the DB object from the corresponding internal model.

Source code in mlte/store/artifact/underlying/rdbs/factory_nc.py
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
def create_report_db_from_model(
    report: ReportModel,
    artifact_header: DBArtifactHeader,
    session: Session,
) -> DBReport:
    """Creates the DB object from the corresponding internal model."""
    negotiation_card_data_obj = create_negotiation_data_db_from_model(
        report.nc_data, session
    )

    # Create the actual object.
    report_obj = DBReport(
        artifact_header=artifact_header,
        negotiation_card_data=negotiation_card_data_obj,
        validated_spec=(
            DBReader.get_validated_spec(
                report.validated_spec_id,
                artifact_header.version_id,
                session,
            )
            if report.validated_spec_id is not None
            else None
        ),
        comments=[],
        quantitative_analysis_content=report.quantitative_analysis.content,
    )

    # Create list of comment objects.
    for comment in report.comments:
        comment_obj = DBCommentDescriptor(content=comment.content)
        report_obj.comments.append(comment_obj)

    return report_obj

create_report_model_from_db(report_obj)

Creates the internal model object from the corresponding DB object.

Source code in mlte/store/artifact/underlying/rdbs/factory_nc.py
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
def create_report_model_from_db(report_obj: DBReport) -> ReportModel:
    """Creates the internal model object from the corresponding DB object."""
    negotiation_card_data = create_negotiation_data_model_from_db(
        report_obj.negotiation_card_data
    )

    body = ReportModel(
        nc_data=negotiation_card_data,
        validated_spec_id=(
            report_obj.validated_spec.artifact_header.identifier
            if report_obj.validated_spec is not None
            else None
        ),
        comments=[
            CommentDescriptor(content=comment.content)
            for comment in report_obj.comments
            if comment.content is not None
        ],
        quantitative_analysis=QuantitiveAnalysisDescriptor(
            content=report_obj.quantitative_analysis_content
        ),
    )
    return body