<jupyter_start><jupyter_text>Serial Execution<jupyter_code>def do_something_1(x, y):
    return x + y + 2*x*y

def do_something_2(a, b):
    return a**3 - b**3

def do_something_3(p, q):
    return p*p + q*q
x = [2, 4, 6, 8, 10]
y = [3, 6, 9, 12, 15]
z = [10, 20, 30, 40, 50]

final_result = []
for i in range(0, len(x)):
    res_1 = do_something_1(x[i], y[i])
    res_2 = do_something_2(y[i], z[i])
    res_3 = do_something_3(res_1, res_2)
    final_result.append(res_3)
final_result
sum(final_result)<jupyter_output><empty_output><jupyter_text>Using dask.delayed<jupyter_code>from dask import delayed, compute

def do_something_1(x, y):
    return x + y + 2*x*y

def do_something_2(a, b):
    return a**3 - b**3

def do_something_3(p, q):
    return p*p + q*q
final_result = []
for i in range(0, len(x)):
    # Wrap the function calls inside delayed
    res_1 = delayed(do_something_1)(x[i], y[i])
    res_2 = delayed(do_something_2)(y[i], z[i])
    res_3 = delayed(do_something_3)(res_1, res_2)
    final_result.append(res_3)

final_sum = delayed(sum)(final_result)<jupyter_output><empty_output><jupyter_text>Lazily evaluated<jupyter_code>final_sum<jupyter_output><empty_output><jupyter_text>Call `compute` to execute<jupyter_code>final_sum.compute()
final_sum.visualize()<jupyter_output><empty_output><jupyter_text>Using @delayed decorator<jupyter_code>@delayed
def do_something_1(x, y):
    return x + y + 2*x*y

@delayed
def do_something_2(a, b):
    return a**3 - b**3

@delayed
def do_something_3(p, q):
    return p*p + q*q
final_result = []
for i in range(0, len(x)):
    res_1 = do_something_1(x[i], y[i])
    res_2 = do_something_2(y[i], z[i])
    res_3 = do_something_3(res_1, res_2)
    final_result.append(res_3)

final_sum = delayed(sum)(final_result)
final_sum.compute()
final_sum.visualize()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1468189233278956, 'fraction_numerical': 0.03860793909733551, 'mean_word_length': 5.258503401360544, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '350859', 'license': 'MIT', 'n_tokens_mistral': 821, 'n_tokens_neox': 794, 'n_words': 152, 'path': 'Section 3/Using @delayed decorator.ipynb', 'repo_name': 'akashmavle5/-Scalable-Data-Analysis-in-Python-with-Dask', 'size': '1839'}