Exemplo n.º 1
0
    def _log(self, artifact):
        """
    Log an artifact.

    This method expects `artifact` to have
      - ARTIFACT_TYPE_NAME string field the form of
        <namespace>/<name>.
      - serialization() method to return a openapi_client.MlMetadataArtifact.

    This method will set artifact.id.
    """
        serialization = artifact.serialization()
        if serialization.custom_properties is None:
            serialization.custom_properties = {}
        if WORKSPACE_PROPERTY_NAME in serialization.custom_properties:
            raise ValueError("custom_properties contains reserved key %s" %
                             WORKSPACE_PROPERTY_NAME)
        if RUN_PROPERTY_NAME in serialization.custom_properties:
            raise ValueError("custom_properties contains reserved key %s" %
                             RUN_PROPERTY_NAME)
        if self.workspace is not None:
            serialization.custom_properties[
                WORKSPACE_PROPERTY_NAME] = openapi_client.MlMetadataValue(
                    string_value=self.workspace.name)
        if self.run is not None:
            serialization.custom_properties[
                RUN_PROPERTY_NAME] = openapi_client.MlMetadataValue(
                    string_value=self.run.name)
        response = self.workspace.client.create_artifact(
            parent=artifact.ARTIFACT_TYPE_NAME,
            body=serialization,
        )
        artifact.id = response.artifact.id
        return artifact
Exemplo n.º 2
0
 def serialization(self):
     model_artifact = openapi_client.MlMetadataArtifact(
         uri=self.uri,
         properties={
             "name":
             openapi_client.MlMetadataValue(string_value=self.name),
             "create_time":
             openapi_client.MlMetadataValue(string_value=self.create_time),
             "description":
             _mlMetadataStringValue(self.description),
             "model_type":
             _mlMetadataStringValue(self.model_type),
             "version":
             _mlMetadataStringValue(self.version),
             "owner":
             _mlMetadataStringValue(self.owner),
             ALL_META_PROPERTY_NAME:
             _mlMetadataStringValue(json.dumps(self.__dict__)),
         })
     _del_none_properties(model_artifact.properties)
     return model_artifact
Exemplo n.º 3
0
    def serialized(self):
        execution = openapi_client.MlMetadataExecution(
            properties={
                "name":
                openapi_client.MlMetadataValue(string_value=self.name),
                "create_time":
                openapi_client.MlMetadataValue(string_value=self.create_time),
                "description":
                _mlMetadataStringValue(self.description),
            })
        _del_none_properties(execution.properties)

        execution.custom_properties = {}
        if self.workspace is not None:
            execution.custom_properties[
                WORKSPACE_PROPERTY_NAME] = openapi_client.MlMetadataValue(
                    string_value=self.workspace.name)
        if self.run is not None:
            execution.custom_properties[
                RUN_PROPERTY_NAME] = openapi_client.MlMetadataValue(
                    string_value=self.run.name)
        return execution
Exemplo n.º 4
0
def _mlMetadataStringValue(str):
    if str is None:
        return None
    return openapi_client.MlMetadataValue(string_value=str)