Quick Start

Installation

Let’s first install the engine with parsl support alongside AiiDA core, which provides the database layer for provenance storage.

$ pip install node-graph-engine[parsl] aiida-core

After installing the packages, initialise an AiiDA profile with verdi presto. This interactive setup only needs to be run once per environment.

$ verdi presto

Creating a simple graph

Suppose we want to calculate (x + y) * z in two steps.

  • step 1: add x and y

  • step 2: then multiply the result with z.

from node_graph.decorator import task
from aiida import load_profile

load_profile()


# Define the tasks
@task()
def add(x, y):
    return x + y


@task()
def multiply(x, y):
    return x * y


# Define the graph
@task.graph()
def AddMultiply(x, y, z):
    the_sum = add(x=x, y=y).result
    return multiply(x=the_sum, y=z).result


ng = AddMultiply.build(x=1, y=2, z=3)
# Visualise the graph
ng.to_html()


Engines and provenance

Run graphs using ParslEngine

from node_graph_engine.engines.parsl import ParslEngine

graph = AddMultiply.build(x=1, y=2, z=3)

engine = ParslEngine()
results = engine.run(graph)
print("results:", results)
Call kwargs: {'x': 1, 'y': 2}
Call kwargs: {'x': 3, 'y': 3}
Persisting workflow knowledge for process node 5
No semantics found; skipping knowledge graph creation.
results: {'result': <Int: uuid: 07f0e4b6-8368-43ba-9a66-8d55b0498fa8 (pk: 9) value: 9>}

After the workflow completes you can inspect its provenance using the AiiDA CLI. The -a option ensures finished processes remain visible.

$ verdi process list -a

 216211  12s ago    NodeGraph<AddMultiply>                                               ⏹ Finished [0]
 216212  12s ago    add                                                                  ⏹ Finished [0]
 216214  12s ago    multiply                                                             ⏹ Finished [0]

In interactive notebooks you can display the provenance graph inline

engine.provenance_graph
100%
%3 N5 Graph<AddMultiply> (7c7409bc) State: finished Exit Code: 0 N6 add (2b244940) State: finished Exit Code: 0 N5->N6 CALL_CALC add N8 multiply (496c814d) State: finished Exit Code: 0 N5->N8 CALL_CALC multiply N9 Int (07f0e4b6) value: 9 N5->N9 RETURN result N2 Int (ef12bb91) value: 1 N2->N5 INPUT_WORK x N3 Int (f8ded355) value: 2 N3->N5 INPUT_WORK y N4 Int (d0564bec) value: 3 N4->N5 INPUT_WORK z N7 Int (e40d83c2) value: 3 N6->N7 CREATE result N7->N8 INPUT_CALC x N8->N9 CREATE result


Total running time of the script: (0 minutes 2.775 seconds)

Gallery generated by Sphinx-Gallery