Skip to content

Commit 0c06649

Browse files
committed
Replace cryptic edges notation with elk inspired edges
The eclipse library provides a standard [JSON format for graphs](https://eclipse.dev/elk/documentation/tooldevelopers/graphdatastructure/jsonformat.html). So there is no need to invent a new JSON representation.
1 parent 2efbdf1 commit 0c06649

File tree

11 files changed

+157
-157
lines changed

11 files changed

+157
-157
lines changed

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,23 @@ JSON file:
4343
"5": 2
4444
},
4545
"edges": [
46-
{"tn": 0, "th": "x", "sn": 1, "sh": "x"},
47-
{"tn": 1, "th": "x", "sn": 4, "sh": null},
48-
{"tn": 1, "th": "y", "sn": 5, "sh": null},
49-
{"tn": 0, "th": "y", "sn": 2, "sh": "y"},
50-
{"tn": 2, "th": "x", "sn": 4, "sh": null},
51-
{"tn": 2, "th": "y", "sn": 5, "sh": null},
52-
{"tn": 0, "th": "z", "sn": 3, "sh": "z"},
53-
{"tn": 3, "th": "x", "sn": 4, "sh": null},
54-
{"tn": 3, "th": "y", "sn": 5, "sh": null}
46+
{"target": 0, "targetPort": "x", "source": 1, "sourcePort": "x"},
47+
{"target": 1, "targetPort": "x", "source": 4, "sourcePort": null},
48+
{"target": 1, "targetPort": "y", "source": 5, "sourcePort": null},
49+
{"target": 0, "targetPort": "y", "source": 2, "sourcePort": "y"},
50+
{"target": 2, "targetPort": "x", "source": 4, "sourcePort": null},
51+
{"target": 2, "targetPort": "y", "source": 5, "sourcePort": null},
52+
{"target": 0, "targetPort": "z", "source": 3, "sourcePort": "z"},
53+
{"target": 3, "targetPort": "x", "source": 4, "sourcePort": null},
54+
{"target": 3, "targetPort": "y", "source": 5, "sourcePort": null}
5555
]
5656
}
5757
```
5858
The abbreviations in the definition of the edges are:
59-
* `tn` - target node
60-
* `th` - target handle - for a node with multiple input parameters the target handle specifies which input parameter to use.
61-
* `sn` - source node
62-
* `sh` - source handle - for a node with multiple output parameters the source handle specifies which output parameter to use.
59+
* `target` - target node
60+
* `targetPort` - target port - for a node with multiple input parameters the target port specifies which input parameter to use.
61+
* `source` - source node
62+
* `sourcePort` - source port - for a node with multiple output parameters the source port specifies which output parameter to use.
6363

6464
As the workflow does not require any additional resources, as it is only using built-in functionality of the Python standard
6565
library.

book/simple.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ JSON file:
2828
"5": 2
2929
},
3030
"edges": [
31-
{"tn": 0, "th": "x", "sn": 1, "sh": "x"},
32-
{"tn": 1, "th": "x", "sn": 4, "sh": null},
33-
{"tn": 1, "th": "y", "sn": 5, "sh": null},
34-
{"tn": 0, "th": "y", "sn": 2, "sh": "y"},
35-
{"tn": 2, "th": "x", "sn": 4, "sh": null},
36-
{"tn": 2, "th": "y", "sn": 5, "sh": null},
37-
{"tn": 0, "th": "z", "sn": 3, "sh": "z"},
38-
{"tn": 3, "th": "x", "sn": 4, "sh": null},
39-
{"tn": 3, "th": "y", "sn": 5, "sh": null}
31+
{"target": 0, "targetPort": "x", "source": 1, "sourcePort": "x"},
32+
{"target": 1, "targetPort": "x", "source": 4, "sourcePort": null},
33+
{"target": 1, "targetPort": "y", "source": 5, "sourcePort": null},
34+
{"target": 0, "targetPort": "y", "source": 2, "sourcePort": "y"},
35+
{"target": 2, "targetPort": "x", "source": 4, "sourcePort": null},
36+
{"target": 2, "targetPort": "y", "source": 5, "sourcePort": null},
37+
{"target": 0, "targetPort": "z", "source": 3, "sourcePort": "z"},
38+
{"target": 3, "targetPort": "x", "source": 4, "sourcePort": null},
39+
{"target": 3, "targetPort": "y", "source": 5, "sourcePort": null}
4040
]
4141
}
4242
```

