Mark Fickett
04/26/2022, 2:07 PMdef mk_my_op(param):
@op
def work(context, input):
do_some_work(input, param)
@graph
def gr():
input = ..
mk_my_op(param)(input)
where input
is only know when the graph runs but param
is something I know when setting up the graph, like an enum value. Another structure I've used is:
@op
def return_constant():
return 'param'
@op
def work(context, param, input):
return do_some_work(input, param)
@graph
def gr():
param = return_constant()
input = ..
work(param, input)
However, having too many 'return a constant' ops slows down execution, especially for small/local test runs.alex
04/26/2022, 2:32 PMresource
could be an optiondef mk_my_op(param):
@op
def work(context, input, x=param):
do_some_work(input, x)
and it will use that default value if its not hooked up to another ops outputMark Fickett
04/26/2022, 2:37 PMclass Workflows(enum.Enum):
One = 1
Two = 2
Three = 3
And then my ops want to use the workflow value -- stick it in logs, pull different config values based on workflow, have slightly branching logic, etc. So the graph is kinda like:
@graph
def gr():
for workflow in Workflows:
result = my_op(workflow, other_input)
So a default value wouldn't work, because it does need to vary based on different times I'm using the op.
I think a resource could work, but it seems a little more cumbersome to implement than wrapping my op in a mk_my_op
.alex
04/26/2022, 2:41 PMMark Fickett
04/26/2022, 2:41 PM