Exemplo n.º 1
0
Arquivo: common.py Projeto: hngenc/ray
    def run_async(self, workflow_id: Optional[str] = None) -> ObjectRef:
        """Run a workflow asynchronously.

        Examples:
            >>> @workflow.step
            ... def book_flight(origin: str, dest: str) -> Flight:
            ...    return Flight(...)

            >>> @workflow.step
            ... def book_hotel(location: str) -> Reservation:
            ...    return Reservation(...)

            >>> @workflow.step
            ... def finalize_trip(bookings: List[Any]) -> Trip:
            ...    return Trip(...)

            >>> flight1 = book_flight.step("OAK", "SAN")
            >>> flight2 = book_flight.step("SAN", "OAK")
            >>> hotel = book_hotel.step("SAN")
            >>> trip = finalize_trip.step([flight1, flight2, hotel])
            >>> result = ray.get(trip.run_async())

        Args:
            workflow_id: A unique identifier that can be used to resume the
                workflow. If not specified, a random id will be generated.
        """
        # TODO(suquark): avoid cyclic importing
        from ray.experimental.workflow.execution import run
        return run(self, workflow_id)
Exemplo n.º 2
0
def run(entry_workflow: "Workflow",
        storage: "Optional[Union[str, Storage]]" = None,
        workflow_id: Optional[str] = None) -> ray.ObjectRef:
    """
    Run a workflow asynchronously.

    Args:
        entry_workflow: The workflow to run.
        storage: The storage or the URL of an external storage used for
            checkpointing.
        workflow_id: The ID of the workflow. The ID is used to identify
            the workflow.

    Returns:
        The execution result of the workflow, represented by Ray ObjectRef.
    """
    assert ray.is_initialized()
    return execution.run(entry_workflow, storage, workflow_id)
Exemplo n.º 3
0
Arquivo: api.py Projeto: ckw017/ray
def run(entry_workflow: "Workflow",
        storage: "Optional[Union[str, Storage]]" = None,
        workflow_id: Optional[str] = None) -> ray.ObjectRef:
    """Run a workflow asynchronously.

    Examples:
        >>> @workflow.step
        ... def book_flight(origin: str, dest: str) -> Flight:
        ...    return Flight(...)

        >>> @workflow.step
        ... def book_hotel(location: str) -> Reservation:
        ...    return Reservation(...)

        >>> @workflow.step
        ... def finalize_trip(bookings: List[Any]) -> Trip:
        ...    return Trip(...)

        >>> flight1 = book_flight.step("OAK", "SAN")
        >>> flight2 = book_flight.step("SAN", "OAK")
        >>> hotel = book_hotel.step("SAN")
        >>> trip = finalize_trip.step([flight1, flight2, hotel])
        >>> ray.get(workflow.run(trip))

    Args:
        entry_workflow: The output step of the workflow to run. The return
            type of the workflow will be ObjectRef[T] if the output step is
            a workflow step returning type T.
        storage: The external storage URL or a custom storage class. If not
            specified, ``/tmp/ray/workflow_data`` will be used.
        workflow_id: A unique identifier that can be used to resume the
            workflow. If not specified, a random id will be generated.

    Returns:
        An object reference that can be used to retrieve the workflow result.
    """
    assert ray.is_initialized()
    if _is_anonymous_namespace():
        raise ValueError("Must use a namespace in 'ray.init()' to access "
                         "workflows properly. Current namespace seems to "
                         "be anonymous.")
    return execution.run(entry_workflow, storage, workflow_id)