[IPython-User] Using parallel tools in notebook

Michael Waskom mwaskom@stanford....
Wed Jan 25 13:55:46 CST 2012


Hi,

I have very little experience using the parallel tools in IPython
directly, but I tried basically the simplest example the other day and
was quite pleased.  Now I would like to use it in the context of the
notebook, and it seems the simple approach does not work as expected.

Here's a trivial notebook session demonstrating my problem::

from IPython.parallel import Client, error
def inner_func(a):
    return a
def to_be_mapped(b):
    return inner_func(b)
rc = Client()

If I try to do::

print rc[:].map_sync(inner_func, range(5))

It prints:

[0, 1, 2, 3, 4]

as expected.

If I try, however:

print rc[:].map_sync(to_be_mapped, range(5))

It immediately raises an exception:

CompositeError: one or more exceptions from call to method: to_be_mapped
[0:apply]: NameError: global name 'inner_func' is not defined
[1:apply]: NameError: global name 'inner_func' is not defined
[2:apply]: NameError: global name 'inner_func' is not defined
[3:apply]: NameError: global name 'inner_func' is not defined
[4:apply]: NameError: global name 'inner_func' is not defined

Obviously there's some namespace issue here, but there doesn't seem to
be any specific information in the docs about using the notebook and
parallel tools together, so I'm wondering if there is a simple answer
that doesn't require me to fully digest all of the parallel mechanics.

Thanks!

Michael


More information about the IPython-User mailing list