Luke Segars
12/12/2021, 4:17 AMadd(1, 10, 100)
, add(1, 10, 200)
, add(1, 10, 300)
, add(1, 20, 100)
, etc, with combinations similar to the results of itertools.product
in standard python
@task
def add(x, y, z):
return x + y + z
@task
def print_all(results):
print(results)
with Flow('Run combinations') as flow:
a = [1, 2, 3]
b = [10, 20, 30]
c = [100, 200, 300]
results = add.map(a, b, c)
print_all(results)
flow.run()
Luke Segars
12/12/2021, 4:19 AMAnna Geller
import itertools
from prefect import task, Flow
from prefect.executors import LocalDaskExecutor
@task
def generate_random_numbers():
list_of_tuples = list(itertools.product((1, 2, 3), (10, 20, 30), (100, 200, 300)))
return list_of_tuples
@task
def sum_all(x):
return sum(x)
@task(log_stdout=True)
def print_results(res):
print(res)
with Flow("mapping", executor=LocalDaskExecutor()) as flow:
numbers = generate_random_numbers()
result = sum_all.map(numbers)
print_results(result)
if __name__ == "__main__":
flow.run()