DSL Recursion

    This page describes how to write recursive functions in the domain specific language (DSL) provided by the Kubeflow Pipelines SDK.

    Decorate the recursive function with kfp.dsl.graph_componentas illustrated below. The decorator does not require any arguments.

    Similar to the pipeline function body, you can instantiate components, create ,use the input parameters from the function signature, and specify dependencies explicitly among components.In the example above, one condition is created inside the recursive function andtwo components op_a and op_b are created inside the condition.

    Here is another example where the recursive function call is at the end of the function body, similar to do-while loops.

    1. @dsl.graph_component
    2. def graph_component_a(input_x):
    3. op_a = task_factory_a(input_x)
    4. op_b = task_factory_b().after(op_a)
    5. with dsl.Condition(op_b.output == 'value_x'):
    6. @dsl.pipeline(
    7. name='pipeline',
    8. )
    9. op_a = task_factory_a()
    10. op_b = task_factory_b()
    11. graph_op_a = graph_component_a(op_a.output)
    12. graph_op_a.after(op_b)
    13. task_factory_c(op_a.output).after(graph_op_a)
    • does not work for the recursive functions. In other words, The type information that is annotated to the recursivefunction signature will not be checked.
    • Since the output of the recursive functions cannot be dynamically resolved, the downstream ContainerOps cannotaccess the output from the recursive functions.