python_workflow_definition/src/python_workflow_definition/aiida.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@ def load_workflow_json(file_name):
3030

3131
# add links
3232
for link in data["edges"]:
33-
to_task = task_name_mapping[str(link["tn"])]
33+
to_task = task_name_mapping[str(link["target"])]
3434
# if the input is not exit, it means we pass the data into to the kwargs
3535
# in this case, we add the input socket
36-
if link["th"] not in to_task.inputs:
37-
to_socket = to_task.add_input( "workgraph.any", name=link["th"])
36+
if link["targetPort"] not in to_task.inputs:
37+
to_socket = to_task.add_input( "workgraph.any", name=link["targetPort"])
3838
else:
39-
to_socket = to_task.inputs[link["th"]]
40-
from_task = task_name_mapping[str(link["sn"])]
39+
to_socket = to_task.inputs[link["targetPort"]]
40+
from_task = task_name_mapping[str(link["source"])]
4141
if isinstance(from_task, orm.Data):
4242
to_socket.value = from_task
4343
else:
4444
try:
45-
if link["sh"] is None:
46-
link["sh"] = "result"
45+
if link["sourcePort"] is None:
46+
link["sourcePort"] = "result"
4747
# because we are not define the outputs explicitly during the pythonjob creation
4848
# we add it here, and assume the output exit
49-
if link["sh"] not in from_task.outputs:
50-
# if str(link["sh"]) not in from_task.outputs:
49+
if link["sourcePort"] not in from_task.outputs:
50+
# if str(link["sourcePort"]) not in from_task.outputs:
5151
from_socket = from_task.add_output(
5252
"workgraph.any",
53-
name=link["sh"],
54-
# name=str(link["sh"]),
53+
name=link["sourcePort"],
54+
# name=str(link["sourcePort"]),
5555
metadata={"is_function_output": True},
5656
)
5757
else:
58-
from_socket = from_task.outputs[link["sh"]]
58+
from_socket = from_task.outputs[link["sourcePort"]]
5959

6060
wg.add_link(from_socket, to_socket)
6161
except Exception as e:
@@ -84,10 +84,10 @@ def write_workflow_json(wg, file_name):
8484
# if the from socket is the default result, we set it to None
8585
if link_data["from_socket"] == "result":
8686
link_data["from_socket"] = None
87-
link_data["tn"] = node_name_mapping[link_data.pop("to_node")]
88-
link_data["th"] = link_data.pop("to_socket")
89-
link_data["sn"] = node_name_mapping[link_data.pop("from_node")]
90-
link_data["sh"] = link_data.pop("from_socket")
87+
link_data["target"] = node_name_mapping[link_data.pop("to_node")]
88+
link_data["targetPort"] = link_data.pop("to_socket")
89+
link_data["source"] = node_name_mapping[link_data.pop("from_node")]
90+
link_data["sourcePort"] = link_data.pop("from_socket")
9191
data["edges"].append(link_data)
9292

9393
for node in wg.tasks:
@@ -112,10 +112,10 @@ def write_workflow_json(wg, file_name):
112112
else:
113113
input_node_name = data_node_name_mapping[input.value.uuid]
114114
data["edges"].append({
115-
"tn": node_name_mapping[node.name],
116-
"th": input._name,
117-
"sn": input_node_name,
118-
"sh": None
115+
"target": node_name_mapping[node.name],
116+
"targetPort": input._name,
117+
"source": input_node_name,
118+
"sourcePort": None
119119
})
120120
with open(file_name, "w") as f:
121121
# json.dump({"nodes": data[], "edges": edges_new_lst}, f)

python_workflow_definition/src/python_workflow_definition/executorlib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def get_item(obj, key):
1212

1313

1414
def _get_value(result_dict, nodes_new_dict, link_dict, exe):
15-
source, source_handle = link_dict["sn"], link_dict["sh"]
15+
source, source_handle = link_dict["source"], link_dict["sourcePort"]
1616
if source in result_dict.keys():
1717
result = result_dict[source]
1818
elif source in nodes_new_dict.keys():

python_workflow_definition/src/python_workflow_definition/jobflow.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def _get_nodes_dict(function_dict):
2626

