Hi :wave:, is there a way to pass in a function fr...
# flyte-support
t
Hi 👋, is there a way to pass in a function from a workflow into the subworkflow, and execute the user defined function inside the subworkflow?
h
Are you trying to dynamically choose a function to execute? There are conditionals that you can use to decide based on a prior step's output or you can use
@dynamic
to run a fully dynamic workflow...
Copy code
@dynamic
def my_dynamic_wf(inputs...):
 ... call this or that
The dynamic workflow won't immediately call
this
or
that
but instead figure out the workflow graph then execute it after the function returns
t
Not really, more like
Copy code
def user_defined_function():
    # do something

@workflow
def subworkflow(custom_function: Any):
    custom_function()
    # do other things

@workflow
def workflow():
    subworkflow(custom_function=user_defined_function)
    # do more things
h
I get that but I'm trying to uncover what is the purpose of that? Would something like this suffice?
Copy code
def user_defined_function():
    # do something

@workflow
def subworkflow(custom_function_name: Any):
    conditional("func")._if(custom_function_name == "user_defined_function").then(custom_function())...
    # do other things

@workflow
def workflow():
    subworkflow(custom_function_name="user_defined_function")
    # do more things
Are you trying to build a workflow that others can use and substitute their own implementation for a portion of it?
there are task resolvers (advanced topic 🙂) that can be used to allow you to customize how to load the function in a given container... so you can pretty much do what you are trying to do but will need to explore/experiment with that as we don't have a ready-made recipe
f
You can use pickle
The only way to pass would be to use python to trigger
Use callable type, I’ll try later today
l
what she is trying to do is more like this
Copy code
@workflow
def workflow_with_udf_input(user_passed_in_func: Type):
  // some logic
  result=user_passed_in_func()
user's perspective
Copy code
def user_defined_function():

@workflow
def user_invoke_our_workflow():
  // some logic
  workflow_with_udf_input(user_defined_function)
f
we do not support tasks as parameters today
ohh there is one way, i realized -
@eager