44from typing import Any
55
66import numpy as np
7- from pyiron_workflow import function_node , Workflow
7+ from pyiron_workflow import as_function_node , function_node , Workflow
88from pyiron_workflow .api import Function
99
1010from python_workflow_definition .models import PythonWorkflowDefinitionWorkflow
@@ -209,6 +209,15 @@ def import_from_string(library_path: str) -> Any:
209209 return obj
210210
211211
212+ def generate_function (args_of_lst ):
213+ lines = "def get_dict(" + ", " .join (args_of_lst ) + "):\n "
214+ lines += " return {\n "
215+ for parameter in args_of_lst :
216+ lines += ' "' + parameter + '": ' + parameter + ",\n "
217+ lines += " }"
218+ return lines
219+
220+
212221def load_workflow_json (file_name : str ) -> Workflow :
213222 content = remove_result (
214223 PythonWorkflowDefinitionWorkflow .load_json_file (file_name = file_name )
@@ -225,7 +234,19 @@ def load_workflow_json(file_name: str) -> Workflow:
225234 wf = Workflow (file_name .split ("." )[0 ])
226235 for node_dict in content [NODES_LABEL ]:
227236 if node_dict ["type" ] == "function" :
228- fnc = import_from_string (node_dict ["value" ])
237+ if node_dict ["value" ] == "python_workflow_definition.shared.get_dict" :
238+ exec (
239+ generate_function (
240+ args_of_lst = [
241+ edge [TARGET_PORT_LABEL ]
242+ for edge in content [EDGES_LABEL ]
243+ if edge [TARGET_LABEL ] == node_dict ["value" ]
244+ ]
245+ )
246+ )
247+ fnc = eval ("get_dict" )
248+ else :
249+ fnc = import_from_string (node_dict ["value" ])
229250 if total_counter_dict [node_dict ["value" ]] > 1 :
230251 counter_dict [node_dict ["value" ]] += 1
231252 name = fnc .__name__ + "_" + str (counter_dict [node_dict ["value" ]])
@@ -238,10 +259,10 @@ def load_workflow_json(file_name: str) -> Workflow:
238259 input_values [node_dict ["id" ]] = node_dict ["value" ]
239260
240261 for edge_dict in content [EDGES_LABEL ]:
241- target_id = edge_dict ["target" ]
242- target_port = edge_dict ["targetPort" ]
243- source_id = edge_dict ["source" ]
244- source_port = edge_dict ["sourcePort" ]
262+ target_id = edge_dict [TARGET_LABEL ]
263+ target_port = edge_dict [TARGET_PORT_LABEL ]
264+ source_id = edge_dict [SOURCE_LABEL ]
265+ source_port = edge_dict [SOURCE_PORT_LABEL ]
245266
246267 if source_port is None :
247268 if source_id in input_values .keys (): # Parent input value
0 commit comments