[IPython-user] Enhancements to ipython1: pushing/pulling functions
Thu Oct 4 16:21:20 CDT 2007
I have just checked in some changes to ipython1 that make it possible
to push and pull functions to and from engines:
In : import ipython1.kernel.api as kernel
In : rc = kernel.RemoteController(('127.0.0.1',10105))
In : def f(x): return 2.0*x
In : rc.pushAll(f=f) # push the actual function!
Out: [None, None, None, None]
In : rc.executeAll('y=f(10)') # now call the function
In : rc.pullAll('y')
Out: [20.0, 20.0, 20.0, 20.0]
We have also adapted the rc.map/mapAll and parallelize methods to take
functions as well:
In : rc.mapAll(lambda x: x*x, range(16))
Out: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225]
Please try these new features out and let us know how they work.
1. Only functions and lambdas can be pushed and pulled. Instances
of classes that are callables don't work unless the class is already
defined on the engines.
2. Functions with closures don't work.
3. Functions that reference global variables work fine though.
Over the coming weeks, we will begin to incorporate these new features
into other parts of ipython1, such as the TaskController.
More information about the IPython-user