-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dbb585
commit 755e03a
Showing
3 changed files
with
83 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
""" | ||
WorkGraph Example | ||
================= | ||
This example demonstrates how to create, configure, and use a | ||
:class:`~aiida_workgraph.workgraph.WorkGraph` object, which is a collection of tasks and links. | ||
Create and launch workgraph | ||
---------------------------- | ||
""" | ||
|
||
# %% | ||
# First, create an empty workgraph: | ||
# | ||
|
||
from aiida_workgraph import WorkGraph, task | ||
|
||
wg = WorkGraph(name="my_first_workgraph") | ||
|
||
# %% | ||
# Define and use tasks | ||
# -------------------- | ||
# | ||
|
||
# Define a task using a `calcfunction`: | ||
@task.calcfunction() | ||
def add(x, y): | ||
return x + y | ||
|
||
|
||
# Add tasks to the workgraph | ||
add1 = wg.add_task(add, name="add1") | ||
add2 = wg.add_task(add, name="add2") | ||
|
||
# %% | ||
# Add a link between tasks: | ||
|
||
wg.add_link(add1.outputs["result"], add2.inputs["x"]) | ||
wg.to_html() | ||
|
||
# %% | ||
# Submit the workgraph: | ||
|
||
wg.submit(inputs={"add1": {"x": 1, "y": 2}, "add2": {"y": 3}}, wait=True) | ||
|
||
# %% | ||
# Load workgraph from the AiiDA process | ||
# ------------------------------------- | ||
# | ||
# WorkGraph saves its data as an extra attribute in its process, allowing reconstruction of the WorkGraph from the process. | ||
|
||
from aiida_workgraph import WorkGraph | ||
|
||
wg_loaded = WorkGraph.load(wg.pk) | ||
|
||
# %% | ||
# Execute order | ||
# ------------- | ||
# The tasks will be executed under the following conditions: | ||
# | ||
# - No input task | ||
# - All input tasks are finished. | ||
# Group outputs | ||
# ------------- | ||
# You can output the results of the tasks as the output of the WorkGraph. | ||
|
||
wg = WorkGraph("test_workgraph_group_outputs") | ||
wg.add_task(add, "add1", x=2, y=3) | ||
wg.group_outputs = [{"name": "sum", "from": "add1.result"}] | ||
wg.submit(wait=True) | ||
assert wg.process.outputs.sum.value == 5 | ||
|
||
# %% | ||
# List of all Methods | ||
# =================== | ||
# | ||
# .. autoclass:: aiida_workgraph.workgraph.WorkGraph | ||
# :members: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.