Hi, I am having some trouble with running prefect ...
# ask-community
b
Hi, I am having some trouble with running prefect tasks correctly where there is more than one mapped variable ( in addition to unmapped variables). In my case, prefect task is not executing over all combinations of the two mapped different variables, but is iterating over random selection of the same. Is this by design /known behaviour/bug ?
1
k
Hey @Bhavya M! I’ll have to get back to you tom but could you give a small code snippet of what you’re trying to do?
b
Hi @Kevin Kho - here is the example - https://gist.github.com/mbhavya/a94f59203853316d37722533984a5d4a, the flow run log is in comments.
What I want actually is task to map over all combinations of both the arrays.
k
You will need an intermediate task like this:
Copy code
from prefect import Flow, context, task, unmapped

@task
def say_hello(a, n, x):
    print(a, n, x)

@task(nout=2)
def cross_product(x_list, y_list):
    test = [(x, y) for x in x_list for y in y_list]
    return [x[0] for x in test], [x[1] for x in test]

with Flow("Example Flow!") as flow:
    alphabets = ['a', 'b', 'c', 'd']
    numbers = [1, 2, 3, 4, 5]
    unmapped_constant = 'x'
    alphabets, numbers = cross_product(alphabets, numbers)
    say_hello.map(alphabets, numbers, unmapped(unmapped_constant))

flow.run()
🙏 1
b
I will try this out. Thanks a lot for reverting back so fast!
👍 1
k
And yes map is not designed to get the cross-product. It’s designed for depth first execution from consecutive mapped tasks.
👀 1