diff --git a/jobflow_to_pyiron_base_simple.ipynb b/jobflow_to_pyiron_base_simple.ipynb index 3dd58b4..0760b77 100644 --- a/jobflow_to_pyiron_base_simple.ipynb +++ b/jobflow_to_pyiron_base_simple.ipynb @@ -1 +1,207 @@ -{"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":"c9e32d6d-5a26-43b3-8455-fae305761a5d","cell_type":"code","source":"import numpy as np","metadata":{"trusted":true},"outputs":[],"execution_count":1},{"id":"000bbd4a-f53c-4eea-9d85-76f0aa2ca10b","cell_type":"code","source":"from jobflow import job, Flow","metadata":{"trusted":true},"outputs":[],"execution_count":2},{"id":"b4a78447-e87c-4fb4-8d17-d9a280eb7254","cell_type":"code","source":"from pyiron_base import Project","metadata":{"trusted":true},"outputs":[],"execution_count":3},{"id":"06c2bd9e-b2ac-4b88-9158-fa37331c3418","cell_type":"code","source":"from python_workflow_definition.jobflow import write_workflow_json","metadata":{"trusted":true},"outputs":[],"execution_count":4},{"id":"fb6dbdaa-8cab-48b2-8307-448003eca3f5","cell_type":"code","source":"from python_workflow_definition.pyiron_base import load_workflow_json","metadata":{"trusted":true},"outputs":[],"execution_count":5},{"id":"fb847d49-7bf9-4839-9b99-c116d1b0e9ee","cell_type":"code","source":"from simple_workflow import (\n add_x_and_y as _add_x_and_y, \n add_x_and_y_and_z as _add_x_and_y_and_z,\n)","metadata":{"trusted":true},"outputs":[],"execution_count":6},{"id":"07598344-0f75-433b-8902-bea21a42088c","cell_type":"code","source":"add_x_and_y = job(_add_x_and_y, data=[\"x\", \"y\", \"z\"])\nadd_x_and_y_and_z = job(_add_x_and_y_and_z)","metadata":{"trusted":true},"outputs":[],"execution_count":7},{"id":"ecef1ed5-a8d3-48c3-9e01-4a40e55c1153","cell_type":"code","source":"obj = add_x_and_y(x=1, y=2)","metadata":{"trusted":true},"outputs":[],"execution_count":8},{"id":"2b88a30a-e26b-4802-89b7-79ca08cc0af9","cell_type":"code","source":"w = add_x_and_y_and_z(x=obj.output.x, y=obj.output.y, z=obj.output.z)","metadata":{"trusted":true},"outputs":[],"execution_count":9},{"id":"a5e5ca63-2906-47c9-bac6-adebf8643cba","cell_type":"code","source":"flow = Flow([obj, w])","metadata":{"trusted":true},"outputs":[],"execution_count":10},{"id":"e464da97-16a1-4772-9a07-0a47f152781d","cell_type":"code","source":"write_workflow_json(flow=flow, file_name=\"workflow_jobflow.json\")","metadata":{"trusted":true},"outputs":[],"execution_count":11},{"id":"bca646b2-0a9a-4271-966a-e5903a8c9031","cell_type":"code","source":"!cat workflow_jobflow.json","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"{\"nodes\": {\"0\": \"simple_workflow.add_x_and_y\", \"1\": \"simple_workflow.add_x_and_y_and_z\", \"2\": 1, \"3\": 2}, \"edges\": [{\"target\": 0, \"targetHandle\": \"x\", \"source\": 2, \"sourceHandle\": null}, {\"target\": 0, \"targetHandle\": \"y\", \"source\": 3, \"sourceHandle\": null}, {\"target\": 1, \"targetHandle\": \"x\", \"source\": 0, \"sourceHandle\": \"x\"}, {\"target\": 1, \"targetHandle\": \"y\", \"source\": 0, \"sourceHandle\": \"y\"}, {\"target\": 1, \"targetHandle\": \"z\", \"source\": 0, \"sourceHandle\": \"z\"}]}"}],"execution_count":12},{"id":"f45684a8-2613-415a-ab0a-5cb2bafaffea","cell_type":"code","source":"pr = Project(\"test\")\npr.remove_jobs(recursive=True, silently=True)","metadata":{"trusted":true},"outputs":[{"output_type":"display_data","data":{"text/plain":"0it [00:00, ?it/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"1dc9fa2d8f8044c8977e1ad0669596b5"}},"metadata":{}}],"execution_count":13},{"id":"8f2a621d-b533-4ddd-8bcd-c22db2f922ec","cell_type":"code","source":"delayed_object = load_workflow_json(project=pr, file_name=\"workflow_jobflow.json\")\ndelayed_object.draw()","metadata":{"trusted":true},"outputs":[{"output_type":"display_data","data":{"text/plain":"","image/svg+xml":"\n\n\n\n\ncreate_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\ncreate_function_job=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef5bc560>\n\n\n\nx_7bbe883cf8e84e98be86ef51b3b4b3f0\n\nx=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef56ffb0>\n\n\n\nx_7bbe883cf8e84e98be86ef51b3b4b3f0->create_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\n\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce\n\nx=1\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->x_7bbe883cf8e84e98be86ef51b3b4b3f0\n\n\n\n\n\ny_8ac62ebe82912d404811d7b4f684816a\n\ny=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef5bc200>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->y_8ac62ebe82912d404811d7b4f684816a\n\n\n\n\n\nz_5e7b48ebebaa407e4bfec5ab40e64557\n\nz=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef5bc170>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->z_5e7b48ebebaa407e4bfec5ab40e64557\n\n\n\n\n\ny_8ac62ebe82912d404811d7b4f684816a->create_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\n\n\n\n\nz_5e7b48ebebaa407e4bfec5ab40e64557->create_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6\n\ny=2\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->x_7bbe883cf8e84e98be86ef51b3b4b3f0\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->y_8ac62ebe82912d404811d7b4f684816a\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->z_5e7b48ebebaa407e4bfec5ab40e64557\n\n\n\n\n"},"metadata":{}}],"execution_count":14},{"id":"cf80267d-c2b0-4236-bf1d-a57596985fc1","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"},{"execution_count":15,"output_type":"execute_result","data":{"text/plain":"6"},"metadata":{}}],"execution_count":15}]} \ No newline at end of file +{ + "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": "000bbd4a-f53c-4eea-9d85-76f0aa2ca10b", + "cell_type": "code", + "source": "from jobflow import job, Flow", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 2 + }, + { + "id": "b4a78447-e87c-4fb4-8d17-d9a280eb7254", + "cell_type": "code", + "source": "from pyiron_base import Project", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 3 + }, + { + "id": "06c2bd9e-b2ac-4b88-9158-fa37331c3418", + "cell_type": "code", + "source": "from python_workflow_definition.jobflow import write_workflow_json", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 4 + }, + { + "id": "fb6dbdaa-8cab-48b2-8307-448003eca3f5", + "cell_type": "code", + "source": "from python_workflow_definition.pyiron_base import load_workflow_json", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 5 + }, + { + "id": "fb847d49-7bf9-4839-9b99-c116d1b0e9ee", + "cell_type": "code", + "source": "from simple_workflow import (\n add_x_and_y as _add_x_and_y, \n add_x_and_y_and_z as _add_x_and_y_and_z,\n)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 6 + }, + { + "id": "07598344-0f75-433b-8902-bea21a42088c", + "cell_type": "code", + "source": "add_x_and_y = job(_add_x_and_y, data=[\"x\", \"y\", \"z\"])\nadd_x_and_y_and_z = job(_add_x_and_y_and_z)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 7 + }, + { + "id": "ecef1ed5-a8d3-48c3-9e01-4a40e55c1153", + "cell_type": "code", + "source": "obj = add_x_and_y(x=1, y=2)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 8 + }, + { + "id": "2b88a30a-e26b-4802-89b7-79ca08cc0af9", + "cell_type": "code", + "source": "w = add_x_and_y_and_z(x=obj.output.x, y=obj.output.y, z=obj.output.z)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 9 + }, + { + "id": "a5e5ca63-2906-47c9-bac6-adebf8643cba", + "cell_type": "code", + "source": "flow = Flow([obj, w])", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 10 + }, + { + "id": "e464da97-16a1-4772-9a07-0a47f152781d", + "cell_type": "code", + "source": "write_workflow_json(flow=flow, file_name=\"workflow_jobflow.json\")", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 11 + }, + { + "id": "bca646b2-0a9a-4271-966a-e5903a8c9031", + "cell_type": "code", + "source": "!cat workflow_jobflow.json", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "{\"nodes\": {\"0\": \"simple_workflow.add_x_and_y\", \"1\": \"simple_workflow.add_x_and_y_and_z\", \"2\": 1, \"3\": 2}, \"edges\": [{\"target\": 0, \"targetHandle\": \"x\", \"source\": 2, \"sourceHandle\": null}, {\"target\": 0, \"targetHandle\": \"y\", \"source\": 3, \"sourceHandle\": null}, {\"target\": 1, \"targetHandle\": \"x\", \"source\": 0, \"sourceHandle\": \"x\"}, {\"target\": 1, \"targetHandle\": \"y\", \"source\": 0, \"sourceHandle\": \"y\"}, {\"target\": 1, \"targetHandle\": \"z\", \"source\": 0, \"sourceHandle\": \"z\"}]}" + } + ], + "execution_count": 12 + }, + { + "id": "f45684a8-2613-415a-ab0a-5cb2bafaffea", + "cell_type": "code", + "source": "pr = Project(\"test\")\npr.remove_jobs(recursive=True, silently=True)", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": "0it [00:00, ?it/s]", + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "1dc9fa2d8f8044c8977e1ad0669596b5" + } + }, + "metadata": {} + } + ], + "execution_count": 13 + }, + { + "id": "8f2a621d-b533-4ddd-8bcd-c22db2f922ec", + "cell_type": "code", + "source": "delayed_object = load_workflow_json(project=pr, file_name=\"workflow_jobflow.json\")\ndelayed_object.draw()", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": "", + "image/svg+xml": "\n\n\n\n\ncreate_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\ncreate_function_job=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef5bc560>\n\n\n\nx_7bbe883cf8e84e98be86ef51b3b4b3f0\n\nx=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef56ffb0>\n\n\n\nx_7bbe883cf8e84e98be86ef51b3b4b3f0->create_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\n\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce\n\nx=1\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->x_7bbe883cf8e84e98be86ef51b3b4b3f0\n\n\n\n\n\ny_8ac62ebe82912d404811d7b4f684816a\n\ny=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef5bc200>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->y_8ac62ebe82912d404811d7b4f684816a\n\n\n\n\n\nz_5e7b48ebebaa407e4bfec5ab40e64557\n\nz=<pyiron_base.project.delayed.DelayedObject object at 0x7e21ef5bc170>\n\n\n\nx_1d847da32ecaabf6731c38f798c3d4ce->z_5e7b48ebebaa407e4bfec5ab40e64557\n\n\n\n\n\ny_8ac62ebe82912d404811d7b4f684816a->create_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\n\n\n\n\nz_5e7b48ebebaa407e4bfec5ab40e64557->create_function_job_2c457c823cb47e0ef9ae0df5b2d1fb40\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6\n\ny=2\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->x_7bbe883cf8e84e98be86ef51b3b4b3f0\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->y_8ac62ebe82912d404811d7b4f684816a\n\n\n\n\n\ny_a9ec4f5f33f0d64e74ed5d9900bceac6->z_5e7b48ebebaa407e4bfec5ab40e64557\n\n\n\n\n" + }, + "metadata": {} + } + ], + "execution_count": 14 + }, + { + "id": "cf80267d-c2b0-4236-bf1d-a57596985fc1", + "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" + }, + { + "execution_count": 15, + "output_type": "execute_result", + "data": { + "text/plain": "6" + }, + "metadata": {} + } + ], + "execution_count": 15 + } + ] +} diff --git a/pyiron_base_to_jobflow_qe.ipynb b/pyiron_base_to_jobflow_qe.ipynb index bf45cb0..1d6e91a 100644 --- a/pyiron_base_to_jobflow_qe.ipynb +++ b/pyiron_base_to_jobflow_qe.ipynb @@ -41,16 +41,6 @@ "outputs": [], "execution_count": 2 }, - { - "id": "78ca455d-d0b8-4814-81fa-6039f6adb4c4", - "cell_type": "code", - "source": "from python_workflow_definition.jobflow import load_workflow_json", - "metadata": { - "trusted": true - }, - "outputs": [], - "execution_count": 3 - }, { "id": "14d87342-706e-4120-99e6-b5363f724601", "cell_type": "code", diff --git a/pyiron_base_to_jobflow_simple.ipynb b/pyiron_base_to_jobflow_simple.ipynb index 81d939b..cb458cf 100644 --- a/pyiron_base_to_jobflow_simple.ipynb +++ b/pyiron_base_to_jobflow_simple.ipynb @@ -1 +1,198 @@ -{"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":5,"nbformat":4,"cells":[{"id":"28d69730-d8cb-4174-ae3f-aa70da8a8108","cell_type":"code","source":"import numpy as np","metadata":{"trusted":true},"outputs":[],"execution_count":1},{"id":"cacaa0a8-27c8-44de-9e37-69cd3d13408b","cell_type":"code","source":"from jobflow.managers.local import run_locally","metadata":{"trusted":true},"outputs":[],"execution_count":2},{"id":"78ca455d-d0b8-4814-81fa-6039f6adb4c4","cell_type":"code","source":"from python_workflow_definition.jobflow import load_workflow_json","metadata":{"trusted":true},"outputs":[],"execution_count":3},{"id":"14d87342-706e-4120-99e6-b5363f724601","cell_type":"code","source":"from pyiron_base import Project, job","metadata":{"trusted":true},"outputs":[],"execution_count":4},{"id":"a2ed2608-9e1b-4a81-81cb-5079573ea2d1","cell_type":"code","source":"from python_workflow_definition.pyiron_base import write_workflow_json","metadata":{"trusted":true},"outputs":[],"execution_count":5},{"id":"444347b0-d5ba-4903-b8d4-a9d7fc35d268","cell_type":"code","source":"from python_workflow_definition.jobflow import load_workflow_json","metadata":{"trusted":true},"outputs":[],"execution_count":6},{"id":"b75c2530-9b89-4185-838f-a17e517fa68f","cell_type":"code","source":"from simple_workflow import (\n add_x_and_y as _add_x_and_y, \n add_x_and_y_and_z as _add_x_and_y_and_z,\n)","metadata":{"trusted":true},"outputs":[],"execution_count":7},{"id":"208ddfb8-dfda-4227-aa1f-3dc29e34ea82","cell_type":"code","source":"add_x_and_y = job(_add_x_and_y, output_key_lst=[\"x\", \"y\", \"z\"])\nadd_x_and_y_and_z = job(_add_x_and_y_and_z)","metadata":{"trusted":true},"outputs":[],"execution_count":8},{"id":"13debfcd-362d-4fd0-a91f-5ab33632fceb","cell_type":"code","source":"pr = Project(\"test\")\npr.remove_jobs(recursive=True, silently=True)","metadata":{"trusted":true},"outputs":[{"output_type":"display_data","data":{"text/plain":"0it [00:00, ?it/s]","application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"1bcb58b981944c688403d1eaca7b3598"}},"metadata":{}}],"execution_count":9},{"id":"1f1cb12f-4001-478d-8ea0-b369f4f2981a","cell_type":"code","source":"obj = add_x_and_y(x=1, y=2, pyiron_project=pr)","metadata":{"trusted":true},"outputs":[],"execution_count":10},{"id":"4140f07b-af54-41ef-be22-df6b5b53bf95","cell_type":"code","source":"w = add_x_and_y_and_z(x=obj.output.x, y=obj.output.y, z=obj.output.z, pyiron_project=pr)","metadata":{"trusted":true},"outputs":[],"execution_count":11},{"id":"52646121-335f-48e6-bd5e-a1d69d00e8bc","cell_type":"code","source":"write_workflow_json(delayed_object=w, file_name=\"workflow_pyiron.json\")","metadata":{"trusted":true},"outputs":[],"execution_count":12},{"id":"72c8e6e6-8e60-4a4f-81f3-968b4b5f36ee","cell_type":"code","source":"!cat workflow_pyiron.json","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"{\"nodes\": {\"0\": \"simple_workflow.add_x_and_y_and_z\", \"1\": \"simple_workflow.add_x_and_y\", \"2\": 1, \"3\": 2}, \"edges\": [{\"target\": 0, \"targetHandle\": \"x\", \"source\": 1, \"sourceHandle\": \"x\"}, {\"target\": 1, \"targetHandle\": \"x\", \"source\": 2, \"sourceHandle\": null}, {\"target\": 1, \"targetHandle\": \"y\", \"source\": 3, \"sourceHandle\": null}, {\"target\": 0, \"targetHandle\": \"y\", \"source\": 1, \"sourceHandle\": \"y\"}, {\"target\": 0, \"targetHandle\": \"z\", \"source\": 1, \"sourceHandle\": \"z\"}]}"}],"execution_count":13},{"id":"32fcd4b2-4f0a-442d-b098-827672823796","cell_type":"code","source":"flow = load_workflow_json(file_name=\"workflow_pyiron.json\")","metadata":{"trusted":true},"outputs":[],"execution_count":14},{"id":"a80b59bd-fe30-49c6-92ca-35ef2d77a6fb","cell_type":"code","source":"result = run_locally(flow)\nresult","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"2025-03-13 06:29:36,854 INFO Started executing jobs locally\n2025-03-13 06:29:37,166 INFO Starting job - add_x_and_y (75f3eb14-326b-46bb-848d-ef501b2d43b4)\n2025-03-13 06:29:37,169 INFO Finished job - add_x_and_y (75f3eb14-326b-46bb-848d-ef501b2d43b4)\n2025-03-13 06:29:37,170 INFO Starting job - add_x_and_y_and_z (609c1659-ec60-4211-8996-670770e4b36c)\n2025-03-13 06:29:37,172 INFO Finished job - add_x_and_y_and_z (609c1659-ec60-4211-8996-670770e4b36c)\n2025-03-13 06:29:37,172 INFO Finished executing jobs locally\n"},{"execution_count":15,"output_type":"execute_result","data":{"text/plain":"{'75f3eb14-326b-46bb-848d-ef501b2d43b4': {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 '609c1659-ec60-4211-8996-670770e4b36c': {1: Response(output=6, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan'))}}"},"metadata":{}}],"execution_count":15},{"id":"6a8d1a17-3698-4873-8937-616e9e7dc7ca","cell_type":"code","source":"","metadata":{"trusted":true},"outputs":[],"execution_count":null}]} \ 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": 5, + "nbformat": 4, + "cells": [ + { + "id": "cacaa0a8-27c8-44de-9e37-69cd3d13408b", + "cell_type": "code", + "source": "from jobflow.managers.local import run_locally", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 2 + }, + { + "id": "14d87342-706e-4120-99e6-b5363f724601", + "cell_type": "code", + "source": "from pyiron_base import Project, job", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 4 + }, + { + "id": "a2ed2608-9e1b-4a81-81cb-5079573ea2d1", + "cell_type": "code", + "source": "from python_workflow_definition.pyiron_base import write_workflow_json", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 5 + }, + { + "id": "444347b0-d5ba-4903-b8d4-a9d7fc35d268", + "cell_type": "code", + "source": "from python_workflow_definition.jobflow import load_workflow_json", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 6 + }, + { + "id": "b75c2530-9b89-4185-838f-a17e517fa68f", + "cell_type": "code", + "source": "from simple_workflow import (\n add_x_and_y as _add_x_and_y, \n add_x_and_y_and_z as _add_x_and_y_and_z,\n)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 7 + }, + { + "id": "208ddfb8-dfda-4227-aa1f-3dc29e34ea82", + "cell_type": "code", + "source": "add_x_and_y = job(_add_x_and_y, output_key_lst=[\"x\", \"y\", \"z\"])\nadd_x_and_y_and_z = job(_add_x_and_y_and_z)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 8 + }, + { + "id": "13debfcd-362d-4fd0-a91f-5ab33632fceb", + "cell_type": "code", + "source": "pr = Project(\"test\")\npr.remove_jobs(recursive=True, silently=True)", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "output_type": "display_data", + "data": { + "text/plain": "0it [00:00, ?it/s]", + "application/vnd.jupyter.widget-view+json": { + "version_major": 2, + "version_minor": 0, + "model_id": "1bcb58b981944c688403d1eaca7b3598" + } + }, + "metadata": {} + } + ], + "execution_count": 9 + }, + { + "id": "1f1cb12f-4001-478d-8ea0-b369f4f2981a", + "cell_type": "code", + "source": "obj = add_x_and_y(x=1, y=2, pyiron_project=pr)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 10 + }, + { + "id": "4140f07b-af54-41ef-be22-df6b5b53bf95", + "cell_type": "code", + "source": "w = add_x_and_y_and_z(x=obj.output.x, y=obj.output.y, z=obj.output.z, pyiron_project=pr)", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 11 + }, + { + "id": "52646121-335f-48e6-bd5e-a1d69d00e8bc", + "cell_type": "code", + "source": "write_workflow_json(delayed_object=w, file_name=\"workflow_pyiron.json\")", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 12 + }, + { + "id": "72c8e6e6-8e60-4a4f-81f3-968b4b5f36ee", + "cell_type": "code", + "source": "!cat workflow_pyiron.json", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "{\"nodes\": {\"0\": \"simple_workflow.add_x_and_y_and_z\", \"1\": \"simple_workflow.add_x_and_y\", \"2\": 1, \"3\": 2}, \"edges\": [{\"target\": 0, \"targetHandle\": \"x\", \"source\": 1, \"sourceHandle\": \"x\"}, {\"target\": 1, \"targetHandle\": \"x\", \"source\": 2, \"sourceHandle\": null}, {\"target\": 1, \"targetHandle\": \"y\", \"source\": 3, \"sourceHandle\": null}, {\"target\": 0, \"targetHandle\": \"y\", \"source\": 1, \"sourceHandle\": \"y\"}, {\"target\": 0, \"targetHandle\": \"z\", \"source\": 1, \"sourceHandle\": \"z\"}]}" + } + ], + "execution_count": 13 + }, + { + "id": "32fcd4b2-4f0a-442d-b098-827672823796", + "cell_type": "code", + "source": "flow = load_workflow_json(file_name=\"workflow_pyiron.json\")", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": 14 + }, + { + "id": "a80b59bd-fe30-49c6-92ca-35ef2d77a6fb", + "cell_type": "code", + "source": "result = run_locally(flow)\nresult", + "metadata": { + "trusted": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": "2025-03-13 06:29:36,854 INFO Started executing jobs locally\n2025-03-13 06:29:37,166 INFO Starting job - add_x_and_y (75f3eb14-326b-46bb-848d-ef501b2d43b4)\n2025-03-13 06:29:37,169 INFO Finished job - add_x_and_y (75f3eb14-326b-46bb-848d-ef501b2d43b4)\n2025-03-13 06:29:37,170 INFO Starting job - add_x_and_y_and_z (609c1659-ec60-4211-8996-670770e4b36c)\n2025-03-13 06:29:37,172 INFO Finished job - add_x_and_y_and_z (609c1659-ec60-4211-8996-670770e4b36c)\n2025-03-13 06:29:37,172 INFO Finished executing jobs locally\n" + }, + { + "execution_count": 15, + "output_type": "execute_result", + "data": { + "text/plain": "{'75f3eb14-326b-46bb-848d-ef501b2d43b4': {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 '609c1659-ec60-4211-8996-670770e4b36c': {1: Response(output=6, detour=None, addition=None, replace=None, stored_data=None, stop_children=False, stop_jobflow=False, job_dir=PosixPath('/home/jovyan'))}}" + }, + "metadata": {} + } + ], + "execution_count": 15 + }, + { + "id": "6a8d1a17-3698-4873-8937-616e9e7dc7ca", + "cell_type": "code", + "source": "", + "metadata": { + "trusted": true + }, + "outputs": [], + "execution_count": null + } + ] +} diff --git a/python_workflow_definition/src/python_workflow_definition/jobflow.py b/python_workflow_definition/src/python_workflow_definition/jobflow.py index 3e54282..185c7f2 100644 --- a/python_workflow_definition/src/python_workflow_definition/jobflow.py +++ b/python_workflow_definition/src/python_workflow_definition/jobflow.py @@ -5,51 +5,49 @@ import numpy as np from jobflow import job, Flow +from python_workflow_definition.shared import get_dict, get_list, get_kwargs, get_source_handles -def get_function_dict(flow): + +def _get_function_dict(flow): return { job.uuid: job.function for job in flow.jobs } -def get_nodes_dict(function_dict): +def _get_nodes_dict(function_dict): nodes_dict, nodes_mapping_dict = {}, {} - # function_dict_len = len(function_dict) for i, [k, v] in enumerate(function_dict.items()): - # nodes_dict[function_dict_len-i] = v - # nodes_mapping_dict[k] = function_dict_len-i nodes_dict[i] = v nodes_mapping_dict[k] = i return nodes_dict, nodes_mapping_dict -def get_edge_from_dict(target, key, value_dict, nodes_mapping_dict): +def _get_edge_from_dict(target, key, value_dict, nodes_mapping_dict): if len(value_dict['attributes']) == 1: return {'target': target, 'targetHandle': key, "source": nodes_mapping_dict[value_dict['uuid']], 'sourceHandle': value_dict['attributes'][0][1]} else: return {'target': target, 'targetHandle': key, "source": nodes_mapping_dict[value_dict['uuid']], 'sourceHandle': None} -def get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict): +def _get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict): edges_lst = [] for job in flow_dict['jobs']: for k, v in job['function_kwargs'].items(): if isinstance(v, dict) and '@module' in v and '@class' in v and '@version' in v: - edges_lst.append(get_edge_from_dict( + edges_lst.append(_get_edge_from_dict( target=nodes_mapping_dict[job["uuid"]], key=k, value_dict=v, nodes_mapping_dict=nodes_mapping_dict, )) elif isinstance(v, dict) and any([isinstance(el, dict) and '@module' in el and '@class' in el and '@version' in el for el in v.values()]): - # print("found link in dict", v) node_dict_index = len(nodes_dict) nodes_dict[node_dict_index] = get_dict for kt, vt in v.items(): if isinstance(vt, dict) and '@module' in vt and '@class' in vt and '@version' in vt: - edges_lst.append(get_edge_from_dict( + edges_lst.append(_get_edge_from_dict( target=node_dict_index, key=kt, value_dict=vt, @@ -60,17 +58,15 @@ def get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict): node_index = len(nodes_dict) nodes_dict[node_index] = vt else: - # print(nodes_dict, vt) node_index = {str(tv): tk for tk, tv in nodes_dict.items()}[str(vt)] edges_lst.append({'target': node_dict_index, 'targetHandle': kt, "source": node_index, 'sourceHandle': None}) edges_lst.append({'target': nodes_mapping_dict[job["uuid"]], 'targetHandle': k, "source": node_dict_index, 'sourceHandle': None}) elif isinstance(v, list) and any([isinstance(el, dict) and '@module' in el and '@class' in el and '@version' in el for el in v]): - # print("found link in list", v) node_list_index = len(nodes_dict) nodes_dict[node_list_index] = get_list for kt, vt in enumerate(v): if isinstance(vt, dict) and '@module' in vt and '@class' in vt and '@version' in vt: - edges_lst.append(get_edge_from_dict( + edges_lst.append(_get_edge_from_dict( target=node_list_index, key=str(kt), value_dict=vt, @@ -81,7 +77,6 @@ def get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict): node_index = len(nodes_dict) nodes_dict[node_index] = vt else: - # print(nodes_dict, vt) node_index = {str(tv): tk for tk, tv in nodes_dict.items()}[str(vt)] edges_lst.append({'target': node_list_index, 'targetHandle': kt, "source": node_index, 'sourceHandle': None}) edges_lst.append({'target': nodes_mapping_dict[job["uuid"]], 'targetHandle': k, "source": node_list_index, 'sourceHandle': None}) @@ -95,19 +90,7 @@ def get_edges_and_extend_nodes(flow_dict, nodes_mapping_dict, nodes_dict): return edges_lst, nodes_dict -def get_dict(**kwargs): - return {k: v for k, v in kwargs.items()} - - -def get_list(**kwargs): - return list(kwargs.values()) - - -def get_kwargs(lst): - return {t['targetHandle']: {'source': t['source'], 'sourceHandle': t['sourceHandle']} for t in lst} - - -def resort_total_lst(total_dict, nodes_dict): +def _resort_total_lst(total_dict, nodes_dict): nodes_with_dep_lst = list(sorted(total_dict.keys())) nodes_without_dep_lst = [k for k in nodes_dict.keys() if k not in nodes_with_dep_lst] ordered_lst = [] @@ -123,8 +106,7 @@ def resort_total_lst(total_dict, nodes_dict): return total_new_dict -def group_edges(edges_lst): - # edges_sorted_lst = sorted(edges_lst, key=lambda x: x['target'], reverse=True) +def _group_edges(edges_lst): total_dict = {} for ed_major in edges_lst: target_id = ed_major["target"] @@ -134,17 +116,15 @@ def group_edges(edges_lst): if target_id == ed["target"]: tmp_lst.append(ed) total_dict[target_id] = get_kwargs(lst=tmp_lst) - # total_dict[target_id] = get_kwargs(lst=tmp_lst) return total_dict -def get_input_dict(nodes_dict): +def _get_input_dict(nodes_dict): return {k:v for k, v in nodes_dict.items() if not isfunction(v)} -def get_workflow(nodes_dict, input_dict, total_dict, source_handles_dict): +def _get_workflow(nodes_dict, input_dict, total_dict, source_handles_dict): def get_attr_helper(obj, source_handle): - # print("attr_helper", source_handle, getattr(obj, "output"), getattr(getattr(obj, "output"), source_handle)) if source_handle is None: return getattr(obj, "output") else: @@ -155,7 +135,6 @@ def get_attr_helper(obj, source_handle): v = nodes_dict[k] if isfunction(v): if k in source_handles_dict.keys(): - # print(k, {el: el for el in source_handles_dict[k] if el is not None}) fn = job(method=v, data=[el for el in source_handles_dict[k] if el is not None]) else: fn = job(method=v) @@ -164,31 +143,17 @@ def get_attr_helper(obj, source_handle): obj=memory_dict[vw['source']], source_handle=vw['sourceHandle']) for kw, vw in total_dict[k].items() } - # print(k, kwargs) memory_dict[k] = fn(**kwargs) return list(memory_dict.values()) -def get_item_from_tuple(input_obj, index, index_lst): +def _get_item_from_tuple(input_obj, index, index_lst): if isinstance(input_obj, dict): return input_obj[index] - else: # input_obj is a tuple + else: return list(input_obj)[index_lst.index(index)] -def get_source_handles(edges_lst): - source_handle_dict = {} - for ed in edges_lst: - if ed['source'] not in source_handle_dict.keys(): - source_handle_dict[ed['source']] = [ed['sourceHandle']] - else: - source_handle_dict[ed['source']].append(ed['sourceHandle']) - return { - k: list(range(len(v))) if len(v) > 1 and all([el is None for el in v]) else v - for k, v in source_handle_dict.items() - } - - def load_workflow_json(file_name): with open(file_name, "r") as f: content = json.load(f) @@ -211,18 +176,16 @@ def load_workflow_json(file_name): for k, v in content["nodes"].items(): if isinstance(v, str) and "." in v: p, m = v.rsplit('.', 1) - if p == "python_workflow_definition.pyiron_base": - p = "python_workflow_definition.jobflow" mod = import_module(p) nodes_new_dict[int(k)] = getattr(mod, m) else: nodes_new_dict[int(k)] = v source_handles_dict = get_source_handles(edges_lst=edges_new_lst) - total_dict = group_edges(edges_lst=edges_new_lst) - input_dict = get_input_dict(nodes_dict=nodes_new_dict) - new_total_dict = resort_total_lst(total_dict=total_dict, nodes_dict=nodes_new_dict) - task_lst = get_workflow( + total_dict = _group_edges(edges_lst=edges_new_lst) + input_dict = _get_input_dict(nodes_dict=nodes_new_dict) + new_total_dict = _resort_total_lst(total_dict=total_dict, nodes_dict=nodes_new_dict) + task_lst = _get_workflow( nodes_dict=nodes_new_dict, input_dict=input_dict, total_dict=new_total_dict, @@ -233,9 +196,9 @@ def load_workflow_json(file_name): def write_workflow_json(flow, file_name="workflow.json"): flow_dict = flow.as_dict() - function_dict = get_function_dict(flow=flow) - nodes_dict, nodes_mapping_dict = get_nodes_dict(function_dict=function_dict) - edges_lst, nodes_dict = get_edges_and_extend_nodes( + function_dict = _get_function_dict(flow=flow) + nodes_dict, nodes_mapping_dict = _get_nodes_dict(function_dict=function_dict) + edges_lst, nodes_dict = _get_edges_and_extend_nodes( flow_dict=flow_dict, nodes_mapping_dict=nodes_mapping_dict, nodes_dict=nodes_dict, diff --git a/python_workflow_definition/src/python_workflow_definition/purepython.py b/python_workflow_definition/src/python_workflow_definition/purepython.py index a916c79..80c996a 100644 --- a/python_workflow_definition/src/python_workflow_definition/purepython.py +++ b/python_workflow_definition/src/python_workflow_definition/purepython.py @@ -3,16 +3,7 @@ from inspect import isfunction -def get_dict(**kwargs): - return {k: v for k, v in kwargs.items()} - - -def get_list(**kwargs): - return list(kwargs.values()) - - -def get_kwargs(lst): - return {t['targetHandle']: {'source': t['source'], 'sourceHandle': t['sourceHandle']} for t in lst} +from python_workflow_definition.shared import get_dict, get_list, get_kwargs def resort_total_lst(total_lst, nodes_dict): @@ -80,8 +71,6 @@ def load_workflow_json(file_name): for k, v in content["nodes"].items(): if isinstance(v, str) and "." in v: p, m = v.rsplit('.', 1) - if p == "python_workflow_definition.pyiron_base": - p = "python_workflow_definition.purepython" mod = import_module(p) nodes_new_dict[int(k)] = getattr(mod, m) else: diff --git a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py index 0918874..de2fe46 100644 --- a/python_workflow_definition/src/python_workflow_definition/pyiron_base.py +++ b/python_workflow_definition/src/python_workflow_definition/pyiron_base.py @@ -6,12 +6,10 @@ from pyiron_base import job from pyiron_base.project.delayed import DelayedObject +from python_workflow_definition.shared import get_kwargs, get_source_handles -def get_kwargs(lst): - return {t['targetHandle']: {'source': t['source'], 'sourceHandle': t['sourceHandle']} for t in lst} - -def resort_total_lst(total_lst, nodes_dict): +def _resort_total_lst(total_lst, nodes_dict): nodes_with_dep_lst = list(sorted([v[0] for v in total_lst])) nodes_without_dep_lst = [k for k in nodes_dict.keys() if k not in nodes_with_dep_lst] ordered_lst, total_new_lst = [], [] @@ -25,7 +23,7 @@ def resort_total_lst(total_lst, nodes_dict): return total_new_lst -def group_edges(edges_lst): +def _group_edges(edges_lst): edges_sorted_lst = sorted(edges_lst, key=lambda x: x['target'], reverse=True) total_lst, tmp_lst = [], [] target_id = edges_sorted_lst[0]['target'] @@ -40,32 +38,19 @@ def group_edges(edges_lst): return total_lst -def get_source_handles(edges_lst): - source_handle_dict = {} - for ed in edges_lst: - if ed['source'] not in source_handle_dict.keys(): - source_handle_dict[ed['source']] = [ed['sourceHandle']] - else: - source_handle_dict[ed['source']].append(ed['sourceHandle']) - return { - k: list(range(len(v))) if len(v) > 1 and all([el is None for el in v]) else v - for k, v in source_handle_dict.items() - } - - -def get_source(nodes_dict, delayed_object_dict, source, sourceHandle): +def _get_source(nodes_dict, delayed_object_dict, source, sourceHandle): if source in delayed_object_dict.keys(): return delayed_object_dict[source].__getattr__("output").__getattr__(sourceHandle) else: return nodes_dict[source] -def get_delayed_object_dict(total_lst, nodes_dict, source_handle_dict, pyiron_project): +def _get_delayed_object_dict(total_lst, nodes_dict, source_handle_dict, pyiron_project): delayed_object_dict = {} for item in total_lst: key, input_dict = item kwargs = { - k: get_source( + k: _get_source( nodes_dict=nodes_dict, delayed_object_dict=delayed_object_dict, source=v["source"], @@ -90,7 +75,7 @@ def get_list(**kwargs): return list(kwargs["kwargs"].values()) -def remove_server_obj(nodes_dict, edges_lst): +def _remove_server_obj(nodes_dict, edges_lst): server_lst = [k for k in nodes_dict.keys() if k.startswith("server_obj_")] for s in server_lst: del nodes_dict[s] @@ -98,19 +83,19 @@ def remove_server_obj(nodes_dict, edges_lst): return nodes_dict, edges_lst -def get_nodes(connection_dict, delayed_object_updated_dict): +def _get_nodes(connection_dict, delayed_object_updated_dict): return { connection_dict[k]: v._python_function if isinstance(v, DelayedObject) else v for k, v in delayed_object_updated_dict.items() } -def get_unique_objects(nodes_dict, edges_lst): # I need a pre-filter before this function to remove the virtual nodes +def _get_unique_objects(nodes_dict): delayed_object_dict = {} for k, v in nodes_dict.items(): if isinstance(v, DelayedObject): delayed_object_dict[k] = v - elif isinstance(v, list) and any([isinstance(el, DelayedObject) for el in v]): # currently this replaces any list - what I need instead is some kind of virtual node - mixed nodes + elif isinstance(v, list) and any([isinstance(el, DelayedObject) for el in v]): delayed_object_dict[k] = DelayedObject(function=get_list) delayed_object_dict[k]._input = {i: el for i, el in enumerate(v)} delayed_object_dict[k]._python_function = get_list @@ -139,7 +124,7 @@ def get_unique_objects(nodes_dict, edges_lst): # I need a pre-filter before thi return delayed_object_updated_dict, match_dict -def get_connection_dict(delayed_object_updated_dict, match_dict): +def _get_connection_dict(delayed_object_updated_dict, match_dict): new_obj_dict = {} connection_dict = {} lookup_dict = {} @@ -155,7 +140,7 @@ def get_connection_dict(delayed_object_updated_dict, match_dict): return connection_dict, lookup_dict -def get_edges_dict(edges_lst, nodes_dict, connection_dict, lookup_dict): +def _get_edges_dict(edges_lst, nodes_dict, connection_dict, lookup_dict): edges_dict_lst = [] existing_connection_lst = [] for ep in edges_lst: @@ -200,17 +185,17 @@ def load_workflow_json(project, file_name): for k, v in content["nodes"].items(): if isinstance(v, str) and "." in v: p, m = v.rsplit('.', 1) - if p == "python_workflow_definition.jobflow": + if p == "python_workflow_definition.shared": p = "python_workflow_definition.pyiron_base" mod = import_module(p) nodes_new_dict[int(k)] = getattr(mod, m) else: nodes_new_dict[int(k)] = v - total_lst = group_edges(edges_new_lst) - total_new_lst = resort_total_lst(total_lst=total_lst, nodes_dict=nodes_new_dict) + total_lst = _group_edges(edges_new_lst) + total_new_lst = _resort_total_lst(total_lst=total_lst, nodes_dict=nodes_new_dict) source_handle_dict = get_source_handles(edges_new_lst) - delayed_object_dict = get_delayed_object_dict( + delayed_object_dict = _get_delayed_object_dict( total_lst=total_new_lst, nodes_dict=nodes_new_dict, source_handle_dict=source_handle_dict, @@ -221,16 +206,19 @@ def load_workflow_json(project, file_name): def write_workflow_json(delayed_object, file_name="workflow.json"): nodes_dict, edges_lst = delayed_object.get_graph() - nodes_dict, edges_lst = remove_server_obj(nodes_dict=nodes_dict, edges_lst=edges_lst) - delayed_object_updated_dict, match_dict = get_unique_objects(nodes_dict=nodes_dict, edges_lst=edges_lst) - connection_dict, lookup_dict = get_connection_dict(delayed_object_updated_dict=delayed_object_updated_dict, match_dict=match_dict) - nodes_new_dict = get_nodes(connection_dict=connection_dict, delayed_object_updated_dict=delayed_object_updated_dict) - edges_new_lst = get_edges_dict(edges_lst=edges_lst, nodes_dict=nodes_dict, connection_dict=connection_dict, lookup_dict=lookup_dict) + nodes_dict, edges_lst = _remove_server_obj(nodes_dict=nodes_dict, edges_lst=edges_lst) + delayed_object_updated_dict, match_dict = _get_unique_objects(nodes_dict=nodes_dict) + connection_dict, lookup_dict = _get_connection_dict(delayed_object_updated_dict=delayed_object_updated_dict, match_dict=match_dict) + nodes_new_dict = _get_nodes(connection_dict=connection_dict, delayed_object_updated_dict=delayed_object_updated_dict) + edges_new_lst = _get_edges_dict(edges_lst=edges_lst, nodes_dict=nodes_dict, connection_dict=connection_dict, lookup_dict=lookup_dict) nodes_store_dict = {} for k, v in nodes_new_dict.items(): if isfunction(v): - nodes_store_dict[k] = v.__module__ + "." + v.__name__ + mod = v.__module__ + if mod == "python_workflow_definition.pyiron_base": + mod = "python_workflow_definition.shared" + nodes_store_dict[k] = mod + "." + v.__name__ elif isinstance(v, np.ndarray): nodes_store_dict[k] = v.tolist() else: diff --git a/python_workflow_definition/src/python_workflow_definition/shared.py b/python_workflow_definition/src/python_workflow_definition/shared.py new file mode 100644 index 0000000..8f2ee29 --- /dev/null +++ b/python_workflow_definition/src/python_workflow_definition/shared.py @@ -0,0 +1,23 @@ +def get_dict(**kwargs): + return {k: v for k, v in kwargs.items()} + + +def get_list(**kwargs): + return list(kwargs.values()) + + +def get_kwargs(lst): + return {t['targetHandle']: {'source': t['source'], 'sourceHandle': t['sourceHandle']} for t in lst} + + +def get_source_handles(edges_lst): + source_handle_dict = {} + for ed in edges_lst: + if ed['source'] not in source_handle_dict.keys(): + source_handle_dict[ed['source']] = [ed['sourceHandle']] + else: + source_handle_dict[ed['source']].append(ed['sourceHandle']) + return { + k: list(range(len(v))) if len(v) > 1 and all([el is None for el in v]) else v + for k, v in source_handle_dict.items() + } \ No newline at end of file diff --git a/workflow_qe.json b/workflow_qe.json index efc1eba..ac11b3f 100644 --- a/workflow_qe.json +++ b/workflow_qe.json @@ -13,25 +13,25 @@ "10": 4.05, "11": true, "12": "mini", - "13": "python_workflow_definition.pyiron_base.get_dict", + "13": "python_workflow_definition.shared.get_dict", "14": {"Al": "Al.pbe-n-kjpaw_psl.1.0.0.UPF"}, "15": [3, 3, 3], "16": "vc-relax", "17": 0.02, "18": [0.9, 0.95, 1.0, 1.05, 1.1], "19": "strain_0", - "20": "python_workflow_definition.pyiron_base.get_dict", + "20": "python_workflow_definition.shared.get_dict", "21": "scf", "22": "strain_1", - "23": "python_workflow_definition.pyiron_base.get_dict", + "23": "python_workflow_definition.shared.get_dict", "24": "strain_2", - "25": "python_workflow_definition.pyiron_base.get_dict", + "25": "python_workflow_definition.shared.get_dict", "26": "strain_3", - "27": "python_workflow_definition.pyiron_base.get_dict", + "27": "python_workflow_definition.shared.get_dict", "28": "strain_4", - "29": "python_workflow_definition.pyiron_base.get_dict", - "30": "python_workflow_definition.pyiron_base.get_list", - "31": "python_workflow_definition.pyiron_base.get_list" + "29": "python_workflow_definition.shared.get_dict", + "30": "python_workflow_definition.shared.get_list", + "31": "python_workflow_definition.shared.get_list" }, "edges": [ {"target": 0, "targetHandle": "element", "source": 9, "sourceHandle": null},