Skip to content
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

Fix recursive loop bug with no sub_group.ops #556

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions sdk/python/kfp_tekton/compiler/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,14 @@ def _group_to_dag_template(self, group, inputs, outputs, dependencies, pipeline_
self.loops_pipeline[group_name]['depends'].append({'org': depend, 'runAfter': group_name})
for op in sub_group.groups + sub_group.ops:
self.loops_pipeline[group_name]['task_list'].append(sanitize_k8s_name(op.name))
if hasattr(op, 'type') and op.type == 'condition' and op.ops:
for condition_op in op.ops:
self.loops_pipeline[group_name]['task_list'].append(sanitize_k8s_name(condition_op.name))
for condition_op in op.groups:
if condition_op.type == 'graph' and condition_op.recursive_ref:
if hasattr(op, 'type') and op.type == 'condition':
if op.ops:
for condition_op in op.ops:
self.loops_pipeline[group_name]['task_list'].append(sanitize_k8s_name(condition_op.name))
if op.groups:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we should still process groups inside condition even there's no op.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, because the recursion graph task is a op.groups, not op.ops

for condition_op in op.groups:
if condition_op.type == 'graph' and condition_op.recursive_ref:
self.loops_pipeline[group_name]['task_list'].append(sanitize_k8s_name(condition_op.name))
self.loops_pipeline[group_name]['spec']['name'] = group_name
self.loops_pipeline[group_name]['spec']['taskRef'] = {
"apiVersion": "custom.tekton.dev/v1alpha1",
Expand Down
7 changes: 7 additions & 0 deletions sdk/python/tests/compiler/compiler_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ def test_parallel_join_workflow(self):
from .testdata.parallel_join import download_and_join
self._test_pipeline_workflow(download_and_join, 'parallel_join.yaml')

def test_recur_cond_workflow(self):
"""
Test compiling a recurive condition workflow.
"""
from .testdata.recur_cond import recur_and_condition
self._test_pipeline_workflow(recur_and_condition, 'recur_cond.yaml')

def test_parallel_join_with_argo_vars_workflow(self):
"""
Test compiling a parallel join workflow.
Expand Down
44 changes: 44 additions & 0 deletions sdk/python/tests/compiler/testdata/recur_cond.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# 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.

from kfp import dsl
from kfp_tekton.tekton import CEL_ConditionOp


class PrintOp(dsl.ContainerOp):
def __init__(self, name: str, msg: str):
super(PrintOp, self).__init__(
name=name,
image='alpine:3.6',
command=['echo', msg, ">", "/tmp/stdout"],
file_outputs={"stdout": "/tmp/stdout"}
)


@dsl.graph_component
def recur(i: int):
decr_i = CEL_ConditionOp(f"{i} - 1").output
PrintOp("print-iter", f"Iter: {decr_i}")
with dsl.Condition(decr_i != 0):
recur(decr_i)


@dsl.pipeline("recur-and-condition")
def recur_and_condition(iter_num: int = 42):
recur(iter_num)


if __name__ == '__main__':
from kfp_tekton.compiler import TektonCompiler as Compiler
Compiler().compile(recur_and_condition, __file__.replace('.py', '.yaml'))
51 changes: 51 additions & 0 deletions sdk/python/tests/compiler/testdata/recur_cond.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# 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.

apiVersion: tekton.dev/v1beta1
kind: PipelineRun
metadata:
annotations:
pipelines.kubeflow.org/pipeline_spec: '{"inputs": [{"default": "42", "name": "iter_num",
"optional": true, "type": "Integer"}], "name": "recur-and-condition"}'
sidecar.istio.io/inject: 'false'
tekton.dev/artifact_bucket: mlpipeline
tekton.dev/artifact_endpoint: minio-service.kubeflow:9000
tekton.dev/artifact_endpoint_scheme: http://
tekton.dev/artifact_items: '{"print-iter": [["stdout", "$(results.stdout.path)"]]}'
tekton.dev/input_artifacts: '{"print-iter": [{"name": "condition-cel-status",
"parent_task": "condition-cel"}]}'
tekton.dev/output_artifacts: '{"print-iter": [{"key": "artifacts/$PIPELINERUN/print-iter/stdout.tgz",
"name": "print-iter-stdout", "path": "/tmp/stdout"}]}'
name: recur-and-condition
spec:
params:
- name: iter_num
value: '42'
pipelineSpec:
params:
- default: '42'
name: iter_num
tasks:
- name: recur-and-condition-graph-recur-1
params:
- name: iter_num
value: $(params.iter_num)
- name: just_one_iteration
value:
- '1'
taskRef:
apiVersion: custom.tekton.dev/v1alpha1
kind: PipelineLoop
name: recur-and-condition-graph-recur-1
timeout: 0s
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# 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.

apiVersion: custom.tekton.dev/v1alpha1
kind: PipelineLoop
metadata:
name: recur-and-condition-c6723-graph-recur-1
spec:
pipelineSpec:
params:
- name: just_one_iteration
type: string
- name: iter_num
type: string
tasks:
- name: condition-cel
params:
- name: status
value: $(params.iter_num) - 1
taskRef:
name: cel_condition
apiVersion: cel.tekton.dev/v1alpha1
kind: CEL
- name: print-iter
params:
- name: condition-cel-status
value: $(tasks.condition-cel.results.status)
taskSpec:
steps:
- name: main
command:
- echo
- 'Iter: $(inputs.params.condition-cel-status)'
- '>'
- $(results.stdout.path)
image: alpine:3.6
params:
- name: condition-cel-status
type: string
results:
- name: stdout
description: /tmp/stdout
metadata:
labels:
pipelines.kubeflow.org/pipelinename: ''
pipelines.kubeflow.org/generation: ''
pipelines.kubeflow.org/cache_enabled: "true"
annotations:
tekton.dev/template: ''
timeout: 0s
- name: recur
taskRef:
apiVersion: custom.tekton.dev/v1alpha1
kind: PipelineLoop
name: recur-and-condition-c6723-graph-recur-1
params:
- name: just_one_iteration
value:
- '1'
- name: iter_num
value: $(tasks.condition-cel.results.status)
when:
- input: $(tasks.condition-cel.results.status)
operator: notin
values:
- '0'
iterateParam: just_one_iteration