[IPython-User] Parallel: problem with user-defined class in apply()

Jacob Vanderplas jakevdp@cs.washington....
Thu Mar 21 13:13:00 CDT 2013


Hi,
I'm having an issue trying to execute a function in parallel which
references a class object.  Here's a minimal snippet:

#------------------------------------------------
from IPython.parallel import Client
client = Client()
lbv = client.load_balanced_view()

# the real model object is much more involved...
class MyModel(object):
    def maximize(self, r):
        return max(r, 4)

def evaluate(r, model):
    return model.maximize(r)

model = MyModel()
print lbv.apply(evaluate, 2, model).get()
#-----------------------------------------------

when I run this, I get the following error:

IPython.parallel.error.RemoteError: AttributeError('DummyMod' object has no
attribute 'MyModel')

I've found that I can get around this by moving the definition of MyModel
to a separate .py file, and importing it from there rather than defining it
in-place.  Is this generally the case in IPython parallel that objects
defined within the script cannot be used in parallel execution?  Is there a
way to get around this without using separate files?

Thanks,
   Jake
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/ipython-user/attachments/20130321/96c067d3/attachment.html 


More information about the IPython-User mailing list