Summary
The user inquires about the feasibility of passing a function from a main workflow to a subworkflow, emphasizing the use of conditionals based on previous outputs and the @dynamic
feature for dynamic workflows. They provide an example of a user-defined function and seek clarification on the purpose of this method, questioning if the example is adequate for creating a workflow that permits others to implement their own versions. Additionally, they mention that task resolvers can be utilized for customizing function loading in a container, suggesting that while the desired functionality is achievable, further exploration and experimentation are necessary as there is no ready-made solution available.
kumare
ohh there is one way, i realized - @eager
kumare
we do not support tasks as parameters today
csv8674xn
what she is trying to do is more like this
def workflow_with_udf_input(user_passed_in_func: Type):
// some logic
result=user_passed_in_func()```
user's perspective
```def user_defined_function():
@workflow
def user_invoke_our_workflow():
// some logic
workflow_with_udf_input(user_defined_function)```
kumare
Use callable type, I’ll try later today
kumare
The only way to pass would be to use python to trigger
kumare
You can use pickle
habuelfutuh
there are task resolvers (advanced topic :slightly_smiling_face:) 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
habuelfutuh
I get that but I'm trying to uncover what is the purpose of that?
Would something like this suffice?
# 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?
aishi
Not really, more like
# 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```
habuelfutuh
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...
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
aishi
Hi :wave:, is there a way to pass in a function from a workflow into the subworkflow, and execute the user defined function inside the subworkflow?