It's not clear to me how to create this what I wou...
# flyte-support
b
It's not clear to me how to create this what I would suggest is a simple workflow. The workflow takes a list of integers and kicks off a
DoubleTask
for each integer. The
SumTask
collects the results from each
DoubleTask
and sums them up.
b
Hi Andy - have you looked into map_task?
gratitude thank you 1
b
I've tried to copy/paste this example, but I can't get the list of numbers (
numbers: typing.List[int]
) in via pyflyte
Copy code
pyflyte run --remote -p citrine -d development sum-doubles-wf.py double_and_sum_workflow --numbers '[1,2,3,4]'
image.png
I added a default values in the code and that also fails
t
the llm here is a bit misguided
though not entirely its fault.
workflow python code is more of a dsl rather than real python
as ramsey suggests, a map task makes more sense here. the underlying issue is that the workflow function is only used once, at compile time (local executions aside). the workflow function is run one time to determine the structure, and thereafter that structure remains static.
which means it’s not capable of running the double task a different number of times for different inputs. (your input should be correct btw)
(not tested, just writing it out) but try something like
Copy code
from flytekit import map_task

map_double = map_task(double)

@workflow
def double_and_sum_workflow(numbers: typing.List[int]) -> int:
    doubled_numbers = map_double(x=numbers)
    return sum_list(numbers=doubled_numbers)
b
Yeah, while that works, I'm fairly confident in saying that this is not possible using the current
jflyte
and
flytekit-java
machinery.
b
I might be misunderstanding, is this what you want @bumpy-match-83743 :
Copy code
@task
def double(x: int) -> int:
  return x * 2

@task
def sum_xs(xs: list[int]) -> int:
  return sum(xs)

@workflow
def double_wf(xs: list[int]) -> int:
  double_xs = map_task(double)(x=xs)
  return sum_xs(xs=double_xs)
🙇🏽 1