-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add metadata SDK samples for list artifact and list execution (#…
…1514) * feat: Add metadata SDK samples for list artifact and execution * update default execution display name * Fix lint issues. * update tests based on review feedback to return a list of more than one item * simplify sample file names
- Loading branch information
1 parent
d442248
commit c0d01f1
Showing
6 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
samples/model-builder/experiment_tracking/list_artifact_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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 | ||
# | ||
# https://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 typing import Optional | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_create_artifact_with_sdk_sample] | ||
def list_artifact_sample( | ||
project: str, | ||
location: str, | ||
display_name_fitler: Optional[str] = "display_name=\"my_model_*\"", | ||
create_date_filter: Optional[str] = "create_time>\"2022-06-11T12:30:00-08:00\"", | ||
): | ||
aiplatform.init( | ||
project=project, | ||
location=location) | ||
|
||
combined_filters = f"{display_name_fitler} AND {create_date_filter}" | ||
|
||
return aiplatform.Artifact.list(filter=combined_filters) | ||
|
||
|
||
# [END aiplatform_sdk_create_artifact_with_sdk_sample] |
33 changes: 33 additions & 0 deletions
33
samples/model-builder/experiment_tracking/list_artifact_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
import list_artifact_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
def test_list_artifact_with_sdk_sample(mock_artifact, mock_list_artifact): | ||
artifacts = list_artifact_sample.list_artifact_sample( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
display_name_fitler=constants.DISPLAY_NAME, | ||
create_date_filter=constants.CREATE_DATE, | ||
) | ||
|
||
mock_list_artifact.assert_called_with( | ||
filter=f"{constants.DISPLAY_NAME} AND {constants.CREATE_DATE}" | ||
) | ||
assert len(artifacts) == 2 | ||
assert artifacts[0] is mock_artifact | ||
assert artifacts[1] is mock_artifact |
36 changes: 36 additions & 0 deletions
36
samples/model-builder/experiment_tracking/list_execution_sample.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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 | ||
# | ||
# https://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 typing import Optional | ||
|
||
from google.cloud import aiplatform | ||
|
||
|
||
# [START aiplatform_sdk_create_execution_with_sdk_sample] | ||
def list_execution_sample( | ||
project: str, | ||
location: str, | ||
display_name_fitler: Optional[str] = "display_name=\"my_execution_*\"", | ||
create_date_filter: Optional[str] = "create_time>\"2022-06-11T12:30:00-08:00\"", | ||
): | ||
aiplatform.init( | ||
project=project, | ||
location=location) | ||
|
||
combined_filters = f"{display_name_fitler} AND {create_date_filter}" | ||
|
||
return aiplatform.Execution.list(filter=combined_filters) | ||
|
||
|
||
# [END aiplatform_sdk_create_execution_with_sdk_sample] |
33 changes: 33 additions & 0 deletions
33
samples/model-builder/experiment_tracking/list_execution_sample_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# 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 | ||
# | ||
# https://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. | ||
|
||
import list_execution_sample | ||
|
||
import test_constants as constants | ||
|
||
|
||
def test_list_execution_sample(mock_execution, mock_list_execution): | ||
executions = list_execution_sample.list_execution_sample( | ||
project=constants.PROJECT, | ||
location=constants.LOCATION, | ||
display_name_fitler=constants.DISPLAY_NAME, | ||
create_date_filter=constants.CREATE_DATE, | ||
) | ||
|
||
mock_list_execution.assert_called_with( | ||
filter=f"{constants.DISPLAY_NAME} AND {constants.CREATE_DATE}" | ||
) | ||
assert len(executions) == 2 | ||
assert executions[0] is mock_execution | ||
assert executions[1] is mock_execution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters