Skip to content

Commit df41384

Browse files
committed
Add universal_qe_to_aiida
1 parent 18ee6f2 commit df41384

File tree

2 files changed

+121
-1
lines changed

2 files changed

+121
-1
lines changed

python_workflow_definition/src/python_workflow_definition/aiida.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,15 @@ def write_workflow_json(wg):
5656

5757

5858
def load_workflow_json(filename):
59+
5960
with open(filename) as f:
6061
data = json.load(f)
6162

6263
wg = WorkGraph()
6364
task_name_mapping = {}
6465
# add tasks
66+
name_counter = {}
67+
6568
for name, identifier in data["nodes"].items():
6669
# if isinstance(identifier, str) and identifier in func_mapping:
6770
if isinstance(identifier, str) and "." in identifier:
@@ -71,12 +74,23 @@ def load_workflow_json(filename):
7174
func = task.pythonjob()(_func)
7275
# func = func_mapping[identifier]
7376
# I use the register_pickle_by_value, because the function is defined in a local file
74-
wg.add_task(func, register_pickle_by_value=True, name=m)
77+
try:
78+
wg.add_task(func, register_pickle_by_value=True, name=m)
79+
except ValueError:
80+
if m in name_counter:
81+
name_counter[m] += 1
82+
else:
83+
name_counter[m] = 0
84+
name_ = f"{m}_{name_counter[m]}"
85+
86+
wg.add_task(func, register_pickle_by_value=True, name=name_)
87+
7588
# Remove the default result output, because we will add the outputs later from the data in the link
7689
del wg.tasks[-1].outputs["result"]
7790
else:
7891
# data task
7992
wg.add_task(pickle_node, value=identifier, name=name)
93+
8094
task_name_mapping[name] = wg.tasks[-1].name
8195
# add links
8296
for link in data["edges"]:

universal_qe_to_aiida.ipynb

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 1,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"\n",
10+
"from python_workflow_definition.aiida import load_workflow_json"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": 2,
16+
"metadata": {},
17+
"outputs": [
18+
{
19+
"name": "stdout",
20+
"output_type": "stream",
21+
"text": [
22+
"outputs [{'identifier': 'workgraph.any', 'name': 'result'}]\n",
23+
"outputs [{'identifier': 'workgraph.any', 'name': 'result'}]\n",
24+
"outputs [{'identifier': 'workgraph.any', 'name': 'result'}]\n",
25+
"outputs [{'identifier': 'workgraph.any', 'name': 'result'}]\n",
26+
"outputs None\n",
27+
"outputs None\n",
28+
"outputs None\n",
29+
"outputs None\n",
30+
"outputs [{'identifier': 'workgraph.any', 'name': 'result'}]\n",
31+
"outputs None\n",
32+
"outputs None\n",
33+
"outputs None\n",
34+
"outputs None\n",
35+
"outputs None\n",
36+
"outputs None\n",
37+
"outputs None\n",
38+
"outputs None\n",
39+
"outputs None\n",
40+
"outputs None\n",
41+
"outputs None\n",
42+
"outputs [{'identifier': 'workgraph.any', 'name': 'result'}]\n"
43+
]
44+
}
45+
],
46+
"source": [
47+
"workgraph = load_workflow_json(filename='workflow_qe.json')"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": 3,
53+
"metadata": {},
54+
"outputs": [
55+
{
56+
"data": {
57+
"application/vnd.jupyter.widget-view+json": {
58+
"model_id": "81c4d0a6e21042c7b82ccca0fdef201f",
59+
"version_major": 2,
60+
"version_minor": 1
61+
},
62+
"text/plain": [
63+
"NodeGraphWidget(settings={'minimap': True}, style={'width': '90%', 'height': '600px'}, value={'name': 'WorkGra…"
64+
]
65+
},
66+
"execution_count": 3,
67+
"metadata": {},
68+
"output_type": "execute_result"
69+
}
70+
],
71+
"source": [
72+
"\n",
73+
"# TODO: Create inputs rather than tasks out of data nodes\n",
74+
"workgraph"
75+
]
76+
},
77+
{
78+
"cell_type": "code",
79+
"execution_count": null,
80+
"metadata": {},
81+
"outputs": [],
82+
"source": []
83+
}
84+
],
85+
"metadata": {
86+
"kernelspec": {
87+
"display_name": "ADIS",
88+
"language": "python",
89+
"name": "python3"
90+
},
91+
"language_info": {
92+
"codemirror_mode": {
93+
"name": "ipython",
94+
"version": 3
95+
},
96+
"file_extension": ".py",
97+
"mimetype": "text/x-python",
98+
"name": "python",
99+
"nbconvert_exporter": "python",
100+
"pygments_lexer": "ipython3",
101+
"version": "3.10.12"
102+
}
103+
},
104+
"nbformat": 4,
105+
"nbformat_minor": 2
106+
}

0 commit comments

Comments
 (0)