Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add notebooks
  • Loading branch information
jan-janssen committed Mar 15, 2025
commit 6adab90a05dcdd70ca1a5f47f0dc15cfe0b96e1d
29 changes: 29 additions & 0 deletions .github/workflows/executorlib.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: executorlib

on:
push:
branches: [ main ]
pull_request:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: conda-incubator/setup-miniconda@v3
with:
auto-update-conda: true
python-version: "3.12"
environment-file: environment.yml
auto-activate-base: false
- name: Tests
shell: bash -l {0}
run: |
pip install -e adis_tools
pip install -e python_workflow_definition
conda install -c conda-forge jupyter papermill
export ESPRESSO_PSEUDO=$(pwd)/espresso/pseudo
papermill universal_simple_to_executorlib.ipynb universal_simple_to_executorlib_out.ipynb -k "python3"
papermill universal_qe_to_executorlib.ipynb universal_qe_to_executorlib_out.ipynb -k "python3"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,21 @@


from python_workflow_definition.shared import get_dict, get_list, get_kwargs, get_source_handles
from python_workflow_definition.purepython import resort_total_lst, group_edges, get_value
from python_workflow_definition.purepython import resort_total_lst, group_edges


def _get_value(result_dict, nodes_new_dict, link_dict, exe):
source, source_handle = link_dict["source"], link_dict["sourceHandle"]
if source in result_dict.keys():
result = result_dict[source]
elif source in nodes_new_dict.keys():
result = nodes_new_dict[source]
else:
raise KeyError()
if source_handle is None:
return result
else:
return exe.submit(getattr, result, source_handle)


def load_workflow_json(file_name, exe):
Expand All @@ -30,7 +44,7 @@ def load_workflow_json(file_name, exe):
node = nodes_new_dict[lst[0]]
if isfunction(node):
kwargs = {
k: get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v)
k: _get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v, exe=exe)
for k, v in lst[1].items()
}
result_dict[lst[0]] = exe.submit(node, **kwargs)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def group_edges(edges_lst):
return total_lst


def get_value(result_dict, nodes_new_dict, link_dict):
def _get_value(result_dict, nodes_new_dict, link_dict):
source, source_handle = link_dict["source"], link_dict["sourceHandle"]
if source in result_dict.keys():
result = result_dict[source]
Expand Down Expand Up @@ -72,7 +72,7 @@ def load_workflow_json(file_name):
node = nodes_new_dict[lst[0]]
if isfunction(node):
kwargs = {
k: get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v)
k: _get_value(result_dict=result_dict, nodes_new_dict=nodes_new_dict, link_dict=v)
for k, v in lst[1].items()
}
result_dict[lst[0]] = node(**kwargs)
Expand Down
1 change: 1 addition & 0 deletions universal_qe_to_executorlib.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +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}]}
78 changes: 78 additions & 0 deletions universal_simple_to_executorlib.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"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_simple.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
}
]
}