From bd7316dfe9e9e7d45df89812325515189a9983b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sat, 3 May 2025 08:56:29 +0200 Subject: [PATCH 1/2] Always define type in node definition --- example_workflows/arithmetic/workflow.json | 8 +-- example_workflows/nfdi/workflow.json | 14 ++-- .../quantum_espresso/workflow.json | 64 +++++++++---------- .../src/python_workflow_definition/aiida.py | 4 +- .../src/python_workflow_definition/jobflow.py | 6 +- .../python_workflow_definition/pyiron_base.py | 6 +- .../src/python_workflow_definition/shared.py | 3 +- 7 files changed, 52 insertions(+), 53 deletions(-) diff --git a/example_workflows/arithmetic/workflow.json b/example_workflows/arithmetic/workflow.json index e68cfc7..d4b2d59 100644 --- a/example_workflows/arithmetic/workflow.json +++ b/example_workflows/arithmetic/workflow.json @@ -1,9 +1,9 @@ { "nodes": [ - {"id": 0, "function": "workflow.get_prod_and_div"}, - {"id": 1, "function": "workflow.get_sum"}, - {"id": 2, "value": 1}, - {"id": 3, "value": 2} + {"id": 0, "type": "function", "value": "workflow.get_prod_and_div"}, + {"id": 1, "type": "function", "value": "workflow.get_sum"}, + {"id": 2, "type": "input", "value": 1}, + {"id": 3, "type": "input", "value": 2} ], "edges": [ {"target": 0, "targetPort": "x", "source": 2, "sourcePort": null}, diff --git a/example_workflows/nfdi/workflow.json b/example_workflows/nfdi/workflow.json index 911beb1..a4b2ad0 100644 --- a/example_workflows/nfdi/workflow.json +++ b/example_workflows/nfdi/workflow.json @@ -1,12 +1,12 @@ { "nodes": [ - {"id": 0, "function": "workflow.generate_mesh"}, - {"id": 1, "function": "workflow.convert_to_xdmf"}, - {"id": 2, "function": "workflow.poisson"}, - {"id": 3, "function": "workflow.plot_over_line"}, - {"id": 4, "function": "workflow.substitute_macros"}, - {"id": 5, "function": "workflow.compile_paper"}, - {"id": 6, "value": 2.0} + {"id": 0, "type": "function", "value": "workflow.generate_mesh"}, + {"id": 1, "type": "function", "value": "workflow.convert_to_xdmf"}, + {"id": 2, "type": "function", "value": "workflow.poisson"}, + {"id": 3, "type": "function", "value": "workflow.plot_over_line"}, + {"id": 4, "type": "function", "value": "workflow.substitute_macros"}, + {"id": 5, "type": "function", "value": "workflow.compile_paper"}, + {"id": 6, "type": "input", "value": 2.0} ], "edges": [ {"target": 0, "targetPort": "domain_size", "source": 6, "sourcePort": null}, diff --git a/example_workflows/quantum_espresso/workflow.json b/example_workflows/quantum_espresso/workflow.json index a085370..6661a76 100644 --- a/example_workflows/quantum_espresso/workflow.json +++ b/example_workflows/quantum_espresso/workflow.json @@ -1,37 +1,37 @@ { "nodes": [ - {"id": 0, "function": "workflow.get_bulk_structure"}, - {"id": 1, "function": "workflow.calculate_qe"}, - {"id": 2, "function": "workflow.generate_structures"}, - {"id": 3, "function": "workflow.calculate_qe"}, - {"id": 4, "function": "workflow.calculate_qe"}, - {"id": 5, "function": "workflow.calculate_qe"}, - {"id": 6, "function": "workflow.calculate_qe"}, - {"id": 7, "function": "workflow.calculate_qe"}, - {"id": 8, "function": "workflow.plot_energy_volume_curve"}, - {"id": 9, "value": "Al"}, - {"id": 10, "value": 4.05}, - {"id": 11, "value": true}, - {"id": 12, "value": "mini"}, - {"id": 13, "function": "python_workflow_definition.shared.get_dict"}, - {"id": 14, "value": {"Al": "Al.pbe-n-kjpaw_psl.1.0.0.UPF"}}, - {"id": 15, "value": [3, 3, 3]}, - {"id": 16, "value": "vc-relax"}, - {"id": 17, "value": 0.02}, - {"id": 18, "value": [0.9, 0.95, 1.0, 1.05, 1.1]}, - {"id": 19, "value": "strain_0"}, - {"id": 20, "function": "python_workflow_definition.shared.get_dict"}, - {"id": 21, "value": "scf"}, - {"id": 22, "value": "strain_1"}, - {"id": 23, "function": "python_workflow_definition.shared.get_dict"}, - {"id": 24, "value": "strain_2"}, - {"id": 25, "function": "python_workflow_definition.shared.get_dict"}, - {"id": 26, "value": "strain_3"}, - {"id": 27, "function": "python_workflow_definition.shared.get_dict"}, - {"id": 28, "value": "strain_4"}, - {"id": 29, "function": "python_workflow_definition.shared.get_dict"}, - {"id": 30, "function": "python_workflow_definition.shared.get_list"}, - {"id": 31, "function": "python_workflow_definition.shared.get_list"} + {"id": 0, "type": "function", "value": "workflow.get_bulk_structure"}, + {"id": 1, "type": "function", "value": "workflow.calculate_qe"}, + {"id": 2, "type": "function", "value": "workflow.generate_structures"}, + {"id": 3, "type": "function", "value": "workflow.calculate_qe"}, + {"id": 4, "type": "function", "value": "workflow.calculate_qe"}, + {"id": 5, "type": "function", "value": "workflow.calculate_qe"}, + {"id": 6, "type": "function", "value": "workflow.calculate_qe"}, + {"id": 7, "type": "function", "value": "workflow.calculate_qe"}, + {"id": 8, "type": "function", "value": "workflow.plot_energy_volume_curve"}, + {"id": 9, "type": "input", "value": "Al"}, + {"id": 10, "type": "input", "value": 4.05}, + {"id": 11, "type": "input", "value": true}, + {"id": 12, "type": "input", "value": "mini"}, + {"id": 13, "type": "function", "value": "python_workflow_definition.shared.get_dict"}, + {"id": 14, "type": "input", "value": {"Al": "Al.pbe-n-kjpaw_psl.1.0.0.UPF"}}, + {"id": 15, "type": "input", "value": [3, 3, 3]}, + {"id": 16, "type": "input", "value": "vc-relax"}, + {"id": 17, "type": "input", "value": 0.02}, + {"id": 18, "type": "input", "value": [0.9, 0.95, 1.0, 1.05, 1.1]}, + {"id": 19, "type": "input", "value": "strain_0"}, + {"id": 20, "type": "function", "value": "python_workflow_definition.shared.get_dict"}, + {"id": 21, "type": "input", "value": "scf"}, + {"id": 22, "type": "input", "value": "strain_1"}, + {"id": 23, "type": "function", "value": "python_workflow_definition.shared.get_dict"}, + {"id": 24, "type": "input", "value": "strain_2"}, + {"id": 25, "type": "function", "value": "python_workflow_definition.shared.get_dict"}, + {"id": 26, "type": "input", "value": "strain_3"}, + {"id": 27, "type": "function", "value": "python_workflow_definition.shared.get_dict"}, + {"id": 28, "type": "input", "value": "strain_4"}, + {"id": 29, "type": "function", "value": "python_workflow_definition.shared.get_dict"}, + {"id": 30, "type": "function", "value": "python_workflow_definition.shared.get_list"}, + {"id": 31, "type": "function", "value": "python_workflow_definition.shared.get_list"} ], "edges": [ {"target": 0, "targetPort": "element", "source": 9, "sourcePort": null}, diff --git a/python_workflow_definition/src/python_workflow_definition/aiida.py b/python_workflow_definition/src/python_workflow_definition/aiida.py index c3fbf12..299c735 100644 --- a/python_workflow_definition/src/python_workflow_definition/aiida.py +++ b/python_workflow_definition/src/python_workflow_definition/aiida.py @@ -88,7 +88,7 @@ def write_workflow_json(wg: WorkGraph, file_name: str) -> dict: callable_name = executor["callable_name"] callable_name = f"{executor['module_path']}.{callable_name}" - data[NODES_LABEL].append({"id": i, "function": callable_name}) + data[NODES_LABEL].append({"id": i, "type": "function", "value": callable_name}) i += 1 for link in wg.links: @@ -117,7 +117,7 @@ def write_workflow_json(wg: WorkGraph, file_name: str) -> dict: raw_value.pop("node_type", None) else: raw_value = input.value.value - data[NODES_LABEL].append({"id": i, "value": raw_value}) + data[NODES_LABEL].append({"id": i, "type": "input", "value": raw_value}) input_node_name = i data_node_name_mapping[input.value.uuid] = input_node_name i += 1 diff --git a/python_workflow_definition/src/python_workflow_definition/jobflow.py b/python_workflow_definition/src/python_workflow_definition/jobflow.py index 0fed5b6..c5966b4 100644 --- a/python_workflow_definition/src/python_workflow_definition/jobflow.py +++ b/python_workflow_definition/src/python_workflow_definition/jobflow.py @@ -322,12 +322,12 @@ def write_workflow_json(flow: Flow, file_name: str = "workflow.json"): for k, v in nodes_dict.items(): if isfunction(v): nodes_store_lst.append( - {"id": k, "function": v.__module__ + "." + v.__name__} + {"id": k, "type": "function", "value": v.__module__ + "." + v.__name__} ) elif isinstance(v, np.ndarray): - nodes_store_lst.append({"id": k, "value": v.tolist()}) + nodes_store_lst.append({"id": k, "type": "input", "value": v.tolist()}) else: - nodes_store_lst.append({"id": k, "value": v}) + nodes_store_lst.append({"id": k, "type": "input", "value": v}) with open(file_name, "w") as f: json.dump({NODES_LABEL: nodes_store_lst, EDGES_LABEL: edges_lst}, f) diff --git a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py index bbca726..a39e1ce 100644 --- a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py +++ b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py @@ -282,11 +282,11 @@ def write_workflow_json( mod = v.__module__ if mod == "python_workflow_definition.pyiron_base": mod = "python_workflow_definition.shared" - nodes_store_lst.append({"id": k, "function": mod + "." + v.__name__}) + nodes_store_lst.append({"id": k, "type": "function", "value" : mod + "." + v.__name__}) elif isinstance(v, np.ndarray): - nodes_store_lst.append({"id": k, "value": v.tolist()}) + nodes_store_lst.append({"id": k, "type": "input", "value": v.tolist()}) else: - nodes_store_lst.append({"id": k, "value": v}) + nodes_store_lst.append({"id": k, "type": "input", "value": v}) with open(file_name, "w") as f: json.dump({NODES_LABEL: nodes_store_lst, EDGES_LABEL: edges_new_lst}, f) diff --git a/python_workflow_definition/src/python_workflow_definition/shared.py b/python_workflow_definition/src/python_workflow_definition/shared.py index ebe34c7..a8cb888 100644 --- a/python_workflow_definition/src/python_workflow_definition/shared.py +++ b/python_workflow_definition/src/python_workflow_definition/shared.py @@ -40,6 +40,5 @@ def get_source_handles(edges_lst: list) -> dict: def convert_nodes_list_to_dict(nodes_list: list) -> dict: return { - str(el["id"]): el["value"] if "value" in el else el["function"] - for el in sorted(nodes_list, key=lambda d: d["id"]) + str(el["id"]): el["value"] for el in sorted(nodes_list, key=lambda d: d["id"]) } From 01454841be8ba67cd6699bec7b52cef94c279221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Jan=C3=9Fen?= Date: Sat, 3 May 2025 08:58:35 +0200 Subject: [PATCH 2/2] black formatting --- .../src/python_workflow_definition/aiida.py | 4 +++- .../src/python_workflow_definition/pyiron_base.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/python_workflow_definition/src/python_workflow_definition/aiida.py b/python_workflow_definition/src/python_workflow_definition/aiida.py index 299c735..9b5c95b 100644 --- a/python_workflow_definition/src/python_workflow_definition/aiida.py +++ b/python_workflow_definition/src/python_workflow_definition/aiida.py @@ -117,7 +117,9 @@ def write_workflow_json(wg: WorkGraph, file_name: str) -> dict: raw_value.pop("node_type", None) else: raw_value = input.value.value - data[NODES_LABEL].append({"id": i, "type": "input", "value": raw_value}) + data[NODES_LABEL].append( + {"id": i, "type": "input", "value": raw_value} + ) input_node_name = i data_node_name_mapping[input.value.uuid] = input_node_name i += 1 diff --git a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py index a39e1ce..a611ae7 100644 --- a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py +++ b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py @@ -282,7 +282,9 @@ def write_workflow_json( mod = v.__module__ if mod == "python_workflow_definition.pyiron_base": mod = "python_workflow_definition.shared" - nodes_store_lst.append({"id": k, "type": "function", "value" : mod + "." + v.__name__}) + nodes_store_lst.append( + {"id": k, "type": "function", "value": mod + "." + v.__name__} + ) elif isinstance(v, np.ndarray): nodes_store_lst.append({"id": k, "type": "input", "value": v.tolist()}) else: