nested graph_sub_nodes and graph input/output
This MR replaces nested graph_sub_nodes
with graph input and output nodes.
This is an example of nested graph_sub_nodes
(the final merged graph has only 2 nodes)
from ewokscore import load_graph
def myfunc(name=None, value=0):
print("name:", name, "value:", value)
return value + 1
subsubgraph = {
"nodes": [
{
"id": "subsubnode1",
"task_type": "method",
"task_identifier": "__main__.myfunc",
"inputs": {"name": "subnode1", "value": 0},
}
]
}
subgraph = {
"nodes": [{"id": "subnode1", "task_type": "graph", "task_identifier": subsubgraph}]
}
nodes = [
{
"id": "node1",
"task_type": "method",
"task_identifier": "__main__.myfunc",
"inputs": {"name": "node1", "value": 0},
},
{"id": "node2", "task_type": "graph", "task_identifier": subgraph},
]
links = [
{
"source": "node1",
"target": "node2",
"sub_graph_nodes": {
"sub_target": "subnode1",
"sub_graph_nodes": {"sub_target": "subsubnode1"},
},
"arguments": {"value": "return_value"},
}
]
graph = load_graph({"nodes": nodes, "links": links})
graph.execute()
With graph input_nodes
and graph output_nodes
this becomes
from ewokscore import load_graph
def myfunc(name=None, value=0):
print("name:", name, "value:", value)
return value + 1
subsubgraph = {
"graph": {"input_nodes": {"in": {"id":"subsubnode1"}}},
"nodes": [
{
"id": "subsubnode1",
"task_type": "method",
"task_identifier": "__main__.myfunc",
"inputs": {"name": "subnode1", "value": 0},
}
],
}
subgraph = {
"graph": {"input_nodes": {"in": {"id":"subnode1", "sub_node":"in"}}},
"nodes": [{"id": "subnode1", "task_type": "graph", "task_identifier": subsubgraph}],
}
nodes = [
{
"id": "node1",
"task_type": "method",
"task_identifier": "__main__.myfunc",
"inputs": {"name": "node1", "value": 0},
},
{"id": "node2", "task_type": "graph", "task_identifier": subgraph},
]
links = [
{
"source": "node1",
"target": "node2",
"sub_graph_nodes": {
"sub_target": "in",
},
"arguments": {"value": "return_value"},
}
]
ewoksgraph = load_graph({"nodes": nodes, "links": links})
tasks = ewoksgraph.execute()
This idea is that when you use subgraphs, you only need to know the input_nodes
and output_nodes
. You no longer need to know what happens in the subgraphs.
Edited by Wout De Nolf