Skip to content

Commit

Permalink
[dag] Fix the workflow doc code build (ray-project#37249)
Browse files Browse the repository at this point in the history
Previously this code was relying on an implementation detail (DAG nodes not being serializable) to illustrate the point about static DAGs. Serializability was enabled in ray-project#37198.

I've updated the code sample to show that the DAG must be constructed statically and returning nodes from other nodes will be evaluated at runtime.

Signed-off-by: Bhavpreet Singh <singh.bhavpreet00@gmail.com>
  • Loading branch information
edoakes authored and Bhav00 committed Jul 11, 2023
1 parent 63bdafd commit 120d233
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions doc/source/workflows/basics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -308,30 +308,31 @@ Idempotent workflow:
Dynamic workflows
-----------------

Workflow tasks can be dynamically created in the runtime. In theory, Ray DAG is
static which means a DAG node can't be returned in a DAG node. For example, the
following code is invalid:
Ray DAGs are static -- returning a node from another node isn't a valid way to
construct a graph. For example, the following code prints a DAG
node, not the output of `bar`:

.. testcode::

@ray.remote
def bar(): ...
def bar():
print("Hello from bar!")

@ray.remote
def foo():
return bar.bind() # This is invalid since Ray DAG is static
# This is evaluated at runtime, not in DAG construction.
return bar.bind()

try:
ray.get(foo.bind().execute()) # This will error
except ray.exceptions.RayTaskError:
print("Ray DAG is static")
# Executing `foo` returns the `bar` DAG node, *not* its result.
print("Output of foo DAG:", type(ray.get(foo.bind().execute())))

.. testoutput::

Ray DAG is static
Output of foo DAG: <class 'ray.dag.function_node.FunctionNode'>


Workflow introduces a utility function called ``workflow.continuation`` which
makes Ray DAG node can return a DAG in the runtime:
To enable dynamically executing DAG nodes at runtime, workflows introduces a utility
function called ``workflow.continuation``:

.. testcode::

Expand Down

0 comments on commit 120d233

Please sign in to comment.