This tutorial is also available in the form of a Jupyter Notebook. Try it out, and play!
Noodles is there to make your life easier, in parallel! The reason why Noodles can be easy and do parallel Python at the same time is its functional approach. In one part you’ll define a set of functions that you’d like to run with Noodles, in an other part you’ll compose these functions into a workflow graph. To make this approach work a function should not have any side effects. Let’s not linger and just start noodling! First we define some functions to use.
from noodles import schedule @schedule def add(x, y): return x + y @schedule def mul(x,y): return x * y
Now we can create a workflow composing several calls to this function.
a = add(1, 1) b = mul(a, 2) c = add(a, a) d = mul(b, c)
That looks easy enough; the funny thing is though, that nothing has been computed yet! Noodles just created the workflow graphs corresponding to the values that still need to be computed. Until such time, we work with the promise of a future value. Using some function in
pygraphviz we can look at the call graphs.
from noodles.tutorial import display_workflows display_workflows(prefix='first_steps-workflow', a=a, b=b, c=c, d=d)
Now, to compute the result we have to tell Noodles to evaluate the program.
from noodles import run_parallel run_parallel(d, n_threads=2)