Skip to content

Commit

Permalink
Updated the "Basic - Parallel execution" sample (#1110)
Browse files Browse the repository at this point in the history
Modernized the sample pipeline code.
  • Loading branch information
Ark-kun authored and k8s-ci-robot committed Apr 19, 2019
1 parent 866cc81 commit 6e7e7b3
Showing 1 changed file with 35 additions and 29 deletions.
64 changes: 35 additions & 29 deletions samples/basic/parallel_join.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# Copyright 2018 Google LLC
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,38 +14,44 @@
# limitations under the License.


import kfp.dsl as dsl
import kfp
from kfp import dsl

def gcs_download_op(url):
return dsl.ContainerOp(
name='GCS - Download',
image='google/cloud-sdk:216.0.0',
command=['sh', '-c'],
arguments=['gsutil cat $0 | tee $1', url, '/tmp/results.txt'],
file_outputs={
'data': '/tmp/results.txt',
}
)


def echo2_op(text1, text2):
return dsl.ContainerOp(
name='echo',
image='library/bash:4.4.23',
command=['sh', '-c'],
arguments=['echo "Text 1: $0"; echo "Text 2: $1"', text1, text2]
)


@dsl.pipeline(
name='Parallel_and_Join',
description='Download two messages in parallel and print the concatenated result.'
name='Parallel pipeline',
description='Download two messages in parallel and prints the concatenated result.'
)
def download_and_join(
url1='gs://ml-pipeline-playground/shakespeare1.txt',
url2='gs://ml-pipeline-playground/shakespeare2.txt'):
"""A three-step pipeline with first two running in parallel."""

download1 = dsl.ContainerOp(
name='download1',
image='google/cloud-sdk:216.0.0',
command=['sh', '-c'],
arguments=['gsutil cat %s | tee /tmp/results.txt' % url1],
file_outputs={'downloaded': '/tmp/results.txt'})

download2 = dsl.ContainerOp(
name='download2',
image='google/cloud-sdk:216.0.0',
command=['sh', '-c'],
arguments=['gsutil cat %s | tee /tmp/results.txt' % url2],
file_outputs={'downloaded': '/tmp/results.txt'})

echo = dsl.ContainerOp(
name='echo',
image='library/bash:4.4.23',
command=['sh', '-c'],
arguments=['echo %s %s' % (download1.output, download2.output)])
url1='gs://ml-pipeline-playground/shakespeare1.txt',
url2='gs://ml-pipeline-playground/shakespeare2.txt'
):
"""A three-step pipeline with first two running in parallel."""

download1_task = gcs_download_op(url1)
download2_task = gcs_download_op(url2)

echo_task = echo2_op(download1_task.output, download2_task.output)

if __name__ == '__main__':
import kfp.compiler as compiler
compiler.Compiler().compile(download_and_join, __file__ + '.zip')
kfp.compiler.Compiler().compile(download_and_join, __file__ + '.zip')

0 comments on commit 6e7e7b3

Please sign in to comment.