def make_actor(cls, num_cpus, num_gpus, memory, object_store_memory, resources, max_restarts, max_task_retries): Class = modify_class(cls) if max_restarts is None: max_restarts = 0 if max_task_retries is None: max_task_retries = 0 infinite_restart = max_restarts == -1 if not infinite_restart: if max_restarts < 0: raise ValueError("max_restarts must be an integer >= -1 " "-1 indicates infinite restarts") else: # Make sure we don't pass too big of an int to C++, causing # an overflow. max_restarts = min(max_restarts, ray_constants.MAX_INT64_VALUE) if max_restarts == 0 and max_task_retries != 0: raise ValueError( "max_task_retries cannot be set if max_restarts is 0.") return ActorClass._ray_from_modified_class(Class, ActorClassID.from_random(), max_restarts, max_task_retries, num_cpus, num_gpus, memory, object_store_memory, resources)
def make_actor(cls, num_cpus, num_gpus, memory, object_store_memory, resources, max_reconstructions): # Give an error if cls is an old-style class. if not issubclass(cls, object): raise TypeError( "The @ray.remote decorator cannot be applied to old-style " "classes. In Python 2, you must declare the class with " "'class ClassName(object):' instead of 'class ClassName:'.") if issubclass(cls, Checkpointable) and inspect.isabstract(cls): raise TypeError( "A checkpointable actor class should implement all abstract " "methods in the `Checkpointable` interface.") if max_reconstructions is None: if ray_constants.direct_call_enabled(): # Allow the actor creation task to be resubmitted automatically # by default. max_reconstructions = 3 else: max_reconstructions = 0 if not (ray_constants.NO_RECONSTRUCTION <= max_reconstructions <= ray_constants.INFINITE_RECONSTRUCTION): raise Exception("max_reconstructions must be in range [%d, %d]." % (ray_constants.NO_RECONSTRUCTION, ray_constants.INFINITE_RECONSTRUCTION)) # Modify the class to have an additional method that will be used for # terminating the worker. class Class(cls): def __ray_terminate__(self): worker = ray.worker.get_global_worker() if worker.mode != ray.LOCAL_MODE: ray.actor.exit_actor() def __ray_checkpoint__(self): """Save a checkpoint. This task saves the current state of the actor, the current task frontier according to the raylet, and the checkpoint index (number of tasks executed so far). """ worker = ray.worker.global_worker if not isinstance(self, ray.actor.Checkpointable): raise Exception( "__ray_checkpoint__.remote() may only be called on actors " "that implement ray.actor.Checkpointable") return worker._save_actor_checkpoint() Class.__module__ = cls.__module__ Class.__name__ = cls.__name__ return ActorClass._ray_from_modified_class(Class, ActorClassID.from_random(), max_reconstructions, num_cpus, num_gpus, memory, object_store_memory, resources)
def make_actor(cls, num_cpus, num_gpus, memory, object_store_memory, resources, max_reconstructions): Class = modify_class(cls) if max_reconstructions is None: max_reconstructions = 0 if not (ray_constants.NO_RECONSTRUCTION <= max_reconstructions <= ray_constants.INFINITE_RECONSTRUCTION): raise ValueError("max_reconstructions must be in range [%d, %d]." % (ray_constants.NO_RECONSTRUCTION, ray_constants.INFINITE_RECONSTRUCTION)) return ActorClass._ray_from_modified_class( Class, ActorClassID.from_random(), max_reconstructions, num_cpus, num_gpus, memory, object_store_memory, resources)