Skip to content

Commit

Permalink
format example
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Sep 11, 2024
1 parent 3771dfb commit dcc42d1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions docs/gallery/howto/autogen/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


# %%
# Example
# Example
# -------
# Suppose we want a WorkGraph which includes another WorkGraph`(x+y)*z` inside it.
# We can actually add a WorkGraph to another WorkGraph
Expand Down Expand Up @@ -131,7 +131,7 @@ def add_multiply(x, y, z):
# Looking at the process list we can also that multiple WorkGraphs have been submitted
#
# .. code-block:: bash
#
#
# verdi process list -a


Expand Down Expand Up @@ -213,7 +213,7 @@ def add_multiply(x, y, z):


# %%
# Example for loop
# Example for loop
# ----------------
# In this example we will create a dynamic number as specified in the input of the WorkGraph.

Expand All @@ -222,18 +222,21 @@ def add_multiply(x, y, z):
def add_one(x):
return x + 1


@task.graph_builder(outputs=[{"name": "result", "from": "context.task_out]"}])
def for_loop(nb_iterations: Int):
wg = WorkGraph()
for i in range(nb_iterations):
task = wg.add_task(add_one, x=i)
task = wg.add_task(add_one, x=i)

# We cannot refer to a specific task as output in the graph builder decorator
# as in the examples below as the name of the last task depends on the input.
# Therefore we use the context to not directly refer to the name but the last
# task object that was created. The context can then be reffered in the outputs
# of the graph builder decorator.
task.set_context({"result": "task_out"}) # put result of the task to the context under the name task_out
task.set_context(
{"result": "task_out"}
) # put result of the task to the context under the name task_out
# If want to know more about the usage of the context please refer to the
# context howto in the documentation
return wg
Expand All @@ -255,7 +258,6 @@ def for_loop(nb_iterations: Int):
generate_node_graph(wg.pk)



# %%
# Example if-then-else
# --------------------
Expand All @@ -279,7 +281,7 @@ def if_then_else(i: Int):
else:
task = wg.add_task(modulo_two, x=i)

task.set_context({"result": "task_out"})
task.set_context({"result": "task_out"})
return wg


Expand Down

0 comments on commit dcc42d1

Please sign in to comment.