diff --git a/notebooks/deepdive.ipynb b/notebooks/deepdive.ipynb index b2917fc8..e0816e96 100644 --- a/notebooks/deepdive.ipynb +++ b/notebooks/deepdive.ipynb @@ -1691,7 +1691,7 @@ "\n" ], "text/plain": [ - "" + "" ] }, "execution_count": 41, @@ -1928,6 +1928,44 @@ "digit_counter(12345)" ] }, + { + "cell_type": "markdown", + "id": "5093b50f-3d2e-41ef-8e66-6bb884a0f027", + "metadata": {}, + "source": [ + "## Dictionary representation\n", + "\n", + "You can get a simple dictionary representation of a given workflow/macro connecting the node and channel (i.e. node and edge in graph parlance) full labels to their python objects:" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "9d2cab07-0e64-495f-accd-338eef3e2822", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'nodes': {'/HowManyDigits/as_str': ,\n", + " '/HowManyDigits/digits': },\n", + " 'edges': {'data': {('/HowManyDigits/as_str.str',\n", + " '/HowManyDigits/digits.obj'): (,\n", + " )},\n", + " 'signal': {('/HowManyDigits/as_str.ran',\n", + " '/HowManyDigits/digits.accumulate_and_run'): (,\n", + " )}}}" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "digit_counter.graph_as_dict" + ] + }, { "cell_type": "markdown", "id": "22d2fdcf-0206-497d-9344-a71e3472a2c0", @@ -1942,7 +1980,7 @@ }, { "cell_type": "code", - "execution_count": 47, + "execution_count": 48, "id": "9aaeeec0-5f88-4c94-a6cc-45b56d2f0111", "metadata": {}, "outputs": [], @@ -1958,7 +1996,7 @@ }, { "cell_type": "code", - "execution_count": 48, + "execution_count": 49, "id": "26a080dc-acaf-45bb-9935-7a42ff8d9552", "metadata": {}, "outputs": [ @@ -1968,7 +2006,7 @@ "{'digits_in_sum_plus_5': None}" ] }, - "execution_count": 48, + "execution_count": 49, "metadata": {}, "output_type": "execute_result" } @@ -1987,7 +2025,7 @@ }, { "cell_type": "code", - "execution_count": 49, + "execution_count": 50, "id": "ea97df98-881e-4a99-a0ad-81c048fe0520", "metadata": {}, "outputs": [ @@ -1997,7 +2035,7 @@ "{'digits_in_sum_plus_5': 2}" ] }, - "execution_count": 49, + "execution_count": 50, "metadata": {}, "output_type": "execute_result" } @@ -2017,7 +2055,7 @@ }, { "cell_type": "code", - "execution_count": 50, + "execution_count": 51, "id": "71413b60-2bbb-4cde-af20-598ea2d0b463", "metadata": {}, "outputs": [ @@ -2436,10 +2474,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 50, + "execution_count": 51, "metadata": {}, "output_type": "execute_result" } @@ -2451,7 +2489,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 52, "id": "630a9ffa-a157-4a1b-8d50-186513454088", "metadata": {}, "outputs": [ @@ -3508,10 +3546,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 51, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -3523,7 +3561,7 @@ }, { "cell_type": "code", - "execution_count": 52, + "execution_count": 53, "id": "2f133c94-ba83-491b-9c47-3c1214a7ff5f", "metadata": {}, "outputs": [ @@ -3846,10 +3884,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 52, + "execution_count": 53, "metadata": {}, "output_type": "execute_result" } @@ -3891,7 +3929,7 @@ }, { "cell_type": "code", - "execution_count": 53, + "execution_count": 54, "id": "aa575249-b209-4e0c-9ea6-a82bc69dc833", "metadata": {}, "outputs": [ @@ -3900,7 +3938,7 @@ "output_type": "stream", "text": [ "None 1\n", - " 5\n" + " 5\n" ] } ], @@ -3927,7 +3965,7 @@ }, { "cell_type": "code", - "execution_count": 54, + "execution_count": 55, "id": "c1b7b4e9-1c76-470c-ba6e-a58ea3f611f6", "metadata": {}, "outputs": [ @@ -3959,7 +3997,7 @@ }, { "cell_type": "code", - "execution_count": 55, + "execution_count": 56, "id": "7e98058b-a791-4cb1-ae2c-864ad7e56cee", "metadata": {}, "outputs": [], @@ -3977,7 +4015,7 @@ }, { "cell_type": "code", - "execution_count": 56, + "execution_count": 57, "id": "0d1b4005-488e-492f-adcb-8ad7235e4fe3", "metadata": {}, "outputs": [ @@ -3986,7 +4024,7 @@ "output_type": "stream", "text": [ "None 1\n", - " 5\n", + " 5\n", "Finally 5\n", "b (Add):\n", "Inputs ['obj', 'other']\n", @@ -4025,7 +4063,7 @@ }, { "cell_type": "code", - "execution_count": 57, + "execution_count": 58, "id": "d03ca074-35a0-4e0d-9377-d4eaa5521f85", "metadata": {}, "outputs": [], @@ -4039,7 +4077,7 @@ }, { "cell_type": "code", - "execution_count": 58, + "execution_count": 59, "id": "a7c07aa0-84fc-4f43-aa4f-6498c0837d76", "metadata": {}, "outputs": [ @@ -4047,7 +4085,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "6.015308832982555\n" + "6.013603942992631\n" ] } ], @@ -4071,7 +4109,7 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 60, "id": "b062ab5f-9b98-4843-8925-b93bf4c173f8", "metadata": {}, "outputs": [ @@ -4079,7 +4117,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "3.8395268750027753\n" + "4.179039627022576\n" ] } ], @@ -4138,7 +4176,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 61, "id": "0b373764-b389-4c24-8086-f3d33a4f7fd7", "metadata": {}, "outputs": [ @@ -4206,7 +4244,7 @@ "4 4 5" ] }, - "execution_count": 60, + "execution_count": 61, "metadata": {}, "output_type": "execute_result" } @@ -4233,7 +4271,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 62, "id": "6f486c87-f3d4-405f-a759-2ada12cb45e2", "metadata": {}, "outputs": [ @@ -4486,7 +4524,7 @@ "15 2 6 8 10 2 6 8 10 e" ] }, - "execution_count": 61, + "execution_count": 62, "metadata": {}, "output_type": "execute_result" } @@ -4527,7 +4565,7 @@ }, { "cell_type": "code", - "execution_count": 62, + "execution_count": 63, "id": "10f284c8-9210-465f-b4d6-9aa4c0909b08", "metadata": {}, "outputs": [ @@ -4585,7 +4623,7 @@ "0 1 3 7 9 1 3 7 9 e" ] }, - "execution_count": 62, + "execution_count": 63, "metadata": {}, "output_type": "execute_result" } @@ -4604,7 +4642,7 @@ }, { "cell_type": "code", - "execution_count": 63, + "execution_count": 64, "id": "c269d736-0599-4885-bf8c-e033e881adc7", "metadata": {}, "outputs": [ @@ -4678,7 +4716,7 @@ "4 4 14 18" ] }, - "execution_count": 63, + "execution_count": 64, "metadata": {}, "output_type": "execute_result" } @@ -4702,7 +4740,7 @@ }, { "cell_type": "code", - "execution_count": 64, + "execution_count": 65, "id": "e0916c46-132c-4046-827e-a75fff6dbc5b", "metadata": {}, "outputs": [], @@ -4744,7 +4782,7 @@ }, { "cell_type": "code", - "execution_count": 65, + "execution_count": 66, "id": "ce8a3c1f-64e9-4da1-b29b-d16717d03b22", "metadata": {}, "outputs": [ @@ -5209,10 +5247,10 @@ "\n" ], "text/plain": [ - "" + "" ] }, - "execution_count": 65, + "execution_count": 66, "metadata": {}, "output_type": "execute_result" } @@ -5224,7 +5262,7 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": 67, "id": "32d1c20d-d484-434f-9b10-02ee17df4eee", "metadata": {}, "outputs": [ @@ -5234,7 +5272,7 @@ "{'greater': 6}" ] }, - "execution_count": 66, + "execution_count": 67, "metadata": {}, "output_type": "execute_result" } @@ -5253,7 +5291,7 @@ }, { "cell_type": "code", - "execution_count": 67, + "execution_count": 68, "id": "d44e90ad-4a96-4c0a-a4d2-0e3ed394479c", "metadata": {}, "outputs": [ @@ -5274,7 +5312,7 @@ " 'switch']" ] }, - "execution_count": 67, + "execution_count": 68, "metadata": {}, "output_type": "execute_result" } @@ -5293,7 +5331,7 @@ }, { "cell_type": "code", - "execution_count": 68, + "execution_count": 69, "id": "5814f830-fe47-4bce-b8f4-35df63565e6b", "metadata": {}, "outputs": [ @@ -5303,7 +5341,7 @@ "[2, 4, 6]" ] }, - "execution_count": 68, + "execution_count": 69, "metadata": {}, "output_type": "execute_result" } @@ -5322,7 +5360,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": 70, "id": "4a7eece3-20dd-4f57-88f2-5a1076daeb08", "metadata": {}, "outputs": [ @@ -5332,7 +5370,7 @@ "6" ] }, - "execution_count": 69, + "execution_count": 70, "metadata": {}, "output_type": "execute_result" } @@ -5369,7 +5407,7 @@ { "data": { "text/plain": [ - "{'always_new__rand': 598, 'cached__rand': 307}" + "{'always_new__rand': 205, 'cached__rand': 457}" ] }, "execution_count": 71, @@ -5412,7 +5450,7 @@ { "data": { "text/plain": [ - "{'always_new__rand': 492, 'cached__rand': 307}" + "{'always_new__rand': 739, 'cached__rand': 457}" ] }, "execution_count": 72, diff --git a/pyiron_workflow/nodes/composite.py b/pyiron_workflow/nodes/composite.py index fb05331e..594505ab 100644 --- a/pyiron_workflow/nodes/composite.py +++ b/pyiron_workflow/nodes/composite.py @@ -401,6 +401,30 @@ def color(self) -> str: """For drawing the graph""" return SeabornColors.brown + @property + def graph_as_dict(self) -> dict: + """ + A nested dictionary representation of the computation graph using full labels + as keys and objects as values. + """ + return { + "nodes": {n.full_label: n for n in self}, + "edges": { + "data": { + (out.full_label, inp.full_label): (out, inp) + for n in self + for out in n.outputs + for inp in out.connections + }, + "signal": { + (out.full_label, inp.full_label): (out, inp) + for n in self + for out in n.signals.output + for inp in out.connections + } + } + } + @property def package_requirements(self) -> set[str]: """