Skip to content

Commit d1a9781

Browse files
authored
Export from pyiron_base to jobflow (#5)
* Export from pyiron_base to jobflow * convert to list * From jobflow to pyiron_base * Convert from jobflow to pyiron_base
1 parent cafaed0 commit d1a9781

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

.github/workflows/jobflow.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,5 @@ jobs:
2525
pip install -e python_workflow_definition
2626
conda install -c conda-forge jupyter papermill
2727
export ESPRESSO_PSEUDO=$(pwd)/espresso/pseudo
28-
papermill universal_qe_to_jobflow.ipynb universal_qe_to_jobflow_out.ipynb -k "python3"
28+
papermill universal_qe_to_jobflow.ipynb universal_qe_to_jobflow_out.ipynb -k "python3"
29+
papermill jobflow_to_pyiron_base.ipynb jobflow_to_pyiron_base_out.ipynb -k "python3"

jobflow_to_pyiron_base.ipynb

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

python_workflow_definition/src/python_workflow_definition/jobflow.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from importlib import import_module
33
from inspect import isfunction
44

5+
import numpy as np
56
from jobflow import job, Flow
67

78

@@ -215,3 +216,26 @@ def load_workflow_json(file_name):
215216
source_handles_dict=source_handles_dict,
216217
)
217218
return Flow(task_lst)
219+
220+
221+
def write_workflow_json(flow, file_name="workflow.json"):
222+
flow_dict = flow.as_dict()
223+
function_dict = get_function_dict(flow=flow)
224+
nodes_dict, nodes_mapping_dict = get_nodes_dict(function_dict=function_dict)
225+
edges_lst, nodes_dict = get_edges_and_extend_nodes(
226+
flow_dict=flow_dict,
227+
nodes_mapping_dict=nodes_mapping_dict,
228+
nodes_dict=nodes_dict,
229+
)
230+
231+
nodes_store_dict = {}
232+
for k, v in nodes_dict.items():
233+
if isfunction(v):
234+
nodes_store_dict[k] = v.__module__ + "." + v.__name__
235+
elif isinstance(v, np.ndarray):
236+
nodes_store_dict[k] = v.tolist()
237+
else:
238+
nodes_store_dict[k] = v
239+
240+
with open(file_name, "w") as f:
241+
json.dump({"nodes": nodes_store_dict, "edges": edges_lst}, f)

python_workflow_definition/src/python_workflow_definition/pyiron_base.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import json
21
from importlib import import_module
2+
from inspect import isfunction
3+
import json
34

5+
import numpy as np
46
from pyiron_base import job
57
from pyiron_base.project.delayed import DelayedObject
68

@@ -216,3 +218,24 @@ def load_workflow_json(project, file_name):
216218
pyiron_project=project,
217219
)
218220
return delayed_object_dict[list(delayed_object_dict.keys())[-1]]
221+
222+
223+
def write_workflow_json(delayed_object, file_name="workflow.json"):
224+
nodes_dict, edges_lst = delayed_object.get_graph()
225+
nodes_dict, edges_lst = remove_server_obj(nodes_dict=nodes_dict, edges_lst=edges_lst)
226+
delayed_object_updated_dict, match_dict = get_unique_objects(nodes_dict=nodes_dict, edges_lst=edges_lst)
227+
connection_dict, lookup_dict = get_connection_dict(delayed_object_updated_dict=delayed_object_updated_dict, match_dict=match_dict)
228+
nodes_new_dict = get_nodes(connection_dict=connection_dict, delayed_object_updated_dict=delayed_object_updated_dict)
229+
edges_new_lst = get_edges_dict(edges_lst=edges_lst, nodes_dict=nodes_dict, connection_dict=connection_dict, lookup_dict=lookup_dict)
230+
231+
nodes_store_dict = {}
232+
for k, v in nodes_new_dict.items():
233+
if isfunction(v):
234+
nodes_store_dict[k] = v.__module__ + "." + v.__name__
235+
elif isinstance(v, np.ndarray):
236+
nodes_store_dict[k] = v.tolist()
237+
else:
238+
nodes_store_dict[k] = v
239+
240+
with open(file_name, "w") as f:
241+
json.dump({"nodes": nodes_store_dict, "edges": edges_new_lst}, f)

0 commit comments

Comments
 (0)