forked from opendatahub-io/data-science-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(backend): Support loop pipelineruns of defining dictionaries par…
…ams (kubeflow#460)
- Loading branch information
Showing
21 changed files
with
1,433 additions
and
23 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
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
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
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
81 changes: 81 additions & 0 deletions
81
sdk/python/tests/compiler/testdata/parallelfor_item_argument_resolving.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,81 @@ | ||
# Copyright 2021 kubeflow.org | ||
# | ||
# 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 | ||
from kfp.components import func_to_container_op | ||
|
||
|
||
# Stabilizing the test output | ||
class StableIDGenerator: | ||
def __init__(self, ): | ||
self._index = 0 | ||
|
||
def get_next_id(self, ): | ||
self._index += 1 | ||
return '{code:0{num_chars:}d}'.format(code=self._index, num_chars=kfp.dsl._for_loop.LoopArguments.NUM_CODE_CHARS) | ||
|
||
|
||
kfp.dsl.ParallelFor._get_unique_id_code = StableIDGenerator().get_next_id | ||
|
||
|
||
@func_to_container_op | ||
def produce_str() -> str: | ||
return "Hello" | ||
|
||
|
||
@func_to_container_op | ||
def produce_list_of_dicts() -> list: | ||
return ({"aaa": "aaa1", "bbb": "bbb1"}, {"aaa": "aaa2", "bbb": "bbb2"}) | ||
|
||
|
||
@func_to_container_op | ||
def produce_list_of_strings() -> list: | ||
return ("a", "z") | ||
|
||
|
||
@func_to_container_op | ||
def produce_list_of_ints() -> list: | ||
return (1234567890, 987654321) | ||
|
||
|
||
@func_to_container_op | ||
def consume(param1): | ||
print(param1) | ||
|
||
|
||
@kfp.dsl.pipeline() | ||
def parallelfor_item_argument_resolving(): | ||
produce_str_task = produce_str() | ||
produce_list_of_strings_task = produce_list_of_strings() | ||
produce_list_of_ints_task = produce_list_of_ints() | ||
produce_list_of_dicts_task = produce_list_of_dicts() | ||
|
||
with kfp.dsl.ParallelFor(produce_list_of_strings_task.output) as loop_item: | ||
consume(produce_list_of_strings_task.output) | ||
consume(loop_item) | ||
consume(produce_str_task.output) | ||
|
||
with kfp.dsl.ParallelFor(produce_list_of_ints_task.output) as loop_item: | ||
consume(produce_list_of_ints_task.output) | ||
consume(loop_item) | ||
|
||
with kfp.dsl.ParallelFor(produce_list_of_dicts_task.output) as loop_item: | ||
consume(produce_list_of_dicts_task.output) | ||
# consume(loop_item) # Cannot use the full loop item when it's a dict | ||
consume(loop_item.aaa) | ||
|
||
|
||
if __name__ == '__main__': | ||
from kfp_tekton.compiler import TektonCompiler | ||
TektonCompiler().compile(parallelfor_item_argument_resolving, __file__.replace('.py', '.yaml')) |
Oops, something went wrong.