diff --git a/aiida_simple.ipynb b/aiida_simple.ipynb index 740f066..0cffc16 100644 --- a/aiida_simple.ipynb +++ b/aiida_simple.ipynb @@ -1 +1,278 @@ -{"metadata":{"kernelspec":{"display_name":"Python 3 (ipykernel)","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.12.8"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"# Simple Workflow with aiida","metadata":{}},{"cell_type":"markdown","source":"## Define workflow with aiida","metadata":{}},{"cell_type":"code","source":"from python_workflow_definition.aiida import write_workflow_json\n\nfrom aiida_workgraph import WorkGraph, task\nfrom aiida import orm, load_profile\nload_profile()\n\nworkflow_json_filename = \"aiida_simple.json\"","metadata":{"trusted":true},"outputs":[],"execution_count":1},{"cell_type":"code","source":"from simple_workflow import add_x_and_y as _add_x_and_y\nfrom simple_workflow import add_x_and_y_and_z","metadata":{"trusted":true},"outputs":[],"execution_count":2},{"cell_type":"code","source":"add_x_and_y = task(outputs=['x', 'y', 'z'])(_add_x_and_y)","metadata":{"trusted":true},"outputs":[],"execution_count":3},{"cell_type":"code","source":"wg = WorkGraph(\"wg-simple\")","metadata":{"trusted":true},"outputs":[],"execution_count":4},{"cell_type":"code","source":"add_x_and_y_task = wg.add_task(\n add_x_and_y,\n name=\"add_x_and_y\",\n x=orm.Int(1),\n y=orm.Int(2),\n)","metadata":{"trusted":true},"outputs":[],"execution_count":5},{"cell_type":"code","source":"add_x_and_y_and_z_task = wg.add_task(\n add_x_and_y_and_z,\n name=\"add_x_and_y_and_z\",\n x=add_x_and_y_task.outputs.x,\n y=add_x_and_y_task.outputs.y,\n z=add_x_and_y_task.outputs.z,\n)","metadata":{"trusted":true},"outputs":[],"execution_count":6},{"cell_type":"code","source":"write_workflow_json(wg=wg, file_name=workflow_json_filename)","metadata":{"trusted":true},"outputs":[{"data":{"text/plain":"{'nodes': {'0': 'simple_workflow.add_x_and_y',\n '1': 'simple_workflow.add_x_and_y_and_z',\n '2': 1,\n '3': 2},\n 'edges': [{'tn': 1, 'th': 'x', 'sn': 0, 'sh': 'x'},\n {'tn': 1, 'th': 'y', 'sn': 0, 'sh': 'y'},\n {'tn': 1, 'th': 'z', 'sn': 0, 'sh': 'z'},\n {'tn': 0, 'th': 'x', 'sn': 2, 'sh': None},\n {'tn': 0, 'th': 'y', 'sn': 3, 'sh': None}]}"},"execution_count":7,"metadata":{},"output_type":"execute_result"}],"execution_count":7},{"cell_type":"code","source":"!cat {workflow_json_filename}","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"{\n \"nodes\": {\n \"0\": \"simple_workflow.add_x_and_y\",\n \"1\": \"simple_workflow.add_x_and_y_and_z\",\n \"2\": 1,\n \"3\": 2\n },\n \"edges\": [\n {\n \"tn\": 1,\n \"th\": \"x\",\n \"sn\": 0,\n \"sh\": \"x\"\n },\n {\n \"tn\": 1,\n \"th\": \"y\",\n \"sn\": 0,\n \"sh\": \"y\"\n },\n {\n \"tn\": 1,\n \"th\": \"z\",\n \"sn\": 0,\n \"sh\": \"z\"\n },\n {\n \"tn\": 0,\n \"th\": \"x\",\n \"sn\": 2,\n \"sh\": null\n },\n {\n \"tn\": 0,\n \"th\": \"y\",\n \"sn\": 3,\n \"sh\": null\n }\n ]\n}"}],"execution_count":8},{"cell_type":"markdown","source":"## Load Workflow with jobflow","metadata":{}},{"cell_type":"code","source":"from python_workflow_definition.jobflow import load_workflow_json","metadata":{"trusted":true},"outputs":[{"name":"stderr","output_type":"stream","text":"/srv/conda/envs/notebook/lib/python3.12/site-packages/paramiko/pkey.py:82: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.\n \"cipher\": algorithms.TripleDES,\n/srv/conda/envs/notebook/lib/python3.12/site-packages/paramiko/transport.py:253: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.\n \"class\": algorithms.TripleDES,\n"}],"execution_count":9},{"cell_type":"code","source":"from jobflow.managers.local import run_locally","metadata":{"trusted":true},"outputs":[],"execution_count":10},{"cell_type":"code","source":"flow = load_workflow_json(file_name=workflow_json_filename)","metadata":{"trusted":true},"outputs":[],"execution_count":11},{"cell_type":"code","source":"result = run_locally(flow)\nresult","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"2025-04-02 14:36:37,425 INFO Started executing jobs locally\n2025-04-02 14:36:37,751 INFO Starting job - add_x_and_y (4bcb90c8-2c19-4981-a88e-56d5d24b5df9)\n2025-04-02 14:36:37,754 INFO Finished job - add_x_and_y (4bcb90c8-2c19-4981-a88e-56d5d24b5df9)\n2025-04-02 14:36:37,755 INFO Starting job - add_x_and_y_and_z (88bc90e5-09a0-443d-b24e-673cc6bc0819)\n2025-04-02 14:36:37,756 INFO Finished job - add_x_and_y_and_z (88bc90e5-09a0-443d-b24e-673cc6bc0819)\n2025-04-02 14:36:37,756 INFO Finished executing jobs locally\n"},{"data":{"text/plain":"{'4bcb90c8-2c19-4981-a88e-56d5d24b5df9': {1: Response(output={'x': 1, 'y': 2, 'z': 3}, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan'))},\n '88bc90e5-09a0-443d-b24e-673cc6bc0819': {1: Response(output=6, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan'))}}"},"execution_count":12,"metadata":{},"output_type":"execute_result"}],"execution_count":12},{"cell_type":"markdown","source":"## Load Workflow with pyiron_base","metadata":{}},{"cell_type":"code","source":"from pyiron_base import Project","metadata":{"trusted":true},"outputs":[],"execution_count":13},{"cell_type":"code","source":"from python_workflow_definition.pyiron_base import load_workflow_json","metadata":{"trusted":true},"outputs":[],"execution_count":14},{"cell_type":"code","source":"pr = Project(\"test\")\npr.remove_jobs(recursive=True, silently=True)","metadata":{"trusted":true},"outputs":[{"data":{"application/vnd.jupyter.widget-view+json":{"model_id":"278f490ab20c4eaf9d39a75a7ee5231d","version_major":2,"version_minor":0},"text/plain":"0it [00:00, ?it/s]"},"metadata":{},"output_type":"display_data"}],"execution_count":15},{"cell_type":"code","source":"delayed_object = load_workflow_json(project=pr, file_name=workflow_json_filename)\ndelayed_object.draw()","metadata":{"trusted":true},"outputs":[{"data":{"image/svg+xml":"\n\n\n\n\ncreate_function_job_988efa8422518ba29903b66c63607fb8\n\ncreate_function_job=<pyiron_base.project.delayed.DelayedObject object at 0x71606f71f740>\n\n\n\nx_b8003ea81f8e4a9bdbfd3b4eb1e68e2b\n\nx=<pyiron_base.project.delayed.DelayedObject object at 0x71606f6efa70>\n\n\n\nx_b8003ea81f8e4a9bdbfd3b4eb1e68e2b->create_function_job_988efa8422518ba29903b66c63607fb8\n\n\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce\n\nx=1\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->x_b8003ea81f8e4a9bdbfd3b4eb1e68e2b\n\n\n\n\n\ny_f60ae41b1c92823db71999ac596241ab\n\ny=<pyiron_base.project.delayed.DelayedObject object at 0x71606f71f6e0>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->y_f60ae41b1c92823db71999ac596241ab\n\n\n\n\n\nz_a926da40ec18154feb3f3bb147af8220\n\nz=<pyiron_base.project.delayed.DelayedObject object at 0x71606f71f2f0>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->z_a926da40ec18154feb3f3bb147af8220\n\n\n\n\n\ny_f60ae41b1c92823db71999ac596241ab->create_function_job_988efa8422518ba29903b66c63607fb8\n\n\n\n\n\nz_a926da40ec18154feb3f3bb147af8220->create_function_job_988efa8422518ba29903b66c63607fb8\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6\n\ny=2\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->x_b8003ea81f8e4a9bdbfd3b4eb1e68e2b\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->y_f60ae41b1c92823db71999ac596241ab\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->z_a926da40ec18154feb3f3bb147af8220\n\n\n\n\n","text/plain":""},"metadata":{},"output_type":"display_data"}],"execution_count":16},{"cell_type":"code","source":"delayed_object.pull()","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"The job add_x_and_y_68901482a2c5221cc845f828aabebd27 was saved and received the ID: 1\nThe job add_x_and_y_and_z_b671e81aaa4670d81d7eee509650af8d was saved and received the ID: 2\n"},{"data":{"text/plain":"6"},"execution_count":17,"metadata":{},"output_type":"execute_result"}],"execution_count":17}]} \ No newline at end of file +{ + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.8" + } + }, + "nbformat_minor": 4, + "nbformat": 4, + "cells": [ + { + "cell_type": "markdown", + "source": "# Simple Workflow with aiida", + "metadata": {} + }, + { + "cell_type": "markdown", + "source": "## Define workflow with aiida", + "metadata": {} + }, + { + "cell_type": "code", + "source": "from python_workflow_definition.aiida import write_workflow_json\n\nfrom aiida_workgraph import WorkGraph, task\nfrom aiida import orm, load_profile\nload_profile()\n\nworkflow_json_filename = \"aiida_simple.json\"", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 1 + }, + { + "cell_type": "code", + "source": [ + "from simple_workflow import add_x_and_y as _add_x_and_y\n", + "from simple_workflow import add_x_and_y_and_z as _add_x_and_y_and_z" + ], + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 2 + }, + { + "cell_type": "code", + "source": "wg = WorkGraph(\"wg-simple\")", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 4 + }, + { + "cell_type": "code", + "source": [ + "add_x_and_y_task = wg.add_task(\n", + " task(outputs=['x', 'y', 'z'])(_add_x_and_y),\n", + " name=\"add_x_and_y\",\n", + " x=orm.Int(1),\n", + " y=orm.Int(2),\n", + ")" + ], + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 5 + }, + { + "cell_type": "code", + "source": [ + "add_x_and_y_and_z_task = wg.add_task(\n", + " _add_x_and_y_and_z,\n", + " name=\"add_x_and_y_and_z\",\n", + " x=add_x_and_y_task.outputs.x,\n", + " y=add_x_and_y_task.outputs.y,\n", + " z=add_x_and_y_task.outputs.z,\n", + ")" + ], + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 6 + }, + { + "cell_type": "code", + "source": "write_workflow_json(wg=wg, file_name=workflow_json_filename)", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "data": { + "text/plain": "{'nodes': {'0': 'simple_workflow.add_x_and_y',\n '1': 'simple_workflow.add_x_and_y_and_z',\n '2': 1,\n '3': 2},\n 'edges': [{'tn': 1, 'th': 'x', 'sn': 0, 'sh': 'x'},\n {'tn': 1, 'th': 'y', 'sn': 0, 'sh': 'y'},\n {'tn': 1, 'th': 'z', 'sn': 0, 'sh': 'z'},\n {'tn': 0, 'th': 'x', 'sn': 2, 'sh': None},\n {'tn': 0, 'th': 'y', 'sn': 3, 'sh': None}]}" + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 7 + }, + { + "cell_type": "code", + "source": "!cat {workflow_json_filename}", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "{\n \"nodes\": {\n \"0\": \"simple_workflow.add_x_and_y\",\n \"1\": \"simple_workflow.add_x_and_y_and_z\",\n \"2\": 1,\n \"3\": 2\n },\n \"edges\": [\n {\n \"tn\": 1,\n \"th\": \"x\",\n \"sn\": 0,\n \"sh\": \"x\"\n },\n {\n \"tn\": 1,\n \"th\": \"y\",\n \"sn\": 0,\n \"sh\": \"y\"\n },\n {\n \"tn\": 1,\n \"th\": \"z\",\n \"sn\": 0,\n \"sh\": \"z\"\n },\n {\n \"tn\": 0,\n \"th\": \"x\",\n \"sn\": 2,\n \"sh\": null\n },\n {\n \"tn\": 0,\n \"th\": \"y\",\n \"sn\": 3,\n \"sh\": null\n }\n ]\n}" + } + ], + "execution_count": 8 + }, + { + "cell_type": "markdown", + "source": "## Load Workflow with jobflow", + "metadata": {} + }, + { + "cell_type": "code", + "source": "from python_workflow_definition.jobflow import load_workflow_json", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": "/srv/conda/envs/notebook/lib/python3.12/site-packages/paramiko/pkey.py:82: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.\n \"cipher\": algorithms.TripleDES,\n/srv/conda/envs/notebook/lib/python3.12/site-packages/paramiko/transport.py:253: CryptographyDeprecationWarning: TripleDES has been moved to cryptography.hazmat.decrepit.ciphers.algorithms.TripleDES and will be removed from cryptography.hazmat.primitives.ciphers.algorithms in 48.0.0.\n \"class\": algorithms.TripleDES,\n" + } + ], + "execution_count": 9 + }, + { + "cell_type": "code", + "source": "from jobflow.managers.local import run_locally", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 10 + }, + { + "cell_type": "code", + "source": "flow = load_workflow_json(file_name=workflow_json_filename)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 11 + }, + { + "cell_type": "code", + "source": "result = run_locally(flow)\nresult", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "2025-04-02 14:36:37,425 INFO Started executing jobs locally\n2025-04-02 14:36:37,751 INFO Starting job - add_x_and_y (4bcb90c8-2c19-4981-a88e-56d5d24b5df9)\n2025-04-02 14:36:37,754 INFO Finished job - add_x_and_y (4bcb90c8-2c19-4981-a88e-56d5d24b5df9)\n2025-04-02 14:36:37,755 INFO Starting job - add_x_and_y_and_z (88bc90e5-09a0-443d-b24e-673cc6bc0819)\n2025-04-02 14:36:37,756 INFO Finished job - add_x_and_y_and_z (88bc90e5-09a0-443d-b24e-673cc6bc0819)\n2025-04-02 14:36:37,756 INFO Finished executing jobs locally\n" + }, + { + "data": { + "text/plain": "{'4bcb90c8-2c19-4981-a88e-56d5d24b5df9': {1: Response(output={'x': 1, 'y': 2, 'z': 3}, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan'))},\n '88bc90e5-09a0-443d-b24e-673cc6bc0819': {1: Response(output=6, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan'))}}" + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 12 + }, + { + "cell_type": "markdown", + "source": "## Load Workflow with pyiron_base", + "metadata": {} + }, + { + "cell_type": "code", + "source": "from pyiron_base import Project", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 13 + }, + { + "cell_type": "code", + "source": "from python_workflow_definition.pyiron_base import load_workflow_json", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 14 + }, + { + "cell_type": "code", + "source": "pr = Project(\"test\")\npr.remove_jobs(recursive=True, silently=True)", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "278f490ab20c4eaf9d39a75a7ee5231d", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": "0it [00:00, ?it/s]" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "execution_count": 15 + }, + { + "cell_type": "code", + "source": "delayed_object = load_workflow_json(project=pr, file_name=workflow_json_filename)\ndelayed_object.draw()", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "data": { + "image/svg+xml": "\n\n\n\n\ncreate_function_job_988efa8422518ba29903b66c63607fb8\n\ncreate_function_job=<pyiron_base.project.delayed.DelayedObject object at 0x71606f71f740>\n\n\n\nx_b8003ea81f8e4a9bdbfd3b4eb1e68e2b\n\nx=<pyiron_base.project.delayed.DelayedObject object at 0x71606f6efa70>\n\n\n\nx_b8003ea81f8e4a9bdbfd3b4eb1e68e2b->create_function_job_988efa8422518ba29903b66c63607fb8\n\n\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce\n\nx=1\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->x_b8003ea81f8e4a9bdbfd3b4eb1e68e2b\n\n\n\n\n\ny_f60ae41b1c92823db71999ac596241ab\n\ny=<pyiron_base.project.delayed.DelayedObject object at 0x71606f71f6e0>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->y_f60ae41b1c92823db71999ac596241ab\n\n\n\n\n\nz_a926da40ec18154feb3f3bb147af8220\n\nz=<pyiron_base.project.delayed.DelayedObject object at 0x71606f71f2f0>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->z_a926da40ec18154feb3f3bb147af8220\n\n\n\n\n\ny_f60ae41b1c92823db71999ac596241ab->create_function_job_988efa8422518ba29903b66c63607fb8\n\n\n\n\n\nz_a926da40ec18154feb3f3bb147af8220->create_function_job_988efa8422518ba29903b66c63607fb8\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6\n\ny=2\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->x_b8003ea81f8e4a9bdbfd3b4eb1e68e2b\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->y_f60ae41b1c92823db71999ac596241ab\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->z_a926da40ec18154feb3f3bb147af8220\n\n\n\n\n", + "text/plain": "" + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "execution_count": 16 + }, + { + "cell_type": "code", + "source": "delayed_object.pull()", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "The job add_x_and_y_68901482a2c5221cc845f828aabebd27 was saved and received the ID: 1\nThe job add_x_and_y_and_z_b671e81aaa4670d81d7eee509650af8d was saved and received the ID: 2\n" + }, + { + "data": { + "text/plain": "6" + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "execution_count": 17 + } + ] +}