+{"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3 (ipykernel)","language":"python"},"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":4,"nbformat":4,"cells":[{"cell_type":"code","source":"from python_workflow_definition.aiida import write_workflow_json\nfrom python_workflow_definition.jobflow import load_workflow_json\nfrom jobflow.managers.local import run_locally\n\nfrom aiida_workgraph import WorkGraph, task\nfrom aiida import load_profile\nload_profile()\n\nworkflow_json_filename = \"aiida_to_jobflow_simple.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":1},{"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":2},{"cell_type":"code","source":"@task.pythonjob()\ndef pickle_node(value):\n \"\"\"Handle data nodes\"\"\"\n return value","metadata":{"trusted":true},"outputs":[],"execution_count":3},{"cell_type":"code","source":"add_x_and_y = task.pythonjob(outputs=[\"x\", \"y\", \"z\"])(_add_x_and_y)\nadd_x_and_y_and_z = task.pythonjob()(_add_x_and_y_and_z)","metadata":{"trusted":true},"outputs":[],"execution_count":4},{"cell_type":"code","source":"# TODO: Create inputs rather than tasks out of data nodes\nwg = WorkGraph(\"wg-simple\")","metadata":{"trusted":true},"outputs":[],"execution_count":5},{"cell_type":"code","source":"helper_task1 = wg.add_task(pickle_node, name=\"x\", value=1)\nhelper_task2 = wg.add_task(pickle_node, name=\"y\", value=2)","metadata":{"trusted":true},"outputs":[],"execution_count":6},{"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=helper_task1.outputs.result,\n y=helper_task2.outputs.result,\n)","metadata":{"trusted":true},"outputs":[],"execution_count":7},{"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":8},{"cell_type":"code","source":"write_workflow_json(wg=wg, file_name=workflow_json_filename)","metadata":{"trusted":true},"outputs":[{"execution_count":9,"output_type":"execute_result","data":{"text/plain":"{'nodes': {'0': 1,\n '1': 2,\n '2': 'simple_workflow.add_x_and_y',\n '3': 'simple_workflow.add_x_and_y_and_z'},\n 'edges': [{'target': 2,\n 'targetHandle': 'x',\n 'source': 0,\n 'sourceHandle': None},\n {'target': 2, 'targetHandle': 'y', 'source': 1, 'sourceHandle': None},\n {'target': 3, 'targetHandle': 'x', 'source': 2, 'sourceHandle': 'x'},\n {'target': 3, 'targetHandle': 'y', 'source': 2, 'sourceHandle': 'y'},\n {'target': 3, 'targetHandle': 'z', 'source': 2, 'sourceHandle': 'z'}]}"},"metadata":{}}],"execution_count":9},{"cell_type":"code","source":"flow = load_workflow_json(file_name=workflow_json_filename)","metadata":{"trusted":true},"outputs":[],"execution_count":10},{"cell_type":"code","source":"result = run_locally(flow)\nresult","metadata":{"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":"2025-03-21 20:45:40,878 INFO Started executing jobs locally\n2025-03-21 20:45:41,115 INFO Starting job - add_x_and_y (ef28440e-7d32-49d3-85f5-121da0fdf65f)\n2025-03-21 20:45:41,117 INFO Finished job - add_x_and_y (ef28440e-7d32-49d3-85f5-121da0fdf65f)\n2025-03-21 20:45:41,118 INFO Starting job - add_x_and_y_and_z (c0da46a8-a430-4d88-adb6-7d5b36b8fe52)\n2025-03-21 20:45:41,119 INFO Finished job - add_x_and_y_and_z (c0da46a8-a430-4d88-adb6-7d5b36b8fe52)\n2025-03-21 20:45:41,120 INFO Finished executing jobs locally\n"},{"execution_count":11,"output_type":"execute_result","data":{"text/plain":"{'ef28440e-7d32-49d3-85f5-121da0fdf65f': {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 'c0da46a8-a430-4d88-adb6-7d5b36b8fe52': {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":11}]}
0 commit comments