2727
def _get_edge_from_dict(target, key, value_dict, nodes_mapping_dict):
2828
if len(value_dict['attributes']) == 1:
29-
return {'tn': target, 'th': key, "sn": nodes_mapping_dict[value_dict['uuid']], 'sh': value_dict['attributes'][0][1]}
29+
return {'tn': target, 'th': key, "source": nodes_mapping_dict[value_dict['uuid']], 'sh': value_dict['attributes'][0][1]}
3030
else:
31-
return {'tn': target, 'th': key, "sn": nodes_mapping_dict[value_dict['uuid']], 'sh': None}
31+
return {'tn': target, 'th': key, "source": nodes_mapping_dict[value_dict['uuid']], 'sh': None}
3232

3333

3434
def _get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict):
@@ -59,8 +59,8 @@ def _get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict):
5959
nodes_dict[node_index] = vt
6060
else:
6161
node_index = {str(tv): tk for tk, tv in nodes_dict.items()}[str(vt)]
62-
edges_lst.append({'tn': node_dict_index, 'th': kt, "sn": node_index, 'sh': None})
63-
edges_lst.append({'tn': nodes_mapping_dict[job["uuid"]], 'th': k, "sn": node_dict_index, 'sh': None})
62+
edges_lst.append({'tn': node_dict_index, 'th': kt, "source": node_index, 'sh': None})
63+
edges_lst.append({'tn': nodes_mapping_dict[job["uuid"]], 'th': k, "source": node_dict_index, 'sh': None})
6464
elif isinstance(v, list) and any([isinstance(el, dict) and '@module' in el and '@class' in el and '@version' in el for el in v]):
6565
node_list_index = len(nodes_dict)
6666
nodes_dict[node_list_index] = get_list
@@ -78,15 +78,15 @@ def _get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict):
7878
nodes_dict[node_index] = vt
7979
else:
8080
node_index = {str(tv): tk for tk, tv in nodes_dict.items()}[str(vt)]
81-
edges_lst.append({'tn': node_list_index, 'th': kt, "sn": node_index, 'sh': None})
82-
edges_lst.append({'tn': nodes_mapping_dict[job["uuid"]], 'th': k, "sn": node_list_index, 'sh': None})
81+
edges_lst.append({'tn': node_list_index, 'th': kt, "source": node_index, 'sh': None})
82+
edges_lst.append({'tn': nodes_mapping_dict[job["uuid"]], 'th': k, "source": node_list_index, 'sh': None})
8383
else:
8484
if v not in nodes_dict.values():
8585
node_index = len(nodes_dict)
8686
nodes_dict[node_index] = v
8787
else:
8888
node_index = {tv: tk for tk, tv in nodes_dict.items()}[v]
89-
edges_lst.append({'tn': nodes_mapping_dict[job["uuid"]], 'th': k, "sn": node_index, 'sh': None})
89+
edges_lst.append({'tn': nodes_mapping_dict[job["uuid"]], 'th': k, "source": node_index, 'sh': None})
9090
return edges_lst, nodes_dict
9191

9292

@@ -99,7 +99,7 @@ def _resort_total_lst(total_dict, nodes_dict):
9999
for ind in sorted(total_dict.keys()):
100100
connect = total_dict[ind]
101101
if ind not in ordered_lst:
102-
source_lst = [sd["sn"] for sd in connect.values()]
102+
source_lst = [sd["source"] for sd in connect.values()]
103103
if all([s in ordered_lst or s in nodes_without_dep_lst for s in source_lst]):
104104
ordered_lst.append(ind)
105105
total_new_dict[ind] = connect
@@ -109,11 +109,11 @@ def _resort_total_lst(total_dict, nodes_dict):
109109
def _group_edges(edges_lst):
110110
total_dict = {}
111111
for ed_major in edges_lst:
112-
target_id = ed_major["tn"]
112+
target_id = ed_major["target"]
113113
tmp_lst = []
114114
if target_id not in total_dict.keys():
115115
for ed in edges_lst:
116-
if target_id == ed["tn"]:
116+
if target_id == ed["target"]:
117117
tmp_lst.append(ed)
118118
total_dict[target_id] = get_kwargs(lst=tmp_lst)
119119
return total_dict

