Exemple #1
0
 def Schedule(self, task, context=None) -> ray_client_pb2.ClientTaskTicket:
     logger.debug(
         "schedule: %s %s" %
         (task.name, ray_client_pb2.ClientTask.RemoteExecType.Name(
             task.type)))
     with stash_api_for_tests(self._test_mode):
         try:
             if task.type == ray_client_pb2.ClientTask.FUNCTION:
                 result = self._schedule_function(task, context)
             elif task.type == ray_client_pb2.ClientTask.ACTOR:
                 result = self._schedule_actor(task, context)
             elif task.type == ray_client_pb2.ClientTask.METHOD:
                 result = self._schedule_method(task, context)
             elif task.type == ray_client_pb2.ClientTask.NAMED_ACTOR:
                 result = self._schedule_named_actor(task, context)
             else:
                 raise NotImplementedError(
                     "Unimplemented Schedule task type: %s" %
                     ray_client_pb2.ClientTask.RemoteExecType.Name(
                         task.type))
             result.valid = True
             return result
         except Exception as e:
             logger.error(f"Caught schedule exception {e}")
             raise e
             return ray_client_pb2.ClientTaskTicket(
                 valid=False, error=cloudpickle.dumps(e))
Exemple #2
0
 def _schedule_method(self,
                      task: ray_client_pb2.ClientTask,
                      context=None) -> ray_client_pb2.ClientTaskTicket:
     actor_handle = self.actor_refs.get(task.payload_id)
     if actor_handle is None:
         raise Exception(
             "Can't run an actor the server doesn't have a handle for")
     arglist = _convert_args(task.args)
     with stash_api_for_tests(self._test_mode):
         output = getattr(actor_handle, task.name).remote(*arglist)
         self.object_refs[output.binary()] = output
     return ray_client_pb2.ClientTaskTicket(return_id=output.binary())
Exemple #3
0
 def _schedule_function(self,
                        task: ray_client_pb2.ClientTask,
                        context=None) -> ray_client_pb2.ClientTaskTicket:
     if task.payload_id not in self.function_refs:
         funcref = self.object_refs[task.payload_id]
         func = ray.get(funcref)
         if not isinstance(func, ClientRemoteFunc):
             raise Exception("Attempting to schedule function that "
                             "isn't a ClientRemoteFunc.")
         self.function_refs[task.payload_id] = func
     remote_func = self.function_refs[task.payload_id]
     arglist = _convert_args(task.args)
     # Prepare call if we're in a test
     with stash_api_for_tests(self._test_mode):
         output = remote_func.remote(*arglist)
         self.object_refs[output.binary()] = output
     return ray_client_pb2.ClientTaskTicket(return_id=output.binary())
Exemple #4
0
 def _schedule_actor(self,
                     task: ray_client_pb2.ClientTask,
                     context=None) -> ray_client_pb2.ClientTaskTicket:
     with stash_api_for_tests(self._test_mode):
         if task.payload_id not in self.registered_actor_classes:
             actor_class_ref = self.object_refs[task.payload_id]
             actor_class = ray.get(actor_class_ref)
             if not inspect.isclass(actor_class):
                 raise Exception("Attempting to schedule actor that "
                                 "isn't a ClientActorClass.")
             reg_class = ray.remote(actor_class)
             self.registered_actor_classes[task.payload_id] = reg_class
         remote_class = self.registered_actor_classes[task.payload_id]
         arglist = _convert_args(task.args)
         actor = remote_class.remote(*arglist)
         actor_ref = actor._actor_id
         self.actor_refs[actor_ref.binary()] = actor
     return ray_client_pb2.ClientTaskTicket(return_id=actor_ref.binary())
Exemple #5
0
 def Schedule(self,
              task,
              context=None,
              prepared_args=None) -> ray_client_pb2.ClientTaskTicket:
     logger.info("schedule: %s %s" %
                 (task.name,
                  ray_client_pb2.ClientTask.RemoteExecType.Name(task.type)))
     with stash_api_for_tests(self._test_mode):
         if task.type == ray_client_pb2.ClientTask.FUNCTION:
             return self._schedule_function(task, context, prepared_args)
         elif task.type == ray_client_pb2.ClientTask.ACTOR:
             return self._schedule_actor(task, context, prepared_args)
         elif task.type == ray_client_pb2.ClientTask.METHOD:
             return self._schedule_method(task, context, prepared_args)
         else:
             raise NotImplementedError(
                 "Unimplemented Schedule task type: %s" %
                 ray_client_pb2.ClientTask.RemoteExecType.Name(task.type))
Exemple #6
0
 def _schedule_actor(self,
                     task: ray_client_pb2.ClientTask,
                     context=None,
                     prepared_args=None) -> ray_client_pb2.ClientTaskTicket:
     with stash_api_for_tests(self._test_mode):
         payload_ref = cloudpickle.loads(task.payload_id)
         if payload_ref.binary() not in self.registered_actor_classes:
             actor_class_ref = self.object_refs[payload_ref.binary()]
             actor_class = ray.get(actor_class_ref)
             if not inspect.isclass(actor_class):
                 raise Exception("Attempting to schedule actor that "
                                 "isn't a class.")
             reg_class = ray.remote(actor_class)
             self.registered_actor_classes[payload_ref.binary()] = reg_class
         remote_class = self.registered_actor_classes[payload_ref.binary()]
         arglist = _convert_args(task.args, prepared_args)
         actor = remote_class.remote(*arglist)
         actorhandle = cloudpickle.dumps(actor)
         self.actor_refs[actorhandle] = actor
     return ray_client_pb2.ClientTaskTicket(
         return_ref=make_remote_ref(actor._actor_id.binary(), actorhandle))
Exemple #7
0
 def _schedule_function(
         self,
         task: ray_client_pb2.ClientTask,
         context=None,
         prepared_args=None) -> ray_client_pb2.ClientTaskTicket:
     payload_ref = cloudpickle.loads(task.payload_id)
     if payload_ref.binary() not in self.function_refs:
         funcref = self.object_refs[payload_ref.binary()]
         func = ray.get(funcref)
         if not inspect.isfunction(func):
             raise Exception("Attempting to schedule function that "
                             "isn't a function.")
         self.function_refs[payload_ref.binary()] = ray.remote(func)
     remote_func = self.function_refs[payload_ref.binary()]
     arglist = _convert_args(task.args, prepared_args)
     # Prepare call if we're in a test
     with stash_api_for_tests(self._test_mode):
         output = remote_func.remote(*arglist)
         if output.binary() in self.object_refs:
             raise Exception("already found it")
         self.object_refs[output.binary()] = output
         pickled_output = cloudpickle.dumps(output)
     return ray_client_pb2.ClientTaskTicket(
         return_ref=make_remote_ref(output.binary(), pickled_output))