Skip to content

Commit b354427

Browse files
authored
Fix the order of nodes for pyiron_base (#163)
* Fix the order of nodes for pyiron_base * black fixes * load object * invert order
1 parent 8e2a625 commit b354427

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/python_workflow_definition/pyiron_base.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,26 +285,40 @@ def write_workflow_json(
285285
)
286286

287287
nodes_store_lst = []
288-
for k, v in nodes_new_dict.items():
288+
translate_dict = {}
289+
for i, k in enumerate(list(nodes_new_dict.keys())[::-1]):
290+
v = nodes_new_dict[k]
291+
translate_dict[k] = i
289292
if isfunction(v):
290293
mod = v.__module__
291294
if mod == "python_workflow_definition.pyiron_base":
292295
mod = "python_workflow_definition.shared"
293296
nodes_store_lst.append(
294-
{"id": k, "type": "function", "value": mod + "." + v.__name__}
297+
{"id": i, "type": "function", "value": mod + "." + v.__name__}
295298
)
296299
elif isinstance(v, np.ndarray):
297-
nodes_store_lst.append({"id": k, "type": "input", "value": v.tolist()})
300+
nodes_store_lst.append({"id": i, "type": "input", "value": v.tolist()})
298301
else:
299-
nodes_store_lst.append({"id": k, "type": "input", "value": v})
302+
nodes_store_lst.append({"id": i, "type": "input", "value": v})
303+
304+
print(translate_dict)
305+
edges_store_lst = [
306+
{
307+
TARGET_LABEL: translate_dict[edge[TARGET_LABEL]],
308+
TARGET_PORT_LABEL: edge[TARGET_PORT_LABEL],
309+
SOURCE_LABEL: translate_dict[edge[SOURCE_LABEL]],
310+
SOURCE_PORT_LABEL: edge[SOURCE_PORT_LABEL],
311+
}
312+
for edge in edges_new_lst
313+
]
300314

301315
PythonWorkflowDefinitionWorkflow(
302316
**set_result_node(
303317
workflow_dict=update_node_names(
304318
workflow_dict={
305319
VERSION_LABEL: VERSION_NUMBER,
306320
NODES_LABEL: nodes_store_lst,
307-
EDGES_LABEL: edges_new_lst,
321+
EDGES_LABEL: edges_store_lst,
308322
}
309323
)
310324
)

0 commit comments

Comments
 (0)