forked from aws/sagemaker-python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
change: add queryLineageResult visualizer load test & integ test #6
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b74e861
test_lineage_visualize.py created
c3d2ff7
Merge branch 'master' into large-graph-test
578acdf
pyvis import issue on running lineage test
9171e4e
import visualization modules using get_module()
d679f4a
test_wide_graphs added
5c89c09
long graph visualize test added
09264c2
Merge pull request #3 from Snoyark/master
ytlee93 fa7b9dd
create context & action added to helper
83964da
resolve conflict with master branch
24f8925
merge integ load test
c66edf8
change: add queryLineageResult visualizer load test & integ test
7cec38d
remove generated graph html file after visualize integ test
c1169be
validation logic clean on integ tests
23fe126
sleep time before clean_all added (avoid race condition)
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
urllib3==1.26.8 | ||
docker-compose==1.29.2 | ||
docker~=5.0.0 | ||
PyYAML==5.4.1 | ||
PyYAML==5.4.1 |
This file contains hidden or 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 |
---|---|---|
|
@@ -18,3 +18,4 @@ fabric==2.6.0 | |
requests==2.27.1 | ||
sagemaker-experiments==0.1.35 | ||
Jinja2==3.0.3 | ||
pyvis==0.2.1 |
This file contains hidden or 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
This file contains hidden or 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
274 changes: 274 additions & 0 deletions
274
tests/integ/sagemaker/lineage/test_lineage_visualize.py
This file contains hidden or 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,274 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file 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. | ||
"""This module contains code to test SageMaker ``LineageQueryResult.visualize()``""" | ||
from __future__ import absolute_import | ||
import time | ||
import json | ||
import os | ||
|
||
import pytest | ||
|
||
import sagemaker.lineage.query | ||
from sagemaker.lineage.query import LineageQueryDirectionEnum | ||
from tests.integ.sagemaker.lineage.helpers import name, LineageResourceHelper | ||
|
||
|
||
def test_LineageResourceHelper(sagemaker_session): | ||
# check if LineageResourceHelper works properly | ||
lineage_resource_helper = LineageResourceHelper(sagemaker_session=sagemaker_session) | ||
try: | ||
art1 = lineage_resource_helper.create_artifact(artifact_name=name()) | ||
art2 = lineage_resource_helper.create_artifact(artifact_name=name()) | ||
lineage_resource_helper.create_association(source_arn=art1, dest_arn=art2) | ||
lineage_resource_helper.clean_all() | ||
jkasiraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
except Exception as e: | ||
print(e) | ||
assert False | ||
|
||
|
||
@pytest.mark.skip("visualizer load test") | ||
def test_wide_graph_visualize(sagemaker_session): | ||
lineage_resource_helper = LineageResourceHelper(sagemaker_session=sagemaker_session) | ||
wide_graph_root_arn = lineage_resource_helper.create_artifact(artifact_name=name()) | ||
|
||
# create wide graph | ||
# Artifact ----> Artifact | ||
# \ \ \-> Artifact | ||
# \ \--> Artifact | ||
# \---> ... | ||
try: | ||
for i in range(10): | ||
artifact_arn = lineage_resource_helper.create_artifact(artifact_name=name()) | ||
lineage_resource_helper.create_association( | ||
source_arn=wide_graph_root_arn, dest_arn=artifact_arn | ||
) | ||
except Exception as e: | ||
print(e) | ||
lineage_resource_helper.clean_all() | ||
assert False | ||
|
||
try: | ||
lq = sagemaker.lineage.query.LineageQuery(sagemaker_session) | ||
lq_result = lq.query(start_arns=[wide_graph_root_arn]) | ||
lq_result.visualize(path="wideGraph.html") | ||
except Exception as e: | ||
print(e) | ||
lineage_resource_helper.clean_all() | ||
assert False | ||
|
||
lineage_resource_helper.clean_all() | ||
|
||
|
||
@pytest.mark.skip("visualizer load test") | ||
def test_long_graph_visualize(sagemaker_session): | ||
lineage_resource_helper = LineageResourceHelper(sagemaker_session=sagemaker_session) | ||
long_graph_root_arn = lineage_resource_helper.create_artifact(artifact_name=name()) | ||
last_arn = long_graph_root_arn | ||
|
||
# create long graph | ||
# Artifact -> Artifact -> ... -> Artifact | ||
try: | ||
for i in range(10): | ||
new_artifact_arn = lineage_resource_helper.create_artifact(artifact_name=name()) | ||
lineage_resource_helper.create_association( | ||
source_arn=last_arn, dest_arn=new_artifact_arn | ||
) | ||
last_arn = new_artifact_arn | ||
except Exception as e: | ||
jkasiraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
print(e) | ||
lineage_resource_helper.clean_all() | ||
assert False | ||
|
||
try: | ||
lq = sagemaker.lineage.query.LineageQuery(sagemaker_session) | ||
lq_result = lq.query( | ||
start_arns=[long_graph_root_arn], direction=LineageQueryDirectionEnum.DESCENDANTS | ||
) | ||
# max depth = 10 -> graph rendered only has length of ten (in DESCENDANTS direction) | ||
lq_result.visualize(path="longGraph.html") | ||
except Exception as e: | ||
print(e) | ||
lineage_resource_helper.clean_all() | ||
assert False | ||
|
||
lineage_resource_helper.clean_all() | ||
|
||
|
||
def test_graph_visualize(sagemaker_session): | ||
lineage_resource_helper = LineageResourceHelper(sagemaker_session=sagemaker_session) | ||
|
||
# create lineage data | ||
# image artifact ------> model artifact(startarn) -> model deploy action -> endpoint context | ||
# /-> | ||
# dataset artifact -/ | ||
try: | ||
graph_startarn = lineage_resource_helper.create_artifact( | ||
artifact_name=name(), artifact_type="Model" | ||
) | ||
image_artifact = lineage_resource_helper.create_artifact( | ||
artifact_name=name(), artifact_type="Image" | ||
) | ||
lineage_resource_helper.create_association( | ||
source_arn=image_artifact, dest_arn=graph_startarn, association_type="ContributedTo" | ||
) | ||
dataset_artifact = lineage_resource_helper.create_artifact( | ||
artifact_name=name(), artifact_type="DataSet" | ||
) | ||
lineage_resource_helper.create_association( | ||
source_arn=dataset_artifact, dest_arn=graph_startarn, association_type="AssociatedWith" | ||
) | ||
modeldeploy_action = lineage_resource_helper.create_action( | ||
action_name=name(), action_type="ModelDeploy" | ||
) | ||
lineage_resource_helper.create_association( | ||
source_arn=graph_startarn, dest_arn=modeldeploy_action, association_type="ContributedTo" | ||
) | ||
endpoint_context = lineage_resource_helper.create_context( | ||
context_name=name(), context_type="Endpoint" | ||
) | ||
lineage_resource_helper.create_association( | ||
source_arn=modeldeploy_action, | ||
dest_arn=endpoint_context, | ||
association_type="AssociatedWith", | ||
) | ||
time.sleep(1) | ||
except Exception as e: | ||
print(e) | ||
lineage_resource_helper.clean_all() | ||
assert False | ||
|
||
# visualize | ||
try: | ||
lq = sagemaker.lineage.query.LineageQuery(sagemaker_session) | ||
lq_result = lq.query(start_arns=[graph_startarn]) | ||
lq_result.visualize(path="testGraph.html") | ||
except Exception as e: | ||
print(e) | ||
lineage_resource_helper.clean_all() | ||
assert False | ||
|
||
# check generated graph info | ||
try: | ||
fo = open("testGraph.html", "r") | ||
jkasiraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
lines = fo.readlines() | ||
for line in lines: | ||
if "nodes = " in line: | ||
node = line | ||
if "edges = " in line: | ||
edge = line | ||
|
||
# extract node data | ||
start = node.find("[") | ||
end = node.find("]") | ||
res = node[start + 1 : end].split("}, ") | ||
res = [i + "}" for i in res] | ||
res[-1] = res[-1][:-1] | ||
node_dict = [json.loads(i) for i in res] | ||
|
||
# extract edge data | ||
start = edge.find("[") | ||
end = edge.find("]") | ||
res = edge[start + 1 : end].split("}, ") | ||
res = [i + "}" for i in res] | ||
res[-1] = res[-1][:-1] | ||
edge_dict = [json.loads(i) for i in res] | ||
|
||
# check node number | ||
assert len(node_dict) == 5 | ||
|
||
# check startarn | ||
found_value = next( | ||
dictionary for dictionary in node_dict if dictionary["id"] == graph_startarn | ||
jkasiraj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
assert found_value["color"] == "#146eb4" | ||
assert found_value["label"] == "Model" | ||
assert found_value["shape"] == "star" | ||
assert found_value["title"] == "Artifact" | ||
|
||
# check image artifact | ||
found_value = next( | ||
dictionary for dictionary in node_dict if dictionary["id"] == image_artifact | ||
) | ||
assert found_value["color"] == "#146eb4" | ||
assert found_value["label"] == "Image" | ||
assert found_value["shape"] == "dot" | ||
assert found_value["title"] == "Artifact" | ||
|
||
# check dataset artifact | ||
found_value = next( | ||
dictionary for dictionary in node_dict if dictionary["id"] == dataset_artifact | ||
) | ||
assert found_value["color"] == "#146eb4" | ||
assert found_value["label"] == "DataSet" | ||
assert found_value["shape"] == "dot" | ||
assert found_value["title"] == "Artifact" | ||
|
||
# check modeldeploy action | ||
found_value = next( | ||
dictionary for dictionary in node_dict if dictionary["id"] == modeldeploy_action | ||
) | ||
assert found_value["color"] == "#88c396" | ||
assert found_value["label"] == "ModelDeploy" | ||
assert found_value["shape"] == "dot" | ||
assert found_value["title"] == "Action" | ||
|
||
# check endpoint context | ||
found_value = next( | ||
dictionary for dictionary in node_dict if dictionary["id"] == endpoint_context | ||
) | ||
assert found_value["color"] == "#ff9900" | ||
assert found_value["label"] == "Endpoint" | ||
assert found_value["shape"] == "dot" | ||
assert found_value["title"] == "Context" | ||
|
||
# check edge number | ||
assert len(edge_dict) == 4 | ||
|
||
# check image_artifact -> model_artifact(startarn) edge | ||
found_value = next( | ||
dictionary for dictionary in edge_dict if dictionary["from"] == image_artifact | ||
) | ||
assert found_value["to"] == graph_startarn | ||
assert found_value["title"] == "ContributedTo" | ||
|
||
# check dataset_artifact -> model_artifact(startarn) edge | ||
found_value = next( | ||
dictionary for dictionary in edge_dict if dictionary["from"] == dataset_artifact | ||
) | ||
assert found_value["to"] == graph_startarn | ||
assert found_value["title"] == "AssociatedWith" | ||
|
||
# check model_artifact(startarn) -> modeldeploy_action edge | ||
found_value = next( | ||
dictionary for dictionary in edge_dict if dictionary["from"] == graph_startarn | ||
) | ||
assert found_value["to"] == modeldeploy_action | ||
assert found_value["title"] == "ContributedTo" | ||
|
||
# check modeldeploy_action -> endpoint_context edge | ||
found_value = next( | ||
dictionary for dictionary in edge_dict if dictionary["from"] == modeldeploy_action | ||
) | ||
assert found_value["to"] == endpoint_context | ||
assert found_value["title"] == "AssociatedWith" | ||
|
||
except Exception as e: | ||
print(e) | ||
lineage_resource_helper.clean_all() | ||
os.remove("testGraph.html") | ||
assert False | ||
|
||
# delete generated test graph | ||
os.remove("testGraph.html") | ||
# clean lineage data | ||
lineage_resource_helper.clean_all() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.