Rahul Mehta
10/18/2022, 4:35 PMconditional
inside a @dynamic
step or should normal python control flow work there? We're seeing a number of issues w/ failing to bind variables in a dynamic workflow using normal `if`/`else` blocksSamhita Alla
conditional
supported within dynamic workflows?Kevin Su
10/18/2022, 4:47 PMRahul Mehta
10/18/2022, 4:51 PM@dynamic
step (regress
is a boolean)
Logical (and/or/is/not) operations are not supported. Expressions Comparison (<,<=,>,>=,==,!=) or Conjunction (&/|) are supported.Received an evaluated expression with val False in train_estimator.if_
flytekit.conditional("train_estimator")
.if_(regress)
.then(
estimator.train_regressor()
)
.else_()
.then(
estimator.train_classifier()
)
flytekit.conditional
? (I also tried regress == True
as well and that resulted in the same error)Kevin Su
10/18/2022, 8:41 PMfrom flytekit import workflow, task, dynamic, conditional
@task
def t1() -> bool:
return True
@task
def t2() -> bool:
return False
@dynamic
def d1() -> bool:
a = t1()
return (
conditional("train_estimator")
.if_(a==True)
.then(t2())
.else_()
.then(t2()))
@workflow
def wf() -> bool:
return d1()
if __name__ == "__main__":
print(wf())
Rahul Mehta
10/18/2022, 8:41 PMa
is an arg to d1
vs the result of a task?Kevin Su
10/18/2022, 8:42 PMregress == True
instead of regress
. Otherwise, it will faildoes this work iflet me try it.is an arg toa
vs the result of a task?d1
a
is bool instead of promise.a
in the if statement must be a promiseRahul Mehta
10/18/2022, 8:49 PMPromise.of(my_literal)
(kind of abusing JavaScript notation here but you get the point)?Kevin Su
10/18/2022, 9:15 PMHm...ok. Is there a way to do something likewe don’t have that now, but you could add a task to convert it to a promise in @dynamic(kind of abusing JavaScript notation here but you get the point)?Promise.of(my_literal)
@task
def convert_to_promise(a: bool) -> bool:
return a
Or maybe another way, is there a reason preventing this from working w/ both promises and literalsI think we can support pure python type in
_if
as well. we can try to update it in the next release.
For now, to work around this issue, just create a @task to convert it to a promise, sorry.bool
or int
in _if
in condition
? currently, we can only use promise in condition.Rahul Mehta
10/18/2022, 10:05 PMKevin Su
10/18/2022, 10:45 PM