Skip to content

Commit 623286f

Browse files
committed
Add jobflow test
1 parent 86cc4e9 commit 623286f

File tree

3 files changed

+121
-3
lines changed

3 files changed

+121
-3
lines changed

.github/workflows/jobflow.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: jobflow
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
- uses: conda-incubator/setup-miniconda@v3
16+
with:
17+
auto-update-conda: true
18+
python-version: "3.12"
19+
environment-file: environment.yml
20+
auto-activate-base: false
21+
- name: Tests
22+
shell: bash -l {0}
23+
run: |
24+
pip install -e aiida_qe_basic
25+
pip install -e adis_tools
26+
conda install -c conda-forge jupyter papermill
27+
export ESPRESSO_PSEUDO=$(pwd)/espresso/pseudo
28+
papermill universal_qe_to_jobflow.ipynb universal_qe_to_jobflow_out.ipynb -k "python3"

python_workflow_definition/src/python_workflow_definition/jobflow.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import json
2+
from importlib import import_module
13
from inspect import isfunction
24

35
from jobflow import job, Flow
@@ -186,6 +188,28 @@ def get_source_handles(edges_lst):
186188
}
187189

188190

189-
def find_root_node(nodes_dict, edges_lst):
190-
source_count_dict = {k: sum([ed["source"] == k for ed in edges_lst]) for k in nodes_dict.keys()}
191-
return min(source_count_dict, key=source_count_dict.get)
191+
def load_workflow_json(file_name):
192+
with open(file_name, "r") as f:
193+
content = json.load(f)
194+
195+
edges_new_lst = content["edges"]
196+
nodes_new_dict = {}
197+
for k, v in content["nodes"].items():
198+
if isinstance(v, str) and "." in v:
199+
p, m = v.rsplit('.', 1)
200+
mod = import_module(p)
201+
nodes_new_dict[int(k)] = getattr(mod, m)
202+
else:
203+
nodes_new_dict[int(k)] = v
204+
205+
source_handles_dict = get_source_handles(edges_lst=edges_new_lst)
206+
total_dict = group_edges(edges_lst=edges_new_lst)
207+
input_dict = get_input_dict(nodes_dict=nodes_new_dict)
208+
new_total_dict = resort_total_lst(total_dict=total_dict, nodes_dict=nodes_new_dict)
209+
task_lst = get_workflow(
210+
nodes_dict=nodes_new_dict,
211+
input_dict=input_dict,
212+
total_dict=new_total_dict,
213+
source_handles_dict=source_handles_dict,
214+
)
215+
return Flow(task_lst)

universal_qe_to_jobflow.ipynb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "eab942d5-f3c5-47e9-8b3b-a7a5a8481aed",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from jobflow.managers.local import run_locally"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "f6f83a43-4d91-4028-9661-a4700509be1b",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from python_workflow_definition.jobflow import load_workflow_json"
21+
]
22+
},
23+
{
24+
"cell_type": "code",
25+
"execution_count": null,
26+
"id": "285ca46b-19e3-4870-9fd1-0c8ddbcf819c",
27+
"metadata": {},
28+
"outputs": [],
29+
"source": [
30+
"flow = load_workflow_json(file_name=\"workflow_qe.json\")"
31+
]
32+
},
33+
{
34+
"cell_type": "code",
35+
"execution_count": null,
36+
"id": "663ac4b3-dee8-474f-a9bc-089a89bde011",
37+
"metadata": {},
38+
"outputs": [],
39+
"source": [
40+
"result = run_locally(flow)\n",
41+
"result"
42+
]
43+
}
44+
],
45+
"metadata": {
46+
"kernelspec": {
47+
"display_name": "Python 3 (ipykernel)",
48+
"language": "python",
49+
"name": "python3"
50+
},
51+
"language_info": {
52+
"codemirror_mode": {
53+
"name": "ipython",
54+
"version": 3
55+
},
56+
"file_extension": ".py",
57+
"mimetype": "text/x-python",
58+
"name": "python",
59+
"nbconvert_exporter": "python",
60+
"pygments_lexer": "ipython3",
61+
"version": "3.12.5"
62+
}
63+
},
64+
"nbformat": 4,
65+
"nbformat_minor": 5
66+
}

0 commit comments

Comments
 (0)