Skip to content

Commit 264b43d

Browse files
committed
fix reuse of functions
1 parent 4188e24 commit 264b43d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

python_workflow_definition/src/python_workflow_definition/pyiron_workflow.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import Counter
12
from inspect import isfunction
23
from importlib import import_module
34
from typing import Any
@@ -217,12 +218,19 @@ def load_workflow_json(file_name: str) -> Workflow:
217218
{}
218219
) # Type is actually more restrictive, must be jsonifyable object
219220
nodes: dict[int, Function] = {}
221+
total_counter_dict = Counter([n["value"] for n in content[NODES_LABEL] if n["type"] == "function"])
222+
counter_dict = {k: -1 for k in total_counter_dict.keys()}
220223
wf = Workflow(file_name.split(".")[0])
221224
for node_dict in content[NODES_LABEL]:
222225
if node_dict["type"] == "function":
223226
fnc = import_from_string(node_dict["value"])
227+
if total_counter_dict[node_dict["value"]] > 1:
228+
counter_dict[node_dict["value"]] += 1
229+
name = fnc.__name__ + "_" + str(counter_dict[node_dict["value"]])
230+
else:
231+
name = fnc.__name__
224232
n = function_node(
225-
fnc, output_labels=fnc.__name__ # Strictly force single-output
233+
fnc, output_labels=name # Strictly force single-output
226234
)
227235
nodes[node_dict["id"]] = n
228236
wf.add_child(n)

0 commit comments

Comments
 (0)