Skip to content

Commit

Permalink
fix typo, improve text
Browse files Browse the repository at this point in the history
  • Loading branch information
agoscinski committed Sep 11, 2024
1 parent dcc42d1 commit c6f29b5
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions docs/gallery/howto/autogen/graph_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,16 @@ def add_multiply(x, y, z):
# %%
# Example for loop
# ----------------
# In this example we will create a dynamic number as specified in the input of the WorkGraph.
# In this example we will create a dynamic number of tasks as specified in the
# input of the WorkGraph.


@task.calcfunction()
def add_one(x):
return x + 1


@task.graph_builder(outputs=[{"name": "result", "from": "context.task_out]"}])
@task.graph_builder(outputs=[{"name": "result", "from": "context.task_out"}])
def for_loop(nb_iterations: Int):
wg = WorkGraph()
for i in range(nb_iterations):
Expand Down Expand Up @@ -261,8 +262,9 @@ def for_loop(nb_iterations: Int):
# %%
# Example if-then-else
# --------------------
# Suppose to run a different task depending on the input. We want to run the add_one task if the number is below 2
# otherwise we want to run a modulo 2 task. For thet we require to create a context.
# Suppose we want to run a different task depending on the input. We run the
# add_one task if the number is below 2 otherwise we run a modulo 2
# task.

from aiida_workgraph import task, WorkGraph
from aiida.orm import Int
Expand All @@ -281,6 +283,7 @@ def if_then_else(i: Int):
else:
task = wg.add_task(modulo_two, x=i)

# same concept as before, please read the for loop example for explanation
task.set_context({"result": "task_out"})
return wg

Expand Down

0 comments on commit c6f29b5

Please sign in to comment.