Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Improved metadata artifact and execution creation using python / SDK #1430

Merged
merged 58 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
5d109a7
rebase to master after ga merge
SinaChavoshi Jun 14, 2022
03b0b94
add support for artifact create
SinaChavoshi Jun 14, 2022
380135d
add unit tests for create from artifact parameters
SinaChavoshi Jun 14, 2022
49e34cc
update formatting
SinaChavoshi Jun 14, 2022
9471dbf
fix lint issues
SinaChavoshi Jun 14, 2022
8d0b9e5
Add integration tests
SinaChavoshi Jun 14, 2022
1bd08aa
add support for execution types
SinaChavoshi Jun 15, 2022
947249f
correct execution type in create
SinaChavoshi Jun 15, 2022
c23efa9
add execution support and unit tests
SinaChavoshi Jun 16, 2022
8c7350c
add support for state in artifacts
SinaChavoshi Jun 16, 2022
b2f2a91
add support for start_execution
SinaChavoshi Jun 16, 2022
1e85c2b
add support for metadata_store_id in start_execution
SinaChavoshi Jun 16, 2022
a93bdcd
lint and docs update based on review feedback
SinaChavoshi Jun 16, 2022
3babdef
merge with upstream/master
SinaChavoshi Jun 16, 2022
743a971
Add e2e integraton tests and lint update
SinaChavoshi Jun 16, 2022
edaf3e6
Update google/cloud/aiplatform/metadata/artifact.py
SinaChavoshi Jun 16, 2022
fb18610
remove the duplicate test_experiments_copy.py
SinaChavoshi Jun 16, 2022
f655741
refactor based on code review feedback
SinaChavoshi Jun 16, 2022
02d6069
regroup tests to match module names
SinaChavoshi Jun 16, 2022
abe3d48
fix e2e integration tests
SinaChavoshi Jun 16, 2022
8056a41
remove call to _temp_prefix = tmpvrtxsdk-e2e from E2E test
SinaChavoshi Jun 16, 2022
d2daa78
Update google/cloud/aiplatform/metadata/schema/base_execution.py
SinaChavoshi Jun 16, 2022
839b708
remove artifact and schema referencing the create result to self
SinaChavoshi Jun 16, 2022
81beab2
remove kwargs
SinaChavoshi Jun 16, 2022
a308bfd
fix typing for container spec
SinaChavoshi Jun 16, 2022
3122e7d
remove resouceName from system types
SinaChavoshi Jun 16, 2022
30c0fcd
metrics should default to None
SinaChavoshi Jun 16, 2022
3c9b5dc
Merge branch 'main' into minimum_schema_set_from_ga
SinaChavoshi Jun 17, 2022
476946f
change from using resouce_name to resource_id
SinaChavoshi Jun 17, 2022
4a2a3fc
fix e2e tests
SinaChavoshi Jun 17, 2022
e42cfa3
Merge remote-tracking branch 'upstream/main' into minimum_schema_set_…
SinaChavoshi Jun 21, 2022
6d89efc
change google and system to sub folders of schema
SinaChavoshi Jun 21, 2022
db1949c
Merge branch 'main' into minimum_schema_set_from_ga
SinaChavoshi Jun 21, 2022
53ba40b
use create_from_base_execution_schema instead of overloading create
SinaChavoshi Jun 22, 2022
1a8931a
update api docs
SinaChavoshi Jun 22, 2022
0265816
update docstring formatting
SinaChavoshi Jun 22, 2022
59afcd6
Update google/cloud/aiplatform/metadata/metadata.py
SinaChavoshi Jun 22, 2022
1e31adf
add return types and move args to constructor
SinaChavoshi Jun 22, 2022
c43fcbf
using forward reference for parameter and return types to resolve cir…
SinaChavoshi Jun 23, 2022
6311bfd
change base classes to abstract classes
SinaChavoshi Jun 23, 2022
04c9e88
Add tests for system.artifact type
SinaChavoshi Jun 23, 2022
1778a34
use resouce name instead of id and populate metadata with resourceNa…
SinaChavoshi Jun 23, 2022
bee8e93
remove start_execution from this pr and move to a separate PR
SinaChavoshi Jun 23, 2022
5e87e0a
change all args to keyword args
SinaChavoshi Jun 23, 2022
48f65dc
always make a copy of metadata instead of pass by reference
SinaChavoshi Jun 23, 2022
086df90
auto generate uri for google types
SinaChavoshi Jun 23, 2022
af765f3
fix e2e tests
SinaChavoshi Jun 23, 2022
e28fb7e
Merge branch 'googleapis:main' into minimum_schema_set_from_ga
SinaChavoshi Jun 23, 2022
f6e0b9d
Merge branch 'main' into minimum_schema_set_from_ga
rosiezou Jun 23, 2022
4e9d28b
Merge branch 'googleapis:main' into minimum_schema_set_from_ga
SinaChavoshi Jun 24, 2022
165ea43
Merge branch 'googleapis:main' into minimum_schema_set_from_ga
SinaChavoshi Jun 24, 2022
63a7e57
switch to using Artifact.create instead of _create
SinaChavoshi Jun 25, 2022
3faef4f
Merge branch 'googleapis:main' into minimum_schema_set_from_ga
SinaChavoshi Jun 27, 2022
246dfcc
change typing for state to Optional
SinaChavoshi Jun 27, 2022
575531e
change typing for state to Optional in artifact base file
SinaChavoshi Jun 27, 2022
3b17ce7
change to use the Execution.create instead of the private method
SinaChavoshi Jun 27, 2022
c9403bf
Merge branch 'googleapis:main' into minimum_schema_set_from_ga
SinaChavoshi Jun 27, 2022
323075e
chagne copy to deepcopy for metadata
SinaChavoshi Jun 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions google/cloud/aiplatform/metadata/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from google.cloud.aiplatform.metadata import resource
from google.cloud.aiplatform.metadata import utils as metadata_utils
from google.cloud.aiplatform.utils import rest_utils

