From 2950b9f6855f7df89f2a922d18c5beec162253ef Mon Sep 17 00:00:00 2001 From: Yi-Ting Lee Date: Mon, 8 Aug 2022 11:18:00 -0700 Subject: [PATCH 1/2] documentation: add visualize & PyvisVisualizer documentation --- src/sagemaker/lineage/query.py | 55 ++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/src/sagemaker/lineage/query.py b/src/sagemaker/lineage/query.py index 0acdccd698..c44e439b5a 100644 --- a/src/sagemaker/lineage/query.py +++ b/src/sagemaker/lineage/query.py @@ -230,7 +230,31 @@ class PyvisVisualizer(object): """Create object used for visualizing graph using Pyvis library.""" def __init__(self, graph_styles): - """Init for PyvisVisualizer.""" + """Init for PyvisVisualizer. + + Args: + graph_styles: A dictionary that contains graph style for node and edges by their type. + Example: Display the nodes with different color by their lineage entity / different shape by start arn. + lineage_graph = { + "TrialComponent": { + "name": "Trial Component", + "style": {"background-color": "#f6cf61"}, + "isShape": "False", + }, + "Context": { + "name": "Context", + "style": {"background-color": "#ff9900"}, + "isShape": "False", + }, + "StartArn": { + "name": "StartArn", + "style": {"shape": "star"}, + "isShape": "True", + "symbol": "★", # shape symbol for legend + }, + } + + """ # import visualization packages ( self.Network, @@ -283,7 +307,22 @@ def _node_color(self, entity): return self.graph_styles[entity]["style"]["background-color"] def render(self, elements, path="pyvisExample.html"): - """Render graph for lineage query result.""" + """Render graph for lineage query result. + + Args: + elements: A dictionary that contains the node and the edges of the graph. + Example: + elements["nodes"] contains a list of tuples, each tuple represents a node in the format + (node arn, node lineage source, node lineage entity, node is start arn) + elements["edges"] contains a list of tuples, each tuple represents an edge in the format + (edge source arn, edge destination arn, edge association type) + + path(optional): The path/filemname of the rendered graph html file. (default path: "pyvisExample.html") + + Returns: + display graph: The interactive visualization is presented as a static HTML file. + + """ net = self.Network(height="500px", width="100%", notebook=True, directed=True) net.set_options(self._options) @@ -384,7 +423,17 @@ def _get_visualization_elements(self): return elements def visualize(self, path="pyvisExample.html"): - """Visualize lineage query result.""" + """Visualize lineage query result. + + Creates a PyvisVisualizer object to render network graph with Pyvis library. The elements(nodes & edges) are + preprocessed in this method and sent to PyvisVisualizer for rendering graph. + + Args: + path(optional): The path/filemname of the rendered graph html file. (default path: "pyvisExample.html") + + Returns: + display graph: The interactive visualization is presented as a static HTML file. + """ lineage_graph = { # nodes can have shape / color "TrialComponent": { From 143143d7cdee94aebcd2c371508fa5743d33811f Mon Sep 17 00:00:00 2001 From: Yi-Ting Lee Date: Tue, 9 Aug 2022 10:44:48 -0700 Subject: [PATCH 2/2] doc: install pyvis before using visualize() --- src/sagemaker/lineage/query.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/sagemaker/lineage/query.py b/src/sagemaker/lineage/query.py index c44e439b5a..f6966d9fa3 100644 --- a/src/sagemaker/lineage/query.py +++ b/src/sagemaker/lineage/query.py @@ -234,7 +234,8 @@ def __init__(self, graph_styles): Args: graph_styles: A dictionary that contains graph style for node and edges by their type. - Example: Display the nodes with different color by their lineage entity / different shape by start arn. + Example: Display the nodes with different color by their lineage entity / different + shape by start arn. lineage_graph = { "TrialComponent": { "name": "Trial Component", @@ -312,10 +313,11 @@ def render(self, elements, path="pyvisExample.html"): Args: elements: A dictionary that contains the node and the edges of the graph. Example: - elements["nodes"] contains a list of tuples, each tuple represents a node in the format - (node arn, node lineage source, node lineage entity, node is start arn) - elements["edges"] contains a list of tuples, each tuple represents an edge in the format - (edge source arn, edge destination arn, edge association type) + elements["nodes"] contains list of tuples, each tuple represents a node + format: (node arn, node lineage source, node lineage entity, + node is start arn) + elements["edges"] contains list of tuples, each tuple represents an edge + format: (edge source arn, edge destination arn, edge association type) path(optional): The path/filemname of the rendered graph html file. (default path: "pyvisExample.html") @@ -425,8 +427,10 @@ def _get_visualization_elements(self): def visualize(self, path="pyvisExample.html"): """Visualize lineage query result. - Creates a PyvisVisualizer object to render network graph with Pyvis library. The elements(nodes & edges) are - preprocessed in this method and sent to PyvisVisualizer for rendering graph. + Creates a PyvisVisualizer object to render network graph with Pyvis library. + Pyvis library should be installed before using this method (run "pip install pyvis") + The elements(nodes & edges) are preprocessed in this method and sent to + PyvisVisualizer for rendering graph. Args: path(optional): The path/filemname of the rendered graph html file. (default path: "pyvisExample.html")