ray.util.ActorPool.map#

ActorPool.map(fn: Callable[[ActorHandle, V], Any], values: List[V])[source]#

Apply the given function in parallel over the actors and values.

This returns an ordered iterator that will return results of the map as they finish. Note that you must iterate over the iterator to force the computation to finish.

Parameters:
  • fn – Function that takes (actor, value) as argument and returns an ObjectRef computing the result over the value. The actor will be considered busy until the ObjectRef completes.

  • values – List of values that fn(actor, value) should be applied to.

Returns:

Iterator over results from applying fn to the actors and values.

Examples

import ray
from ray.util.actor_pool import ActorPool

@ray.remote
class Actor:
    def double(self, v):
        return 2 * v

a1, a2 = Actor.remote(), Actor.remote()
pool = ActorPool([a1, a2])
print(list(pool.map(lambda a, v: a.double.remote(v),
                    [1, 2, 3, 4])))
[2, 4, 6, 8]