python_workflow_definition/src/python_workflow_definition/purepython.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,30 @@ def resort_total_lst(total_lst, nodes_dict):
1313
while len(total_new_lst) < len(total_lst):
1414
for ind, connect in total_lst:
1515
if ind not in ordered_lst:
16-
source_lst = [sd["sn"] for sd in connect.values()]
16+
source_lst = [sd["source"] for sd in connect.values()]
1717
if all([s in ordered_lst or s in nodes_without_dep_lst for s in source_lst]):
1818
ordered_lst.append(ind)
1919
total_new_lst.append([ind, connect])
2020
return total_new_lst
2121

2222

2323
def group_edges(edges_lst):
24-
edges_sorted_lst = sorted(edges_lst, key=lambda x: x["tn"], reverse=True)
24+
edges_sorted_lst = sorted(edges_lst, key=lambda x: x["target"], reverse=True)
2525
total_lst, tmp_lst = [], []
26-
target_id = edges_sorted_lst[0]["tn"]
26+
target_id = edges_sorted_lst[0]["target"]
2727
for ed in edges_sorted_lst:
28-
if target_id == ed["tn"]:
28+
if target_id == ed["target"]:
2929
tmp_lst.append(ed)
3030
else:
3131
total_lst.append((target_id, get_kwargs(lst=tmp_lst)))
32-
target_id = ed["tn"]
32+
target_id = ed["target"]
3333
tmp_lst = [ed]
3434
total_lst.append((target_id, get_kwargs(lst=tmp_lst)))
3535
return total_lst
3636

3737

3838
def _get_value(result_dict, nodes_new_dict, link_dict):
39-
source, source_handle = link_dict["sn"], link_dict["sh"]
39+
source, source_handle = link_dict["source"], link_dict["sourcePort"]
4040
if source in result_dict.keys():
4141
result = result_dict[source]
4242
elif source in nodes_new_dict.keys():

python_workflow_definition/src/python_workflow_definition/pyiron_base.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,23 @@ def _resort_total_lst(total_lst, nodes_dict):
1616
while len(total_new_lst) < len(total_lst):
1717
for ind, connect in total_lst:
1818
if ind not in ordered_lst:
19-
source_lst = [sd["sn"] for sd in connect.values()]
19+
source_lst = [sd["source"] for sd in connect.values()]
2020
if all([s in ordered_lst or s in nodes_without_dep_lst for s in source_lst]):
2121
ordered_lst.append(ind)
2222
total_new_lst.append([ind, connect])
2323
return total_new_lst
2424

2525

2626
def _group_edges(edges_lst):
27-
edges_sorted_lst = sorted(edges_lst, key=lambda x: x["tn"], reverse=True)
27+
edges_sorted_lst = sorted(edges_lst, key=lambda x: x["target"], reverse=True)
2828
total_lst, tmp_lst = [], []
29-
target_id = edges_sorted_lst[0]["tn"]
29+
target_id = edges_sorted_lst[0]["target"]
3030
for ed in edges_sorted_lst:
31-
if target_id == ed["tn"]:
31+
if target_id == ed["target"]:
3232
tmp_lst.append(ed)
3333
else:
3434
total_lst.append((target_id, get_kwargs(lst=tmp_lst)))
35-
target_id = ed["tn"]
35+
target_id = ed["target"]
3636
tmp_lst = [ed]
3737
total_lst.append((target_id, get_kwargs(lst=tmp_lst)))
3838
return total_lst
@@ -54,8 +54,8 @@ def _get_delayed_object_dict(total_lst, nodes_dict, source_handle_dict, pyiron_p
5454
k: _get_source(
5555
nodes_dict=nodes_dict,
5656
delayed_object_dict=delayed_object_dict,
57-
source=v["sn"],
58-
sourceHandle=v["sh"],
57+
source=v["source"],
58+
sourceHandle=v["sourcePort"],
5959
)
6060
for k, v in input_dict.items()
6161
}
@@ -152,24 +152,24 @@ def _get_edges_dict(edges_lst, nodes_dict, connection_dict, lookup_dict):
152152
if isinstance(output, DelayedObject):
153153
if output._list_index is not None:
154154
edges_dict_lst.append({
155-
"tn": target,
156-
"th": target_handle,
157-
"sn": connection_dict[output_name],
158-
"sh": f"s_{output._list_index}", # check for list index
155+
"target": target,
156+
"targetPort": target_handle,
157+
"source": connection_dict[output_name],
158+
"sourcePort": f"s_{output._list_index}", # check for list index
159159
})
160160
else:
161161
edges_dict_lst.append({
162-
"tn": target,
163-
"th": target_handle,
164-
"sn": connection_dict[output_name],
165-
"sh": output._output_key, # check for list index
162+
"target": target,
163+
"targetPort": target_handle,
164+
"source": connection_dict[output_name],
165+
"sourcePort": output._output_key, # check for list index
166166
})
167167
else:
168168
edges_dict_lst.append({
169-
"tn": target,
170-
"th": target_handle,
171-
"sn": connection_dict[output_name],
172-
"sh": None,
169+
"target": target,
170+
"targetPort": target_handle,
171+
"source": connection_dict[output_name],
172+
"sourcePort": None,
173173
})
174174
existing_connection_lst.append(connection_name)
175175
return edges_dict_lst

