Skip to content

Commit ad4b8a9

Browse files
authored
Always define type in node definition (#92)
* Always define type in node definition * black formatting
1 parent 8871fea commit ad4b8a9

File tree

7 files changed

+56
-53
lines changed

7 files changed

+56
-53
lines changed

example_workflows/arithmetic/workflow.json

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

example_workflows/nfdi/workflow.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
{
22
"nodes": [
3-
{"id": 0, "function": "workflow.generate_mesh"},
4-
{"id": 1, "function": "workflow.convert_to_xdmf"},
5-
{"id": 2, "function": "workflow.poisson"},
6-
{"id": 3, "function": "workflow.plot_over_line"},
7-
{"id": 4, "function": "workflow.substitute_macros"},
8-
{"id": 5, "function": "workflow.compile_paper"},
9-
{"id": 6, "value": 2.0}
3+
{"id": 0, "type": "function", "value": "workflow.generate_mesh"},
4+
{"id": 1, "type": "function", "value": "workflow.convert_to_xdmf"},
5+
{"id": 2, "type": "function", "value": "workflow.poisson"},
6+
{"id": 3, "type": "function", "value": "workflow.plot_over_line"},
7+
{"id": 4, "type": "function", "value": "workflow.substitute_macros"},
8+
{"id": 5, "type": "function", "value": "workflow.compile_paper"},
9+
{"id": 6, "type": "input", "value": 2.0}
1010
],
1111
"edges": [
1212
{"target": 0, "targetPort": "domain_size", "source": 6, "sourcePort": null},

example_workflows/quantum_espresso/workflow.json

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
11
{
22
"nodes": [
3-
{"id": 0, "function": "workflow.get_bulk_structure"},
4-
{"id": 1, "function": "workflow.calculate_qe"},
5-
{"id": 2, "function": "workflow.generate_structures"},
6-
{"id": 3, "function": "workflow.calculate_qe"},
7-
{"id": 4, "function": "workflow.calculate_qe"},
8-
{"id": 5, "function": "workflow.calculate_qe"},
9-
{"id": 6, "function": "workflow.calculate_qe"},
10-
{"id": 7, "function": "workflow.calculate_qe"},
11-
{"id": 8, "function": "workflow.plot_energy_volume_curve"},
12-
{"id": 9, "value": "Al"},
13-
{"id": 10, "value": 4.05},
14-
{"id": 11, "value": true},
15-
{"id": 12, "value": "mini"},
16-
{"id": 13, "function": "python_workflow_definition.shared.get_dict"},
17-
{"id": 14, "value": {"Al": "Al.pbe-n-kjpaw_psl.1.0.0.UPF"}},
18-
{"id": 15, "value": [3, 3, 3]},
19-
{"id": 16, "value": "vc-relax"},
20-
{"id": 17, "value": 0.02},
21-
{"id": 18, "value": [0.9, 0.95, 1.0, 1.05, 1.1]},
22-
{"id": 19, "value": "strain_0"},
23-
{"id": 20, "function": "python_workflow_definition.shared.get_dict"},
24-
{"id": 21, "value": "scf"},
25-
{"id": 22, "value": "strain_1"},
26-
{"id": 23, "function": "python_workflow_definition.shared.get_dict"},
27-
{"id": 24, "value": "strain_2"},
28-
{"id": 25, "function": "python_workflow_definition.shared.get_dict"},
29-
{"id": 26, "value": "strain_3"},
30-
{"id": 27, "function": "python_workflow_definition.shared.get_dict"},
31-
{"id": 28, "value": "strain_4"},
32-
{"id": 29, "function": "python_workflow_definition.shared.get_dict"},
33-
{"id": 30, "function": "python_workflow_definition.shared.get_list"},
34-
{"id": 31, "function": "python_workflow_definition.shared.get_list"}
3+
{"id": 0, "type": "function", "value": "workflow.get_bulk_structure"},
4+
{"id": 1, "type": "function", "value": "workflow.calculate_qe"},
5+
{"id": 2, "type": "function", "value": "workflow.generate_structures"},
6+
{"id": 3, "type": "function", "value": "workflow.calculate_qe"},
7+
{"id": 4, "type": "function", "value": "workflow.calculate_qe"},
8+
{"id": 5, "type": "function", "value": "workflow.calculate_qe"},
9+
{"id": 6, "type": "function", "value": "workflow.calculate_qe"},
10+
{"id": 7, "type": "function", "value": "workflow.calculate_qe"},
11+
{"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"},
16+
{"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"},
23+
{"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"},
26+
{"id": 23, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
27+
{"id": 24, "type": "input", "value": "strain_2"},
28+
{"id": 25, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
29+
{"id": 26, "type": "input", "value": "strain_3"},
30+
{"id": 27, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
31+
{"id": 28, "type": "input", "value": "strain_4"},
32+
{"id": 29, "type": "function", "value": "python_workflow_definition.shared.get_dict"},
33+
{"id": 30, "type": "function", "value": "python_workflow_definition.shared.get_list"},
34+
{"id": 31, "type": "function", "value": "python_workflow_definition.shared.get_list"}
3535
],
3636
"edges": [
3737
{"target": 0, "targetPort": "element", "source": 9, "sourcePort": null},

python_workflow_definition/src/python_workflow_definition/aiida.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def write_workflow_json(wg: WorkGraph, file_name: str) -> dict:
8888

8989
callable_name = executor["callable_name"]
9090
callable_name = f"{executor['module_path']}.{callable_name}"
91-
data[NODES_LABEL].append({"id": i, "function": callable_name})
91+
data[NODES_LABEL].append({"id": i, "type": "function", "value": callable_name})
9292
i += 1
9393

9494
for link in wg.links:
@@ -117,7 +117,9 @@ def write_workflow_json(wg: WorkGraph, file_name: str) -> dict:
117117
raw_value.pop("node_type", None)
118118
else:
119119
raw_value = input.value.value
120-
data[NODES_LABEL].append({"id": i, "value": raw_value})
120+
data[NODES_LABEL].append(
121+
{"id": i, "type": "input", "value": raw_value}
122+
)
121123
input_node_name = i
122124
data_node_name_mapping[input.value.uuid] = input_node_name
123125
i += 1

python_workflow_definition/src/python_workflow_definition/jobflow.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,12 @@ def write_workflow_json(flow: Flow, file_name: str = "workflow.json"):
322322
for k, v in nodes_dict.items():
323323
if isfunction(v):
324324
nodes_store_lst.append(
325-
{"id": k, "function": v.__module__ + "." + v.__name__}
325+
{"id": k, "type": "function", "value": v.__module__ + "." + v.__name__}
326326
)
327327
elif isinstance(v, np.ndarray):
328-
nodes_store_lst.append({"id": k, "value": v.tolist()})
328+
nodes_store_lst.append({"id": k, "type": "input", "value": v.tolist()})
329329
else:
330-
nodes_store_lst.append({"id": k, "value": v})
330+
nodes_store_lst.append({"id": k, "type": "input", "value": v})
331331

332332
with open(file_name, "w") as f:
333333
json.dump({NODES_LABEL: nodes_store_lst, EDGES_LABEL: edges_lst}, f)

python_workflow_definition/src/python_workflow_definition/pyiron_base.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,13 @@ def write_workflow_json(
282282
mod = v.__module__
283283
if mod == "python_workflow_definition.pyiron_base":
284284
mod = "python_workflow_definition.shared"
285-
nodes_store_lst.append({"id": k, "function": mod + "." + v.__name__})
285+
nodes_store_lst.append(
286+
{"id": k, "type": "function", "value": mod + "." + v.__name__}
287+
)
286288
elif isinstance(v, np.ndarray):
287-
nodes_store_lst.append({"id": k, "value": v.tolist()})
289+
nodes_store_lst.append({"id": k, "type": "input", "value": v.tolist()})
288290
else:
289-
nodes_store_lst.append({"id": k, "value": v})
291+
nodes_store_lst.append({"id": k, "type": "input", "value": v})
290292

291293
with open(file_name, "w") as f:
292294
json.dump({NODES_LABEL: nodes_store_lst, EDGES_LABEL: edges_new_lst}, f)

python_workflow_definition/src/python_workflow_definition/shared.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@ def get_source_handles(edges_lst: list) -> dict:
4040

4141
def convert_nodes_list_to_dict(nodes_list: list) -> dict:
4242
return {
43-
str(el["id"]): el["value"] if "value" in el else el["function"]
44-
for el in sorted(nodes_list, key=lambda d: d["id"])
43+
str(el["id"]): el["value"] for el in sorted(nodes_list, key=lambda d: d["id"])
4544
}

0 commit comments

Comments
 (0)