Note that there are some explanatory texts on larger screens.

plurals
  1. POParallel mapping functions in IPython w/ multiple parameters
    primarykey
    data
    text
    <p>I'm trying to use IPython's parallel environment and so far, it's looking great but I'm running into a problem. Lets say that I have a function, defined in a library</p> <pre><code>def func(a,b): ... </code></pre> <p>that I use when I want to evaluate on one value of a and a bunch of values of b. </p> <pre><code>[func(myA, b) for b in myLongList] </code></pre> <p>Obviously, the real function is more complicated but the essence of the matter is that it takes multiple parameters and I'd like to map over only one of them. The problem is that map, @dview.parallel, etc. map over all the arguments. </p> <p>So lets say I want to get the answer to func(myA, myLongList). The obvious way to do this is to curry, either w/ functools.partial or just as </p> <pre><code>dview.map_sync(lambda b: func(myA, b), myLongList) </code></pre> <p>However, this does not work correctly on remote machines. The reason is that when the lambda expression is pickled, the value of myA is not included and instead, the value of myA from the local scope on the remote machine is used. When closures get pickled, the variables they close over don't. </p> <p>Two ways I can think of doing this that will actually work are to manually construct lists for every argument and have map work over all of the arguments,</p> <pre><code>dview.map_sync(func, [myA]*len(myLongList), myLongList) </code></pre> <p>or to horrifically use the data as default arguments to a function, forcing it to get pickled:</p> <pre><code># Can't use a lambda here b/c lambdas don't use default arguments :( def parallelFunc(b, myA = myA): return func(myA, b) dview.map_sync(parallelFunc, myLongList) </code></pre> <p>Really, this all seems horribly contorted when the real function takes a lot of parameters and is more complicated. Is there some idiomatic way of doing this? Something like</p> <pre><code>@parallel(mapOver='b') def bigLongFn(a, b): ... </code></pre> <p>but as far as I know, nothing like the 'mapOver' thing exists. I probably have an idea of how to implement it ... this just feels like a very basic operation that there should exist support for so I want to check if I'm missing something. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload