RayActor
The class is specific implementation of Actor
class using Ray.
The RayActor
implements 2 internal methods:
__getattr__()
– transmits an access responsibility to the methods of native Ray actor, held by this class, toRayActorMethod
class._remote()
– creates native Ray actor object to be held by this class.
API
- class unidist.core.backends.ray.actor.RayActor(cls, num_cpus, resources, actor_handle=None)
The class implements the interface in
Actor
using Ray backend.- Parameters:
cls (object) – Class to be an actor class.
num_cpus (int) – The number of CPUs to reserve for the lifetime of the actor.
resources (dict) – Custom resources to reserve for the lifetime of the actor.
actor_handle (None or ray.actor.ActorHandle) – Used for proper serialization/deserialization via __reduce__.
- classmethod _deserialization_helper(state)
Helper to restore the state of the object.
This is defined to make pickling work via __reduce__.
- Parameters:
state (dict) – The serialized state of the object.
- Return type:
- _remote(*args, num_cpus=None, resources=None, **kwargs)
Create actor class, specific for Ray backend, from self._cls.
- Parameters:
*args (iterable) – Positional arguments to be passed in self._cls class constructor.
num_cpus (int, optional) – The number of CPUs to reserve for the lifetime of the actor.
resources (dict, optional) – Custom resources to reserve for the lifetime of the actor.
**kwargs (dict) – Keyword arguments to be passed in self._cls class constructor.
- Return type:
- _serialization_helper()
Helper to save the state of the object.
This is defined to make pickling work via __reduce__.
- Returns:
A dictionary of the information needed to reconstruct the object.
- Return type:
dict
RayActorMethod
The class is specific implementation of ActorMethod
class using Ray.
The RayActorMethod
implements internal method
_remote()
that is responsible for
calls of native Ray actor class methods.
API
- class unidist.core.backends.ray.actor.RayActorMethod(cls, method_name)
The class implements the interface in
ActorMethod
using Ray backend.- Parameters:
cls (ray.actor.ActorHandle) – An actor class from which method method_name will be called.
method_name (str) – The name of the method to be called.
- _remote(*args, num_returns=None, **kwargs)
Execute self._method_name in a worker process.
- Parameters:
*args (iterable) – Positional arguments to be passed in the method.
num_returns (int, optional) – Number of results to be returned. If it isn’t provided, self._num_returns will be used.
**kwargs (dict) – Keyword arguments to be passed in the method.
- Returns:
Type of returns depends on num_returns value:
if num_returns == 1,
ObjectRef
will be returned.if num_returns > 1, list of
ObjectRef
will be returned.if num_returns == 0,
None
will be returned.
- Return type:
ObjectRef, list or None