acoustic-carpenter-78188
03/20/2023, 5:02 PMdataclasses as the only way of passing multiple values to a map task.
from flytekit import task, workflow, map_task
import typing
import functools
@task
def generate(n: int) -> typing.List[int]:
return list(range(n))
@task
def square_add(i: int, j: int) -> int:
return i*i + j
@workflow
def wf(n: int) -> typing.List[int]:
l = generate(n=n)
square = functools.partial(square_add, j=10)
return map_task(square)(i=l)
It is possible to bind promises to partials
@workflow
def wf(n: int) -> typing.List[int]:
l = generate(n=n)
square = functools.partial(square_add, j=n). # notice n is a promise
return map_task(square)(i=l)
*Support for passing multiple lists using map_tasks *
from flytekit import task, workflow, map_task
import typing
import functools
@task
def generate(n: int) -> typing.List[int]:
return list(range(n))
@task
def square_add(i: int, j: int) -> int:
return i*i + j
@workflow
def wf(n: int) -> typing.List[int]:
l = generate(n=n)
return map_task(p)(i=l, j=l)
from flytekit import task, workflow, map_task
import typing
import functools
@task
def generate(n: int) -> typing.List[int]:
return list(range(n))
@task
def square_add(i: int, j: int, k: int) -> int:
return i*i + j + k
@workflow
def wf(n: int) -> typing.List[int]:
l = generate(n=n)
p = functools.partial(square_add, k=n)
return map_task(p)(i=l, j=l)
Note: In addition this PR also verifies that it is possible to use partial functions in flytekit, as follows,
from flytekit import task, workflow
import functools
@task
def tk(i: int) -> int:
return i + 1
@workflow
def wf():
p = functools.partial(tk, i=10) # Note binding to a constant value
x = p()
p2 = functools.partial(tk, i=x) # Note binding to a promise
p2()
Type
☐ Bug Fix
☑︎ Feature
☐ Plugin
Are all requirements met?
☐ Code completed
☑︎ Smoke tested
☐ Unit tests added
☑︎ Code documentation added
☑︎ Any pending items have an associated Issue
Complete description
How did you fix the bug, make the feature etc. Link to any design docs etc
Tracking Issue
flyteorg/flyte#3403
flyteorg/flytekit
✅ All checks have passed
30/30 successful checksacoustic-carpenter-78188
03/29/2023, 6:29 PM