Esempio n. 1
0
    def get_full_actor_cls(
        self, trial: "Trial", actor_cls: ActorClass
    ) -> Optional[ActorClass]:
        """Get a fully configured actor class.

        Returns the actor handle if the placement group is ready. In this case,
        the placement group is moved to `self._in_use_pgs` and removed from
        `self._ready`.

        Args:
            trial: "Trial" object to start
            actor_cls: Ray actor class.

        Returns:
            Configured ActorClass or None

        """
        pgf = trial.placement_group_factory

        if not self._ready[pgf]:
            return None

        pg = self._ready[pgf].pop()
        self._in_use_pgs[pg] = trial
        self._in_use_trials[trial] = pg

        logger.debug(f"For trial {trial} use pg {pg.id}")

        # We still have to pass resource specs
        if not pgf.head_bundle_is_empty:
            # Pass the full resource specs of the first bundle per default
            head_bundle = pg.bundle_specs[0].copy()
            num_cpus = head_bundle.pop("CPU", 0)
            num_gpus = head_bundle.pop("GPU", 0)
            memory = head_bundle.pop("memory", None)
            object_store_memory = head_bundle.pop("object_store_memory", None)

            # Only custom resources remain in `head_bundle`
            resources = head_bundle
            return actor_cls.options(
                placement_group=pg,
                placement_group_bundle_index=0,
                placement_group_capture_child_tasks=True,
                num_cpus=num_cpus,
                num_gpus=num_gpus,
                memory=memory,
                object_store_memory=object_store_memory,
                resources=resources,
            )
        else:
            return actor_cls.options(
                placement_group=pg,
                placement_group_capture_child_tasks=True,
                num_cpus=0,
                num_gpus=0,
                resources={},
            )
Esempio n. 2
0
def java_actor_class(class_name):
    from ray.actor import ActorClass
    return ActorClass._ray_from_function_descriptor(
        Language.JAVA,
        JavaFunctionDescriptor(class_name, "<init>", ""),
        0,  # max_reconstructions,
        None,  # num_cpus,
        None,  # num_gpus,
        None,  # memory,
        None,  # object_store_memory,
        None)  # resources,
Esempio n. 3
0
def java_actor_class(class_name: str):
    """Define a Java actor class.

    Args:
        class_name: Java class name.
    """
    from ray.actor import ActorClass

    return ActorClass._ray_from_function_descriptor(
        Language.JAVA,
        JavaFunctionDescriptor(class_name, "<init>", ""),
        {},
    )
Esempio n. 4
0
def java_actor_class(class_name):
    from ray.actor import ActorClass
    return ActorClass._ray_from_function_descriptor(
        Language.JAVA,
        JavaFunctionDescriptor(class_name, "<init>", ""),
        max_restarts=0,
        max_task_retries=0,
        num_cpus=None,
        num_gpus=None,
        memory=None,
        object_store_memory=None,
        resources=None,
        accelerator_type=None,
    )
Esempio n. 5
0
def cpp_actor_class(create_function_name: str, class_name: str):
    """Define a Cpp actor class.

    Args:
        create_function_name: Create cpp class function name.
        class_name: Cpp class name.
    """
    from ray.actor import ActorClass

    print("create func=", create_function_name, "class_name=", class_name)
    return ActorClass._ray_from_function_descriptor(
        Language.CPP,
        CppFunctionDescriptor(create_function_name, "PYTHON", class_name),
        {},
    )
Esempio n. 6
0
    def get_full_actor_cls(self, trial: "Trial",
                           actor_cls: ActorClass) -> Optional[ActorClass]:
        """Get a fully configured actor class.

        Returns the actor handle if the placement group is ready. In this case,
        the placement group is moved to `self._in_use_pgs` and removed from
        `self._ready`.

        Args:
            trial ("Trial"): "Trial" object to start
            actor_cls: Ray actor class.

        Returns:
            Configured ActorClass or None

        """
        pgf = trial.placement_group_factory

        if not self._ready[pgf]:
            return None

        pg = self._ready[pgf].pop()
        self._in_use_pgs[pg] = trial
        self._in_use_trials[trial] = pg

        # We still have to pass resource specs
        # Pass the full resource specs of the first bundle per default
        first_bundle = pg.bundle_specs[0].copy()
        num_cpus = first_bundle.pop("CPU", None)
        num_gpus = first_bundle.pop("GPU", None)

        # Only custom resources remain in `first_bundle`
        resources = first_bundle or None

        if num_cpus is None:
            # If the placement group specifically set the number
            # of CPUs to 0, use this.
            num_cpus = pgf.head_cpus

        logger.debug(f"For trial {trial} use pg {pg.id}")

        return actor_cls.options(
            placement_group=pg,
            placement_group_bundle_index=0,
            placement_group_capture_child_tasks=True,
            num_cpus=num_cpus,
            num_gpus=num_gpus,
            resources=resources)
Esempio n. 7
0
def java_actor_class(class_name):
    """Define a Java actor class.

    Args:
        class_name (str): Java class name.
    """
    from ray.actor import ActorClass
    return ActorClass._ray_from_function_descriptor(
        Language.JAVA,
        JavaFunctionDescriptor(class_name, "<init>", ""),
        max_restarts=0,
        max_task_retries=0,
        num_cpus=None,
        num_gpus=None,
        memory=None,
        object_store_memory=None,
        resources=None,
        accelerator_type=None,
        runtime_env=None)
Esempio n. 8
0
    def get_full_actor_cls(self, trial: Trial,
                           actor_cls: ActorClass) -> Optional[ActorClass]:
        """Get a fully configured actor class.

        Returns the actor handle if the placement group is ready. In this case,
        the placement group is moved to `self._in_use_pgs` and removed from
        `self._ready`.

        Args:
            trial (Trial): Trial object to start
            actor_cls: Ray actor class.

        Returns:
            Configured ActorClass or None

        """
        pgf = trial.placement_group_factory

        if not self._ready[pgf]:
            return None

        pg = self._ready[pgf].pop()
        self._in_use_pgs[pg] = trial
        self._in_use_trials[trial] = pg

        # We still have to pass resource specs
        # Pass the full resource specs of the first bundle per default
        first_bundle = pg.bundle_specs[0].copy()
        num_cpus = first_bundle.pop("CPU", None)
        num_gpus = first_bundle.get("GPU", None)

        # Only custom resources remain in `first_bundle`
        resources = first_bundle or None

        return actor_cls.options(placement_group=pg,
                                 placement_group_bundle_index=0,
                                 num_cpus=num_cpus,
                                 num_gpus=num_gpus,
                                 resources=resources)
Esempio n. 9
0
def cpp_actor_class(create_function_name, class_name):
    """Define a Cpp actor class.

    Args:
        create_function_name (str): Create cpp class function name.
        class_name (str): Cpp class name.
    """
    from ray.actor import ActorClass

    print("create func=", create_function_name, "class_name=", class_name)
    return ActorClass._ray_from_function_descriptor(
        Language.CPP,
        CppFunctionDescriptor(create_function_name, "PYTHON", class_name),
        max_restarts=0,
        max_task_retries=0,
        num_cpus=None,
        num_gpus=None,
        memory=None,
        object_store_memory=None,
        resources=None,
        accelerator_type=None,
        runtime_env=None,
    )