Skip to content

Commit 6adab90

Browse files
committed
Add notebooks
1 parent 1b5c0fa commit 6adab90

File tree

5 files changed

+126
-4
lines changed

5 files changed

+126
-4
lines changed

.github/workflows/executorlib.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: executorlib
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_simple_to_executorlib.ipynb universal_simple_to_executorlib_out.ipynb -k "python3"
29+
papermill universal_qe_to_executorlib.ipynb universal_qe_to_executorlib_out.ipynb -k "python3"

python_workflow_definition/src/python_workflow_definition/executorlib.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44

55

66
from python_workflow_definition.shared import get_dict, get_list, get_kwargs, get_source_handles
7-
from python_workflow_definition.purepython import resort_total_lst, group_edges, get_value
7+
from python_workflow_definition.purepython import resort_total_lst, group_edges
8+
9+
10+
def _get_value(result_dict, nodes_new_dict, link_dict, exe):
11+
source, source_handle = link_dict["source"], link_dict["sourceHandle"]
12+
if source in result_dict.keys():
13+
result = result_dict[source]
14+
elif source in nodes_new_dict.keys():
15+
result = nodes_new_dict[source]
16+
else:
17+
raise KeyError()
18+
if source_handle is None:
19+
return result
20+
else:
21+
return exe.submit(getattr, result, source_handle)
822

923

1024
def load_workflow_json(file_name, exe):
@@ -30,7 +44,7 @@ def load_workflow_json(file_name, exe):
3044
node = nodes_new_dict[lst[0]]
3145
if isfunction(node):
3246
kwargs = {
33-
k: get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v)
47+
k: _get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v, exe=exe)
3448
for k, v in lst[1].items()
3549
}
3650
result_dict[lst[0]] = exe.submit(node, **kwargs)

python_workflow_definition/src/python_workflow_definition/purepython.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def group_edges(edges_lst):
3535
return total_lst
3636

3737

38-
def get_value(result_dict, nodes_new_dict, link_dict):
38+
def _get_value(result_dict, nodes_new_dict, link_dict):
3939
source, source_handle = link_dict["source"], link_dict["sourceHandle"]
4040
if source in result_dict.keys():
4141
result = result_dict[source]
@@ -72,7 +72,7 @@ def load_workflow_json(file_name):
7272
node = nodes_new_dict[lst[0]]
7373
if isfunction(node):
7474
kwargs = {
75-
k: get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v)
75+
k: _get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v)
7676
for k, v in lst[1].items()
7777
}
7878
result_dict[lst[0]] = node(**kwargs)

universal_qe_to_executorlib.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.12.8","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":5,"nbformat":4,"cells":[{"id":"ae0b5775-fb9d-4150-be79-d48dfb0b2cf4","cell_type":"code","source":"from executorlib import SingleNodeExecutor","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"b0f920a2-c646-485b-af0f-48251e061163","cell_type":"code","source":"from python_workflow_definition.executorlib import load_workflow_json","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"46559120-d58a-492f-b734-db27424b5659","cell_type":"code","source":"with SingleNodeExecutor() as exe:\n result = load_workflow_json(file_name=\"workflow_qe.json\", exe=exe).result()","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"b37f476d-b7f8-4400-8070-83f8f2eb8bf9","cell_type":"code","source":"result","metadata":{"trusted":true},"outputs":[],"execution_count":null},{"id":"336dfbea-7e5c-4950-a0b3-c027a2a8e935","cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"metadata": {
3+
"kernelspec": {
4+
"display_name": "Python 3 (ipykernel)",
5+
"language": "python",
6+
"name": "python3"
7+
},
8+
"language_info": {
9+
"name": "python",
10+
"version": "3.12.8",
11+
"mimetype": "text/x-python",
12+
"codemirror_mode": {
13+
"name": "ipython",
14+
"version": 3
15+
},
16+
"pygments_lexer": "ipython3",
17+
"nbconvert_exporter": "python",
18+
"file_extension": ".py"
19+
}
20+
},
21+
"nbformat_minor": 5,
22+
"nbformat": 4,
23+
"cells": [
24+
{
25+
"id": "ae0b5775-fb9d-4150-be79-d48dfb0b2cf4",
26+
"cell_type": "code",
27+
"source": "from executorlib import SingleNodeExecutor",
28+
"metadata": {
29+
"trusted": true
30+
},
31+
"outputs": [],
32+
"execution_count": null
33+
},
34+
{
35+
"id": "b0f920a2-c646-485b-af0f-48251e061163",
36+
"cell_type": "code",
37+
"source": "from python_workflow_definition.executorlib import load_workflow_json",
38+
"metadata": {
39+
"trusted": true
40+
},
41+
"outputs": [],
42+
"execution_count": null
43+
},
44+
{
45+
"id": "46559120-d58a-492f-b734-db27424b5659",
46+
"cell_type": "code",
47+
"source": [
48+
"with SingleNodeExecutor() as exe:\n",
49+
" result = load_workflow_json(file_name=\"workflow_simple.json\", exe=exe).result()"
50+
],
51+
"metadata": {
52+
"trusted": true
53+
},
54+
"outputs": [],
55+
"execution_count": null
56+
},
57+
{
58+
"id": "b37f476d-b7f8-4400-8070-83f8f2eb8bf9",
59+
"cell_type": "code",
60+
"source": "result",
61+
"metadata": {
62+
"trusted": true
63+
},
64+
"outputs": [],
65+
"execution_count": null
66+
},
67+
{
68+
"id": "336dfbea-7e5c-4950-a0b3-c027a2a8e935",
69+
"cell_type": "code",
70+
"source": "",
71+
"metadata": {
72+
"trusted": true
73+
},
74+
"outputs": [],
75+
"execution_count": null
76+
}
77+
]
78+
}

0 commit comments

Comments
 (0)