Skip to content

Commit cafaed0

Browse files
authored
Add jobflow test (#3)
* Add jobflow test * fixes * fix import * update jupyter notebook
1 parent 2e1497c commit cafaed0

File tree

4 files changed

+60
-3
lines changed

4 files changed

+60
-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 adis_tools
25+
pip install -e python_workflow_definition
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: 29 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,30 @@ 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+
if p == "python_workflow_definition.pyiron_base":
201+
p = "python_workflow_definition.jobflow"
202+
mod = import_module(p)
203+
nodes_new_dict[int(k)] = getattr(mod, m)
204+
else:
205+
nodes_new_dict[int(k)] = v
206+
207+
source_handles_dict = get_source_handles(edges_lst=edges_new_lst)
208+
total_dict = group_edges(edges_lst=edges_new_lst)
209+
input_dict = get_input_dict(nodes_dict=nodes_new_dict)
210+
new_total_dict = resort_total_lst(total_dict=total_dict, nodes_dict=nodes_new_dict)
211+
task_lst = get_workflow(
212+
nodes_dict=nodes_new_dict,
213+
input_dict=input_dict,
214+
total_dict=new_total_dict,
215+
source_handles_dict=source_handles_dict,
216+
)
217+
return Flow(task_lst)

python_workflow_definition/src/python_workflow_definition/pyiron_base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ def load_workflow_json(project, file_name):
199199
for k, v in content["nodes"].items():
200200
if isinstance(v, str) and "." in v:
201201
p, m = v.rsplit('.', 1)
202+
if p == "python_workflow_definition.jobflow":
203+
p = "python_workflow_definition.pyiron_base"
202204
mod = import_module(p)
203205
nodes_new_dict[int(k)] = getattr(mod, m)
204206
else:

universal_qe_to_jobflow.ipynb

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

0 commit comments

Comments
 (0)