Skip to content
This repository

Views created with c.direct_view() fail #986

Closed
takluyver opened this Issue November 09, 2011 · 3 comments

2 participants

Thomas Kluyver Min RK
Thomas Kluyver
Collaborator

Going through a basic example from the docs, I ran into this failure. It looks like view.targets is 'all', when it should be a collection of IDs. Creating the equivalent view with c[:] works.

In [3]: v = c.direct_view()

In [4]: v
Out[4]: <DirectView all>

In [5]: v.map_sync(lambda x: x**10, range(32))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/home/thomas/Code/virtualenvs/ipy-trunk/<ipython-input-5-b937e0334e06> in <module>()
----> 1 v.map_sync(lambda x: x**10, range(32))

/home/thomas/Code/virtualenvs/ipy-trunk/local/lib/python2.7/site-packages/IPython/parallel/client/view.pyc in map_sync(self, f, *sequences, **kwargs)
    340             raise TypeError("map_sync doesn't take a `block` keyword argument.")
    341         kwargs['block'] = True
--> 342         return self.map(f,*sequences,**kwargs)
    343 
    344     def imap(self, f, *sequences, **kwargs):

/home/thomas/Code/virtualenvs/ipy-trunk/<string> in map(self, f, *sequences, **kwargs)

/home/thomas/Code/virtualenvs/ipy-trunk/local/lib/python2.7/site-packages/IPython/parallel/client/view.pyc in spin_after(f, self, *args, **kwargs)
     66 def spin_after(f, self, *args, **kwargs):
     67     """call spin after the method."""
---> 68     ret = f(self, *args, **kwargs)
     69     self.spin()
     70     return ret

/home/thomas/Code/virtualenvs/ipy-trunk/local/lib/python2.7/site-packages/IPython/parallel/client/view.pyc in map(self, f, *sequences, **kwargs)
    575         assert len(sequences) > 0, "must have some sequences to map onto!"
    576         pf = ParallelFunction(self, f, block=block, **kwargs)
--> 577         return pf.map(*sequences)
    578 
    579     def execute(self, code, targets=None, block=None):

/home/thomas/Code/virtualenvs/ipy-trunk/local/lib/python2.7/site-packages/IPython/parallel/client/remotefunction.pyc in map(self, *sequences)
    212         self._map = True
    213         try:
--> 214             ret = self.__call__(*sequences)
    215         finally:
    216             del self._map

/home/thomas/Code/virtualenvs/ipy-trunk/local/lib/python2.7/site-packages/IPython/parallel/client/remotefunction.pyc in __call__(self, *sequences)
    185                 f=self.func
    186 
--> 187             view = self.view if balanced else client[t]
    188             with view.temp_flags(block=False, **self.flags):
    189                 ar = view.apply(f, *args)

/home/thomas/Code/virtualenvs/ipy-trunk/local/lib/python2.7/site-packages/IPython/parallel/client/client.pyc in __getitem__(self, key)
    763         Must be int, slice, or list/tuple/xrange of ints"""
    764         if not isinstance(key, (int, slice, tuple, list, xrange)):
--> 765             raise TypeError("key by int/slice/iterable of ints only, not %s"%(type(key)))
    766         else:
    767             return self.direct_view(key)

TypeError: key by int/slice/iterable of ints only, not <type 'str'>
Min RK
Owner

'all' is actually correct, because it is meant to be lazily evaluated (rc.direct_view('all') != rc[:]), but the remotefunction code doesn't handle that properly. Fix is easy and forthcoming.

Thanks!

Min RK
Owner

Where is the example that doesn't work? I can't find one that would do this.

Thomas Kluyver
Collaborator

Sorry, I should have been clearer - the example itself uses c[:], but I had deviated slightly from it. I was going from this: http://ipython.org/ipython-doc/stable/parallel/parallel_multiengine.html#parallel-map

Min RK minrk closed this issue from a commit November 09, 2011
Min RK handle targets='all' in remotefunction
* add explanation of lazy evaluation of 'all' to direct_view docstring
* previously failing test included

closes gh-986
55d81f8
Min RK minrk closed this in 55d81f8 November 09, 2011
Brian E. Granger ellisonbg referenced this issue from a commit January 10, 2012
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.