def my_wf(a: int, b: str) -> (int, str):
     x, y = t1(a=a)
     d = conditional("test1").if_(x == 4).then(
         t2(a=b)).elif_(x >= 5).then(t2(a=y))
     conditional("test2").if_(x == 4).then(
         t2(a=b)).elif_(x >= 5).then(t2(a=y)).else_().fail("blah")
     return x, d
 def my_wf(a: int, b: str) -> (int, str):
     x, y = t1(a=a)
     d = (conditional("test1").if_(x == 4).then(t2(a=b)).elif_(x >= 5).then(
         t2(a=y)).else_().fail("Unable to choose branch"))
     f = conditional("test2").if_(d == "hello ").then(
         t2(a="It is hello")).else_().then(t2(a="Not Hello!"))
     return x, f
Beispiel #3
0
 def multiplier_2(my_input: float) -> float:
     return (conditional("fractions").if_(
         (my_input > 0.1) & (my_input < 1.0)).then(
             conditional("inner_fractions").if_(my_input < 0.5).then(
                 double(n=my_input)).else_().fail("Only <0.5 allowed")).
             elif_((my_input > 1.0) & (my_input < 10.0)).then(
                 square(n=my_input)).else_().fail(
                     "The input must be between 0 and 10"))
 def merge_sort(in1: typing.List[int], count: int) -> typing.List[int]:
     return (
         conditional("terminal_case")
         .if_(count < 500)
         .then(merge_sort_locally(in1=in1))
         .elif_(count < 1000)
         .then(also_merge_sort_locally(in1=in1))
         .else_()
         .then(merge_sort_remotely(in1=in1))
     )
Beispiel #5
0
    def math_ops(a: int, b: int) -> typing.Tuple[int, int]:
        add, sub = (
            conditional("noDivByZero")
            .if_(a > b)
            .then(sum_sub(a=a, b=b))
            .else_()
            .fail("Only positive results are allowed")
        )

        return add, sub
Beispiel #6
0
    def math_ops(a: int, b: int) -> (int, int):
        # Flyte will only make `sum` and `sub` available as outputs because they are common between all branches
        sum, sub = (
            conditional("noDivByZero")
            .if_(a > b)
            .then(sum_sub(a=a, b=b))
            .else_()
            .fail("Only positive results are allowed")
        )

        return sum, sub
Beispiel #7
0
 def if_elif_else_branching(x: int) -> int:
     return (
         conditional("test")
         .if_(x == 2)
         .then(wf1())
         .elif_(x == 3)
         .then(wf2())
         .elif_(x == 4)
         .then(wf3())
         .else_()
         .then(wf4())
     )
Beispiel #8
0
 def my_wf(a: int, b: str) -> (int, str):
     x, y = t1(a=a)
     d = (
         conditional("test1")
         .if_(x == 4)
         .then(t2(a=b))
         .elif_(x >= 5)
         .then(t2(a=y))
         .else_()
         .fail("All Branches failed")
     )
     return x, d
Beispiel #9
0
def my_wf_example(a: int) -> typing.Tuple[int, int]:
    """example

    Workflows can have inputs and return outputs of simple or complex types.

    :param a: input a
    :return: outputs
    """

    x = add_5(a=a)

    # You can use outputs of a previous task as inputs to other nodes.
    z = add_5(a=x)

    # You can call other workflows from within this workflow
    d = simple_wf()

    # You can add conditions that can run on primitive types and execute different branches
    e = conditional("bool").if_(a == 5).then(add_5(a=d)).else_().then(add_5(a=z))

    # Outputs of the workflow have to be outputs returned by prior nodes.
    # No outputs and single or multiple outputs are supported
    return x, e
Beispiel #10
0
 def branching(x: int) -> int:
     return conditional("test").if_(x == 2).then(t().b).else_().then(
         wf1().b)
Beispiel #11
0
 def nested_branching(x: int) -> int:
     return conditional("nested test").if_(x == 2).then(
         ifelse_branching(x=x)).else_().then(wf5())
Beispiel #12
0
 def ifelse_branching_fail(x: int) -> int:
     return conditional("simple branching test").if_(x == 2).then(
         wf1()).else_().fail("failed")
Beispiel #13
0
 def decompose() -> int:
     result = return_true()
     return conditional("test").if_(result.is_true()).then(
         success()).else_().then(failed())
Beispiel #14
0
 def decompose_none() -> int:
     return conditional("test").if_(None).then(success()).else_().then(
         failed())
Beispiel #15
0
 def wf(a: bool = True) -> bool:
     return conditional("bool").if_(a.is_true()).then(t()).else_().then(f())
 def my_wf(a: int, b: str) -> str:
     new_a = t1(a=a)
     return conditional("test1").if_(new_a != 5).then(
         t2(a=b)).else_().fail("Unable to choose branch")
 def my_wf(a: int) -> str:
     c = mimic(a=a)
     return conditional("test1").if_(c.c == 4).then(
         t1(c=c.c).c).else_().then(t2().c)
 def my_wf(a: int) -> int:
     d = (conditional("test1").if_((a == 4) | (a == 3)).then(t1(a=a)).elif_(
         a < 6).then(t1(a=a)).else_().fail("Unable to choose branch"))
     return d
 def my_wf(a: int) -> int:
     d = conditional("test1").if_(a > 3).then(t1(a=a)).else_().then(
         my_sub_wf(a=a))
     return d