2021-08-27 16:20:48 -07:00
API Comparisons
===============
Comparison between Ray Core APIs and Workflows
----------------------------------------------
Workflows is built on top of Ray, and offers a mostly consistent subset of its API while providing durability. This section highlights some of the differences:
2021-11-05 17:05:35 -07:00
`` func.remote `` vs `` func.step ``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-08-27 16:20:48 -07:00
With Ray tasks, `` func.remote `` will submit a remote task to run. In Ray workflows, `` func.step `` is used to create a `` Workflow `` object. Execution of the workflow is deferred until `` .run(workflow_id="id") `` or `` .run_async(workflow_id="id") `` is called on the `` Workflow `` . Specifying the workflow id allows for resuming of the workflow by its id in case of cluster failure.
2021-11-05 17:05:35 -07:00
`` Actor.remote `` vs `` Actor.get_or_create ``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-08-27 16:20:48 -07:00
With Ray actors, `` Actor.remote `` will submit an actor creation task and create an actor process in the cluster. In Ray workflows, virtual actors are created by `` Actor.get_or_create `` . The actor state is tracked as a dynamic workflow (durably logged) instead of in a running process. This means that the actor uses no resources when inactive, and can be used even after cluster restarts.
2021-11-05 17:05:35 -07:00
`` actor.func.remote `` vs `` actor.func.run ``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2021-08-27 16:20:48 -07:00
With Ray actors, `` actor.func.remote `` will submit a remote task to run which is similar as `` func.remote `` . On the other hand `` actor.func.run `` on a virtual actor will read the actor state from storage, execute a step, and then write the new state back to storage. If the `` actor.func `` is decorated with `` workflow.virtual_actor.readonly `` , its result will not be logged.
Other Workflow Engines
----------------------
Note: these comparisons are inspired by the `Serverless workflows comparisons repo <https://github.com/serverlessworkflow/specification/tree/main/comparisons> `__ .
Argo API Comparison
~~~~~~~~~~~~~~~~~~~
The original source of these comparisons can be `found here <https://github.com/serverlessworkflow/specification/blob/main/comparisons/comparison-argo.md> `__ .
Conditionals
^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/conditionals_argo.yaml
2021-08-27 16:20:48 -07:00
:caption: Argo version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/conditionals_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
DAG
^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/dag_argo.yaml
2021-08-27 16:20:48 -07:00
:caption: Argo version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/dag_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Multi-step Workflow
^^^^^^^^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/multi_step_argo.yaml
2021-08-27 16:20:48 -07:00
:caption: Argo version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/multi_step_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Exit Handler
^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/exit_handler_argo.yaml
2021-08-27 16:20:48 -07:00
:caption: Argo version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/exit_handler_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Loops
^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/loops_argo.yaml
2021-08-27 16:20:48 -07:00
:caption: Argo version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/loops_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Recursion
^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/recursion_argo.yaml
2021-08-27 16:20:48 -07:00
:caption: Argo version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/recursion_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Retries
^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/retry_argo.yaml
2021-08-27 16:20:48 -07:00
:caption: Argo version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/argo/retry_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Metaflow API Comparison
~~~~~~~~~~~~~~~~~~~~~~~
The original source of these comparisons can be `found here <https://docs.metaflow.org/metaflow/basics#foreach> `__ .
Foreach
^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/metaflow/foreach_metaflow.py.txt
2021-08-27 16:20:48 -07:00
:caption: Metaflow version:
:language: python
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/metaflow/foreach_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Cadence API Comparison
~~~~~~~~~~~~~~~~~~~~~~
The original source of these comparisons can be `found here <https://github.com/serverlessworkflow/specification/blob/main/comparisons/comparison-cadence.md> `__ .
Sub Workflows
^^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/cadence/sub_workflow_cadence.java
2021-08-27 16:20:48 -07:00
:caption: Cadence version:
:language: java
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/cadence/sub_workflow_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
File Processing
^^^^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/cadence/file_processing_cadence.java
2021-08-27 16:20:48 -07:00
:caption: Cadence version:
:language: java
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/cadence/file_processing_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Trip Booking
^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/cadence/trip_booking_cadence.java
2021-08-27 16:20:48 -07:00
:caption: Cadence version:
:language: java
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/cadence/trip_booking_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Google Cloud Workflows API Comparison
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The original source of these comparisons can be `found here <https://github.com/serverlessworkflow/specification/blob/main/comparisons/comparison-google-cloud-workflows.md> `__ .
Data Conditional
^^^^^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/google_cloud_workflows/data_cond_google.yaml
2021-08-27 16:20:48 -07:00
:caption: Google Cloud version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/google_cloud_workflows/data_cond_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Concat Array
^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/google_cloud_workflows/concat_array_google.yaml
2021-08-27 16:20:48 -07:00
:caption: Google Cloud version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/google_cloud_workflows/concat_array_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
Sub Workflows
^^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/google_cloud_workflows/sub_workflows_google.yaml
2021-08-27 16:20:48 -07:00
:caption: Google Cloud version:
:language: yaml
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/google_cloud_workflows/sub_workflows_workflow.py
2021-08-27 16:20:48 -07:00
:caption: Workflow version:
:language: python
2021-09-03 19:26:33 -07:00
Prefect API Comparison
~~~~~~~~~~~~~~~~~~~~~~
The original source of these comparisons can be `found here <https://docs.prefect.io/core/advanced_tutorials/task-looping.html> `__ .
Looping
^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/prefect/compute_fib_prefect.py.txt
2021-09-03 19:26:33 -07:00
:caption: Prefect version:
:language: python
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/prefect/compute_fib_workflow.py
2021-09-03 19:26:33 -07:00
:caption: Workflow version:
:language: python
AirFlow API Comparison
~~~~~~~~~~~~~~~~~~~~~~
The original source of these comparisons can be `found here <https://airflow.apache.org/docs/apache-airflow/stable/tutorial_taskflow_api.html> `__ .
ETL Workflow
^^^^^^^^^^^^
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/airflow/etl_airflow.py.txt
2021-09-03 19:26:33 -07:00
:caption: AirFlow version:
:language: python
2021-09-13 17:45:18 -07:00
.. literalinclude :: ../../../python/ray/workflow/examples/comparisons/airflow/etl_workflow.py
2021-09-03 19:26:33 -07:00
:caption: Workflow version:
:language: python