Skip to content

Commit 83e5644

Browse files
committed
Implement input node names
1 parent ad4b8a9 commit 83e5644

File tree

7 files changed

+55
-21
lines changed

7 files changed

+55
-21
lines changed

example_workflows/arithmetic/workflow.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"nodes": [
33
{"id": 0, "type": "function", "value": "workflow.get_prod_and_div"},
44
{"id": 1, "type": "function", "value": "workflow.get_sum"},
5-
{"id": 2, "type": "input", "value": 1},
6-
{"id": 3, "type": "input", "value": 2}
5+
{"id": 2, "type": "input", "value": 1, "name": "x"},
6+
{"id": 3, "type": "input", "value": 2, "name": "y"}
77
],
88
"edges": [
99
{"target": 0, "targetPort": "x", "source": 2, "sourcePort": null},

example_workflows/nfdi/workflow.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{"id": 3, "type": "function", "value": "workflow.plot_over_line"},
77
{"id": 4, "type": "function", "value": "workflow.substitute_macros"},
88
{"id": 5, "type": "function", "value": "workflow.compile_paper"},
9-
{"id": 6, "type": "input", "value": 2.0}
9+
{"id": 6, "type": "input", "value": 2.0, "name": "domain_size"}
1010
],
1111
"edges": [
1212
{"target": 0, "targetPort": "domain_size", "source": 6, "sourcePort": null},

example_workflows/quantum_espresso/workflow.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,26 @@
99
{"id": 6, "type": "function", "value": "workflow.calculate_qe"},
1010
{"id": 7, "type": "function", "value": "workflow.calculate_qe"},
1111
{"id": 8, "type": "function", "value": "workflow.plot_energy_volume_curve"},
12-
{"id": 9, "type": "input", "value": "Al"},
13-
{"id": 10, "type": "input", "value": 4.05},
14-
{"id": 11, "type": "input", "value": true},
15-
{"id": 12, "type": "input", "value": "mini"},
12+
{"id": 9, "type": "input", "value": "Al", "name": "element"},
13+
{"id": 10, "type": "input", "value": 4.05, "name": "a"},
14+
{"id": 11, "type": "input", "value": true, "name": "cubic"},
15+
{"id": 12, "type": "input", "value": "mini", "name": "working_directory_0"},
1616
{"id": 13, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
17-
{"id": 14, "type": "input", "value": {"Al": "Al.pbe-n-kjpaw_psl.1.0.0.UPF"}},
18-
{"id": 15, "type": "input", "value": [3, 3, 3]},
19-
{"id": 16, "type": "input", "value": "vc-relax"},
20-
{"id": 17, "type": "input", "value": 0.02},
21-
{"id": 18, "type": "input", "value": [0.9, 0.95, 1.0, 1.05, 1.1]},
22-
{"id": 19, "type": "input", "value": "strain_0"},
17+
{"id": 14, "type": "input", "value": {"Al": "Al.pbe-n-kjpaw_psl.1.0.0.UPF"}, "name": "pseudopotentials"},
18+
{"id": 15, "type": "input", "value": [3, 3, 3], "name": "kpts"},
19+
{"id": 16, "type": "input", "value": "vc-relax", "name": "calculation_0"},
20+
{"id": 17, "type": "input", "value": 0.02, "name": "smearing"},
21+
{"id": 18, "type": "input", "value": [0.9, 0.95, 1.0, 1.05, 1.1], "name": "strain_lst"},
22+
{"id": 19, "type": "input", "value": "strain_0", "name": "working_directory_1"},
2323
{"id": 20, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
24-
{"id": 21, "type": "input", "value": "scf"},
25-
{"id": 22, "type": "input", "value": "strain_1"},
24+
{"id": 21, "type": "input", "value": "scf", "name": "calculation_1"},
25+
{"id": 22, "type": "input", "value": "strain_1", "name": "working_directory_2"},
2626
{"id": 23, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
27-
{"id": 24, "type": "input", "value": "strain_2"},
27+
{"id": 24, "type": "input", "value": "strain_2", "name": "working_directory_3"},
2828
{"id": 25, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
29-
{"id": 26, "type": "input", "value": "strain_3"},
29+
{"id": 26, "type": "input", "value": "strain_3", "name": "working_directory_4"},
3030
{"id": 27, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
31-
{"id": 28, "type": "input", "value": "strain_4"},
31+
{"id": 28, "type": "input", "value": "strain_4", "name": "working_directory_5"},
3232
{"id": 29, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
3333
{"id": 30, "type": "function", "value": "python_workflow_definition.shared.get_list"},
3434
{"id": 31, "type": "function", "value": "python_workflow_definition.shared.get_list"}

python_workflow_definition/src/python_workflow_definition/aiida.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from python_workflow_definition.shared import (
1111
convert_nodes_list_to_dict,
12+
update_node_names,
1213
NODES_LABEL,
1314
EDGES_LABEL,
1415
SOURCE_LABEL,
@@ -135,6 +136,6 @@ def write_workflow_json(wg: WorkGraph, file_name: str) -> dict:
135136
)
136137
with open(file_name, "w") as f:
137138
# json.dump({"nodes": data[], "edges": edges_new_lst}, f)
138-
json.dump(data, f, indent=2)
139+
json.dump(update_node_names(content=data), f, indent=2)
139140

140141
return data

python_workflow_definition/src/python_workflow_definition/jobflow.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
get_list,
1111
get_kwargs,
1212
get_source_handles,
13+
update_node_names,
1314
convert_nodes_list_to_dict,
1415
NODES_LABEL,
1516
EDGES_LABEL,
@@ -330,4 +331,7 @@ def write_workflow_json(flow: Flow, file_name: str = "workflow.json"):
330331
nodes_store_lst.append({"id": k, "type": "input", "value": v})
331332

332333
with open(file_name, "w") as f:
333-
json.dump({NODES_LABEL: nodes_store_lst, EDGES_LABEL: edges_lst}, f)
334+
json.dump(update_node_names(content={
335+
NODES_LABEL: nodes_store_lst,
336+
EDGES_LABEL: edges_lst
337+
}), f, indent=2)

python_workflow_definition/src/python_workflow_definition/pyiron_base.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
get_kwargs,
1212
get_source_handles,
1313
convert_nodes_list_to_dict,
14+
update_node_names,
1415
NODES_LABEL,
1516
EDGES_LABEL,
1617
SOURCE_LABEL,
@@ -291,4 +292,7 @@ def write_workflow_json(
291292
nodes_store_lst.append({"id": k, "type": "input", "value": v})
292293

293294
with open(file_name, "w") as f:
294-
json.dump({NODES_LABEL: nodes_store_lst, EDGES_LABEL: edges_new_lst}, f)
295+
json.dump(update_node_names(content={
296+
NODES_LABEL: nodes_store_lst,
297+
EDGES_LABEL: edges_new_lst
298+
}), f, indent=2)

python_workflow_definition/src/python_workflow_definition/shared.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections import Counter
2+
13
NODES_LABEL = "nodes"
24
EDGES_LABEL = "edges"
35
SOURCE_LABEL = "source"
@@ -42,3 +44,26 @@ def convert_nodes_list_to_dict(nodes_list: list) -> dict:
4244
return {
4345
str(el["id"]): el["value"] for el in sorted(nodes_list, key=lambda d: d["id"])
4446
}
47+
48+
49+
def update_node_names(content: dict) -> dict:
50+
node_names_final_dict = {}
51+
input_nodes = [n for n in content[NODES_LABEL] if n["type"] == "input"]
52+
node_names_dict = {
53+
n["id"]: list(set([e[TARGET_PORT_LABEL] for e in content[EDGES_LABEL] if e[SOURCE_LABEL] == n["id"]]))[0]
54+
for n in input_nodes
55+
}
56+
57+
counter_dict = Counter(node_names_dict.values())
58+
node_names_useage_dict = {k: -1 for k in counter_dict.keys()}
59+
for k, v in node_names_dict.items():
60+
node_names_useage_dict[v] += 1
61+
if counter_dict[v] > 1:
62+
node_names_final_dict[k] = v + "_" + str(node_names_useage_dict[v])
63+
else:
64+
node_names_final_dict[k] = v
65+
66+
for n in content[NODES_LABEL]:
67+
if n["type"] == "input":
68+
n["name"] = node_names_final_dict[n["id"]]
69+
return content

0 commit comments

Comments
 (0)