From 1b7f67eba7ed5c7e126b718d5ba226ee5a8eb2ab Mon Sep 17 00:00:00 2001 From: James Liu Date: Mon, 28 Jun 2021 15:32:36 -0700 Subject: [PATCH 1/4] feat(sample) Add markdown visualization example for v1 and v2 compatible --- samples/core/visualization/markdown.py | 61 +++++++++++++++++++++ samples/core/visualization/markdown_test.py | 29 ++++++++++ 2 files changed, 90 insertions(+) create mode 100644 samples/core/visualization/markdown.py create mode 100644 samples/core/visualization/markdown_test.py diff --git a/samples/core/visualization/markdown.py b/samples/core/visualization/markdown.py new file mode 100644 index 00000000000..f2b98c4a79f --- /dev/null +++ b/samples/core/visualization/markdown.py @@ -0,0 +1,61 @@ +# Copyright 2021 The Kubeflow Authors +# +# 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. + +import kfp.dsl as dsl +import kfp.components as comp + +# Advanced function +# Demonstrates imports, helper functions and multiple outputs +from typing import NamedTuple + + +def markdown_visualization() -> NamedTuple('VisualizationOutput', [('mlpipeline_ui_metadata', 'UI_metadata')]): + import json + + # Exports a sample tensorboard: + metadata = { + 'outputs': [ + { + # Markdown that is hardcoded inline + 'storage': 'inline', + 'source': '# Inline Markdown\n[A link](https://www.kubeflow.org/)', + 'type': 'markdown', + }, + { + # Markdown that is read from a file + 'source': 'https://raw.githubusercontent.com/kubeflow/pipelines/master/README.md', + # Alternatively, use Google Cloud Storage for sample. + # 'source': 'gs://jamxl-kfp-bucket/v2-compatible/markdown/markdown_example.md', + 'type': 'markdown', + }] + } + + from collections import namedtuple + divmod_output = namedtuple('VisualizationOutput', [ + 'mlpipeline_ui_metadata']) + return divmod_output(json.dumps(metadata)) + + +markdown_visualization_op = comp.func_to_container_op( + markdown_visualization, base_image='tensorflow/tensorflow:1.11.0-py3') + + +@dsl.pipeline( + name='calculation-pipeline', + description='A toy pipeline that performs arithmetic calculations.' +) +def markdown_pipeline(): + # Passing a task output reference as operation arguments + # For an operation with a single return value, the output reference can be accessed using `task.output` or `task.outputs['output_name']` syntax + markdown_visualization_task = markdown_visualization_op() diff --git a/samples/core/visualization/markdown_test.py b/samples/core/visualization/markdown_test.py new file mode 100644 index 00000000000..c5f79b105a1 --- /dev/null +++ b/samples/core/visualization/markdown_test.py @@ -0,0 +1,29 @@ +# Copyright 2021 The Kubeflow Authors +# +# 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 .markdown import markdown_pipeline +from ...test.util import run_pipeline_func, TestCase + +import kfp + +run_pipeline_func([TestCase(pipeline_func=markdown_pipeline, + mode=kfp.dsl.PipelineExecutionMode.V2_COMPATIBLE, + arguments={ + kfp.dsl.ROOT_PARAMETER_NAME: + 'minio://mlpipeline/override/artifacts' + }), + TestCase(pipeline_func=markdown_pipeline, + mode=kfp.dsl.PipelineExecutionMode.V1_LEGACY + )]) From 7e5365743253a20d00804188d5e8a711e88786d6 Mon Sep 17 00:00:00 2001 From: James Liu Date: Mon, 28 Jun 2021 20:51:10 -0700 Subject: [PATCH 2/4] address comment --- samples/core/visualization/markdown.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/samples/core/visualization/markdown.py b/samples/core/visualization/markdown.py index f2b98c4a79f..0e7e813c566 100644 --- a/samples/core/visualization/markdown.py +++ b/samples/core/visualization/markdown.py @@ -29,7 +29,11 @@ def markdown_visualization() -> NamedTuple('VisualizationOutput', [('mlpipeline_ { # Markdown that is hardcoded inline 'storage': 'inline', - 'source': '# Inline Markdown\n[A link](https://www.kubeflow.org/)', + 'source': ''' + # Inline Markdown + + * [Kubeflow official doc](https://www.kubeflow.org/), + ''', 'type': 'markdown', }, { @@ -52,8 +56,8 @@ def markdown_visualization() -> NamedTuple('VisualizationOutput', [('mlpipeline_ @dsl.pipeline( - name='calculation-pipeline', - description='A toy pipeline that performs arithmetic calculations.' + name='markdown-pipeline', + description='A sample pipeline to generate markdown for UI visualization.' ) def markdown_pipeline(): # Passing a task output reference as operation arguments From 99d71aab75aa35bdbdfd6c6c64bba82511fd6e23 Mon Sep 17 00:00:00 2001 From: James Liu Date: Mon, 28 Jun 2021 20:58:01 -0700 Subject: [PATCH 3/4] use multi line markdown --- samples/core/visualization/markdown.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/samples/core/visualization/markdown.py b/samples/core/visualization/markdown.py index 0e7e813c566..94c7b3075a4 100644 --- a/samples/core/visualization/markdown.py +++ b/samples/core/visualization/markdown.py @@ -29,11 +29,10 @@ def markdown_visualization() -> NamedTuple('VisualizationOutput', [('mlpipeline_ { # Markdown that is hardcoded inline 'storage': 'inline', - 'source': ''' - # Inline Markdown + 'source': '''# Inline Markdown - * [Kubeflow official doc](https://www.kubeflow.org/), - ''', +* [Kubeflow official doc](https://www.kubeflow.org/). +''', 'type': 'markdown', }, { From 44a28c28d681c7bc53034e64fbe361d046188a13 Mon Sep 17 00:00:00 2001 From: "Yuan (Bob) Gong" <4957653+Bobgy@users.noreply.github.com> Date: Tue, 29 Jun 2021 18:57:37 +0800 Subject: [PATCH 4/4] Update markdown.py --- samples/core/visualization/markdown.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/samples/core/visualization/markdown.py b/samples/core/visualization/markdown.py index 94c7b3075a4..9c93da32634 100644 --- a/samples/core/visualization/markdown.py +++ b/samples/core/visualization/markdown.py @@ -19,7 +19,7 @@ # Demonstrates imports, helper functions and multiple outputs from typing import NamedTuple - +@comp.create_component_from_func def markdown_visualization() -> NamedTuple('VisualizationOutput', [('mlpipeline_ui_metadata', 'UI_metadata')]): import json @@ -50,10 +50,6 @@ def markdown_visualization() -> NamedTuple('VisualizationOutput', [('mlpipeline_ return divmod_output(json.dumps(metadata)) -markdown_visualization_op = comp.func_to_container_op( - markdown_visualization, base_image='tensorflow/tensorflow:1.11.0-py3') - - @dsl.pipeline( name='markdown-pipeline', description='A sample pipeline to generate markdown for UI visualization.' @@ -61,4 +57,4 @@ def markdown_visualization() -> NamedTuple('VisualizationOutput', [('mlpipeline_ def markdown_pipeline(): # Passing a task output reference as operation arguments # For an operation with a single return value, the output reference can be accessed using `task.output` or `task.outputs['output_name']` syntax - markdown_visualization_task = markdown_visualization_op() + markdown_visualization_task = markdown_visualization()