from google.cloud.aiplatform.metadata.types import base as types_base
SinaChavoshi marked this conversation as resolved.
Show resolved Hide resolved

_LOGGER = base.Logger(__name__)

Expand Down Expand Up @@ -176,6 +176,7 @@ def _create(

"""
api_client = cls._instantiate_client(location=location, credentials=credentials)
SinaChavoshi marked this conversation as resolved.
Show resolved Hide resolved
api_client = cls._instantiate_client(location=location, credentials=credentials)

parent = utils.full_resource_name(
resource_name=metadata_store_id,
Expand Down Expand Up @@ -249,8 +250,8 @@ def _list_resources(
@classmethod
def create(
cls,
schema_title: str,
*,
schema_title: Optional[str] = None,
resource_id: Optional[str] = None,
uri: Optional[str] = None,
display_name: Optional[str] = None,
Expand All @@ -262,12 +263,13 @@ def create(
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
base_artifact: Optional[types_base.BaseArtifactSchema] = None,
) -> "Artifact":
"""Creates a new Metadata Artifact.

Args:
schema_title (str):
Required. schema_title identifies the schema title used by the Artifact.
Optional. schema_title identifies the schema title used by the Artifact.
SinaChavoshi marked this conversation as resolved.
Show resolved Hide resolved

Please reference https://cloud.google.com/vertex-ai/docs/ml-metadata/system-schemas.
resource_id (str):
Expand Down Expand Up @@ -307,10 +309,28 @@ def create(
credentials (auth_credentials.Credentials):
Optional. Custom credentials used to create this Artifact. Overrides
credentials set in aiplatform.init.
base_artifact (BaseArtifactType):
Optional. An instance of the BaseArtifactType class that can be provided instead of providing artifact specific parameters. It overrides
the values provided for schema_title, resource_id, uri, display_name, schema_version, description, and metadata.

Returns:
Artifact: Instantiated representation of the managed Metadata Artifact.
"""
if base_artifact:
return cls._create(
resource_id=base_artifact.resource_id,
schema_title=base_artifact.schema_title,
uri=base_artifact.uri,
display_name=base_artifact.display_name,
schema_version=base_artifact.schema_version,
description=base_artifact.description,
metadata=base_artifact.metadata,
metadata_store_id=metadata_store_id,
project=project,
location=location,
credentials=credentials,
)

return cls._create(
resource_id=resource_id,
schema_title=schema_title,
Expand Down
126 changes: 126 additions & 0 deletions google/cloud/aiplatform/metadata/types/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# -*- coding: utf-8 -*-

# Copyright 2022 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

from google.auth import credentials as auth_credentials
from typing import Optional, Dict
from google.cloud.aiplatform.metadata import artifact
from google.cloud.aiplatform import base

from google.cloud.aiplatform.metadata import constants

_LOGGER = base.Logger(__name__)


class BaseArtifactSchema(object):
"""Base class for Metadata Artifact types.

This is the base class for defining various artifact types, which can be
passed to google.Artifact to create a corresponding resource.
Artifacts carry a `metadata` field, which is a dictionary for storing
metadata related to this artifact. Subclasses from ArtifactType can enforce
various structure and field requirements for the metadata field.

Args:
schema_title (str):
Optional. The schema title used by the Artifact, defaults to "system.Artifact"
resource_name (str):
Optional. The resource name of the Artifact following the format as follows.
This is globally unique in a metadataStore:
projects/123/locations/us-central1/metadataStores/<metadata_store_id>/artifacts/<resource_id>.
uri (str):
Optional. The uniform resource identifier of the artifact file. May be empty if there is no actual
artifact file.
display_name (str):
Optional. The user-defined name of the Artifact.
schema_version (str):
Optional. schema_version specifies the version used by the Artifact.
If not set, defaults to use the latest version.
description (str):
Optional. Describes the purpose of the Artifact to be created.
metadata (Dict):
Optional. Contains the metadata information that will be stored in the Artifact.
**kwargs:
Optional. Additional Args that will be passed directly to the Artifact base method for backward compatibility.
"""

ARTIFACT_PROPERTY_KEY_RESOURCE_NAME = "resourceName"
SCHEMA_TITLE = "system.Artifact"

def __init__(
self,
schema_title: Optional[str] = None,
resource_name: Optional[str] = None,
uri: Optional[str] = None,
display_name: Optional[str] = None,
schema_version: Optional[str] = None,
description: Optional[str] = None,
metadata: Optional[Dict] = None,
**kwargs,
):

"""Initializes the Artifact with the given name, URI and metadata."""
self.schema_title = BaseArtifactSchema.SCHEMA_TITLE
if schema_title:
self.schema_title = schema_title
self.resource_name = resource_name

self.resource_id = None
if resource_name:
# Temporary work around while Artifact.create takes resource_id instead of resource_name
SinaChavoshi marked this conversation as resolved.
Show resolved Hide resolved
self.resource_id = resource_name.split("/")[-1]

self.uri = uri
self.display_name = display_name
self.schema_version = schema_version or constants._DEFAULT_SCHEMA_VERSION
self.description = description
self.metadata = metadata

def create(
self,
metadata_store_id: Optional[str] = "default",
project: Optional[str] = None,
location: Optional[str] = None,
credentials: Optional[auth_credentials.Credentials] = None,
):
"""Creates a new Metadata Artifact.

Args:
metadata_store_id (str):
Optional. The <metadata_store_id> portion of the resource name with
the format:
projects/123/locations/us-central1/metadataStores/<metadata_store_id>/artifacts/<resource_id>
If not provided, the MetadataStore's ID will be set to "default".
project (str):
Optional. Project used to create this Artifact. Overrides project set in
aiplatform.init.
location (str):
Optional. Location used to create this Artifact. Overrides location set in
aiplatform.init.
credentials (auth_credentials.Credentials):
Optional. Custom credentials used to create this Artifact. Overrides
credentials set in aiplatform.init.
Returns:
Artifact: Instantiated representation of the managed Metadata Artifact.
"""
self.artifact = artifact.Artifact.create(
base_artifact=self,
metadata_store_id=metadata_store_id,
project=project,
location=location,
credentials=credentials,
)
return self.artifact
Loading