python_workflow_definition/src/python_workflow_definition/shared.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ def get_list(**kwargs):
99

1010

1111
def get_kwargs(lst):
12-
return {t["th"]: {"sn": t["sn"], "sh": t["sh"]} for t in lst}
12+
return {t["targetPort"]: {"source": t["source"], "sourcePort": t["sourcePort"]} for t in lst}
1313

1414

1515
def get_source_handles(edges_lst):
1616
source_handle_dict = {}
1717
for ed in edges_lst:
18-
if ed["sn"] not in source_handle_dict.keys():
19-
source_handle_dict[ed["sn"]] = [ed["sh"]]
18+
if ed["source"] not in source_handle_dict.keys():
19+
source_handle_dict[ed["source"]] = [ed["sourcePort"]]
2020
else:
21-
source_handle_dict[ed["sn"]].append(ed["sh"])
21+
source_handle_dict[ed["source"]].append(ed["sourcePort"])
2222
return {
2323
k: list(range(len(v))) if len(v) > 1 and all([el is None for el in v]) else v
2424
for k, v in source_handle_dict.items()

workflow_nfdi.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
"6": 2.0
1010
},
1111
"edges": [
12-
{"tn": 0, "th": "domain_size", "sn": 6, "sh": null},
13-
{"tn": 1, "th": "gmsh_output_file", "sn": 0, "sh": null},
14-
{"tn": 2, "th": "meshio_output_xdmf", "sn": 1, "sh": "xdmf_file"},
15-
{"tn": 2, "th": "meshio_output_h5", "sn": 1, "sh": "h5_file"},
16-
{"tn": 3, "th": "poisson_output_pvd_file", "sn": 2, "sh": "pvd_file"},
17-
{"tn": 3, "th": "poisson_output_vtu_file", "sn": 2, "sh": "vtu_file"},
18-
{"tn": 4, "th": "pvbatch_output_file", "sn": 3, "sh": null},
19-
{"tn": 4, "th": "ndofs", "sn": 2, "sh": "numdofs"},
20-
{"tn": 4, "th": "domain_size", "sn": 6, "sh": null},
21-
{"tn": 5, "th": "macros_tex", "sn": 4, "sh": null},
22-
{"tn": 5, "th": "plot_file", "sn": 3, "sh": null}
12+
{"target": 0, "targetPort": "domain_size", "source": 6, "sourcePort": null},
13+
{"target": 1, "targetPort": "gmsh_output_file", "source": 0, "sourcePort": null},
14+
{"target": 2, "targetPort": "meshio_output_xdmf", "source": 1, "sourcePort": "xdmf_file"},
15+
{"target": 2, "targetPort": "meshio_output_h5", "source": 1, "sourcePort": "h5_file"},
16+
{"target": 3, "targetPort": "poisson_output_pvd_file", "source": 2, "sourcePort": "pvd_file"},
17+
{"target": 3, "targetPort": "poisson_output_vtu_file", "source": 2, "sourcePort": "vtu_file"},
18+
{"target": 4, "targetPort": "pvbatch_output_file", "source": 3, "sourcePort": null},
19+
{"target": 4, "targetPort": "ndofs", "source": 2, "sourcePort": "numdofs"},
20+
{"target": 4, "targetPort": "domain_size", "source": 6, "sourcePort": null},
21+
{"target": 5, "targetPort": "macros_tex", "source": 4, "sourcePort": null},
22+
{"target": 5, "targetPort": "plot_file", "source": 3, "sourcePort": null}
2323
]
2424
}

0 commit comments

Comments
 (0)