Skip to content

Always define type in node definition #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions example_workflows/arithmetic/workflow.json
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
14 changes: 7 additions & 7 deletions example_workflows/nfdi/workflow.json
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
64 changes: 32 additions & 32 deletions example_workflows/quantum_espresso/workflow.json
Original file line number Diff line number Diff line change
@@ -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},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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, "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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,13 @@ 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)
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
}
Loading