forked from cadCAD-org/cadCAD
-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nb + refactor __init__.py + add graphviz to reqs
- Loading branch information
Showing
3 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
from cadCAD_diagram.config_diagram import diagram, diagram_from_config | ||
from cadCAD.diagram.config_diagram import diagram, diagram_from_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def policy_1(p, s, h, v):\n", | ||
" return {\"pi_1\": v[\"var_1\"]}\n", | ||
"\n", | ||
"\n", | ||
"def policy_2(p, s, h, v):\n", | ||
" return {\"pi_1\": v[\"var_1\"], \"pi_2\": v[\"var_1\"] * v[\"var_2\"]}\n", | ||
"\n", | ||
"\n", | ||
"def suf_1(p, s, h, v, pi):\n", | ||
" return (\"var_1\", pi[\"pi_1\"])\n", | ||
"\n", | ||
"\n", | ||
"def suf_2(p, s, h, v, pi):\n", | ||
" return (\"var_2\", pi[\"pi_2\"])\n", | ||
"\n", | ||
"\n", | ||
"psubs = [\n", | ||
" {\n", | ||
" \"label\": \"Test\",\n", | ||
" \"policies\": {\"policy_1\": policy_1, \"policy_2\": policy_2},\n", | ||
" \"variables\": {\"var_1\": suf_1, \"var_2\": suf_2},\n", | ||
" }\n", | ||
"]\n", | ||
"\n", | ||
"initial_state = {\"var_1\": 0, \"var_2\": 1}\n", | ||
"\n", | ||
"params = {\"param_1\": 0, \"param_2\": 1}" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"sys.path.append('..')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"image/svg+xml": [ | ||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n", | ||
"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n", | ||
" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n", | ||
"<!-- Generated by graphviz version 2.43.0 (0)\n", | ||
" -->\n", | ||
"<!-- Title: cluster_timestep Pages: 1 -->\n", | ||
"<svg width=\"481pt\" height=\"183pt\"\n", | ||
" viewBox=\"0.00 0.00 693.14 264.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n", | ||
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1.44 1.44) rotate(0) translate(4 260)\">\n", | ||
"<title>cluster_timestep</title>\n", | ||
"<polygon fill=\"pink\" stroke=\"transparent\" points=\"-4,4 -4,-260 689.14,-260 689.14,4 -4,4\"/>\n", | ||
"<g id=\"clust1\" class=\"cluster\">\n", | ||
"<title>cluster_psub_0</title>\n", | ||
"<polygon fill=\"thistle\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"8,-8 8,-248 677.14,-248 677.14,-8 8,-8\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"342.57\" y=\"-232.8\" font-family=\"Times,serif\" font-size=\"14.00\">Partial State Update Block</text>\n", | ||
"</g>\n", | ||
"<g id=\"clust3\" class=\"cluster\">\n", | ||
"<title>cluster_variables_0</title>\n", | ||
"<polygon fill=\"skyblue\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"16,-88 16,-217 106,-217 106,-88 16,-88\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"61\" y=\"-201.8\" font-family=\"Times,serif\" font-size=\"14.00\">State</text>\n", | ||
"</g>\n", | ||
"<g id=\"clust4\" class=\"cluster\">\n", | ||
"<title>cluster_policy_0</title>\n", | ||
"<polygon fill=\"thistle\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"126,-16 126,-217 390.64,-217 390.64,-16 126,-16\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"258.32\" y=\"-201.8\" font-family=\"Times,serif\" font-size=\"14.00\">Policies</text>\n", | ||
"</g>\n", | ||
"<g id=\"clust5\" class=\"cluster\">\n", | ||
"<title>cluster_suf_0</title>\n", | ||
"<polygon fill=\"thistle\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"418.64,-16 418.64,-217 561.64,-217 561.64,-16 418.64,-16\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"490.14\" y=\"-201.8\" font-family=\"Times,serif\" font-size=\"14.00\">State Update Functions</text>\n", | ||
"</g>\n", | ||
"<!-- state_0 -->\n", | ||
"<g id=\"node1\" class=\"node\">\n", | ||
"<title>state_0</title>\n", | ||
"<path fill=\"honeydew\" stroke=\"black\" d=\"M88,-74.73C88,-76.53 75.9,-78 61,-78 46.1,-78 34,-76.53 34,-74.73 34,-74.73 34,-45.27 34,-45.27 34,-43.47 46.1,-42 61,-42 75.9,-42 88,-43.47 88,-45.27 88,-45.27 88,-74.73 88,-74.73\"/>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M88,-74.73C88,-72.92 75.9,-71.45 61,-71.45 46.1,-71.45 34,-72.92 34,-74.73\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"61\" y=\"-56.3\" font-family=\"Times,serif\" font-size=\"14.00\">State 1</text>\n", | ||
"</g>\n", | ||
"<!-- policy_policy_1_0 -->\n", | ||
"<g id=\"node5\" class=\"node\">\n", | ||
"<title>policy_policy_1_0</title>\n", | ||
"<polygon fill=\"palegreen\" stroke=\"black\" stroke-width=\"2\" points=\"246,-90 134,-90 134,-30 246,-30 258,-60 246,-90\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"196\" y=\"-56.3\" font-family=\"Times,serif\" font-size=\"14.00\">policy_1 (policy_1)</text>\n", | ||
"</g>\n", | ||
"<!-- state_0->policy_policy_1_0 -->\n", | ||
"<g id=\"edge6\" class=\"edge\">\n", | ||
"<title>state_0->policy_policy_1_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M88.28,-60C98.61,-60 111.02,-60 123.67,-60\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"123.82,-63.5 133.82,-60 123.82,-56.5 123.82,-63.5\"/>\n", | ||
"</g>\n", | ||
"<!-- policy_policy_2_0 -->\n", | ||
"<g id=\"node6\" class=\"node\">\n", | ||
"<title>policy_policy_2_0</title>\n", | ||
"<polygon fill=\"palegreen\" stroke=\"black\" stroke-width=\"2\" points=\"246,-180 134,-180 134,-120 246,-120 258,-150 246,-180\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"196\" y=\"-146.3\" font-family=\"Times,serif\" font-size=\"14.00\">policy_2 (policy_2)</text>\n", | ||
"</g>\n", | ||
"<!-- state_0->policy_policy_2_0 -->\n", | ||
"<g id=\"edge7\" class=\"edge\">\n", | ||
"<title>state_0->policy_policy_2_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M88.43,-72.68C94.43,-76.03 100.62,-79.87 106,-84 116.22,-91.85 116.09,-96.76 126,-105 127.13,-105.94 128.29,-106.88 129.46,-107.82\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"127.34,-110.61 137.4,-113.92 131.61,-105.05 127.34,-110.61\"/>\n", | ||
"</g>\n", | ||
"<!-- variable_var_2_0 -->\n", | ||
"<g id=\"node2\" class=\"node\">\n", | ||
"<title>variable_var_2_0</title>\n", | ||
"<path fill=\"honeydew\" stroke=\"black\" d=\"M98,-182.73C98,-184.53 81.42,-186 61,-186 40.58,-186 24,-184.53 24,-182.73 24,-182.73 24,-153.27 24,-153.27 24,-151.47 40.58,-150 61,-150 81.42,-150 98,-151.47 98,-153.27 98,-153.27 98,-182.73 98,-182.73\"/>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M98,-182.73C98,-180.92 81.42,-179.45 61,-179.45 40.58,-179.45 24,-180.92 24,-182.73\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"61\" y=\"-164.3\" font-family=\"Times,serif\" font-size=\"14.00\">var_2 (int)</text>\n", | ||
"</g>\n", | ||
"<!-- variable_var_2_0->policy_policy_2_0 -->\n", | ||
"<g id=\"edge4\" class=\"edge\">\n", | ||
"<title>variable_var_2_0->policy_policy_2_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M98.34,-163.08C106.33,-162 115.06,-160.82 123.9,-159.62\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"124.45,-163.08 133.89,-158.27 123.51,-156.14 124.45,-163.08\"/>\n", | ||
"</g>\n", | ||
"<!-- variable_var_1_0 -->\n", | ||
"<g id=\"node3\" class=\"node\">\n", | ||
"<title>variable_var_1_0</title>\n", | ||
"<path fill=\"honeydew\" stroke=\"black\" d=\"M98,-128.73C98,-130.53 81.42,-132 61,-132 40.58,-132 24,-130.53 24,-128.73 24,-128.73 24,-99.27 24,-99.27 24,-97.47 40.58,-96 61,-96 81.42,-96 98,-97.47 98,-99.27 98,-99.27 98,-128.73 98,-128.73\"/>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M98,-128.73C98,-126.92 81.42,-125.45 61,-125.45 40.58,-125.45 24,-126.92 24,-128.73\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"61\" y=\"-110.3\" font-family=\"Times,serif\" font-size=\"14.00\">var_1 (int)</text>\n", | ||
"</g>\n", | ||
"<!-- variable_var_1_0->policy_policy_1_0 -->\n", | ||
"<g id=\"edge3\" class=\"edge\">\n", | ||
"<title>variable_var_1_0->policy_policy_1_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M98.34,-99.24C106.51,-95.93 115.44,-92.3 124.47,-88.64\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"125.94,-91.82 133.89,-84.81 123.31,-85.33 125.94,-91.82\"/>\n", | ||
"</g>\n", | ||
"<!-- variable_var_1_0->policy_policy_2_0 -->\n", | ||
"<g id=\"edge5\" class=\"edge\">\n", | ||
"<title>variable_var_1_0->policy_policy_2_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M98.34,-123.84C106.42,-126.02 115.25,-128.41 124.18,-130.83\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"123.32,-134.22 133.89,-133.46 125.15,-127.47 123.32,-134.22\"/>\n", | ||
"</g>\n", | ||
"<!-- agg_0 -->\n", | ||
"<g id=\"node4\" class=\"node\">\n", | ||
"<title>agg_0</title>\n", | ||
"<ellipse fill=\"greenyellow\" stroke=\"black\" stroke-width=\"2\" cx=\"338.32\" cy=\"-105\" rx=\"44.15\" ry=\"44.15\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"338.32\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\">Aggregation</text>\n", | ||
"</g>\n", | ||
"<!-- suf_var_1_0 -->\n", | ||
"<g id=\"node7\" class=\"node\">\n", | ||
"<title>suf_var_1_0</title>\n", | ||
"<polygon fill=\"red\" stroke=\"black\" stroke-width=\"2\" points=\"522.64,-180 444.64,-180 444.64,-120 522.64,-120 534.64,-150 522.64,-180\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"489.64\" y=\"-146.3\" font-family=\"Times,serif\" font-size=\"14.00\">var_1 (suf_1)</text>\n", | ||
"</g>\n", | ||
"<!-- agg_0->suf_var_1_0 -->\n", | ||
"<g id=\"edge8\" class=\"edge\">\n", | ||
"<title>agg_0->suf_var_1_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M380.92,-117.54C397.59,-122.56 417.02,-128.42 434.75,-133.76\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"433.82,-137.13 444.4,-136.67 435.84,-130.43 433.82,-137.13\"/>\n", | ||
"</g>\n", | ||
"<!-- suf_var_2_0 -->\n", | ||
"<g id=\"node8\" class=\"node\">\n", | ||
"<title>suf_var_2_0</title>\n", | ||
"<polygon fill=\"red\" stroke=\"black\" stroke-width=\"2\" points=\"522.64,-90 444.64,-90 444.64,-30 522.64,-30 534.64,-60 522.64,-90\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"489.64\" y=\"-56.3\" font-family=\"Times,serif\" font-size=\"14.00\">var_2 (suf_2)</text>\n", | ||
"</g>\n", | ||
"<!-- agg_0->suf_var_2_0 -->\n", | ||
"<g id=\"edge9\" class=\"edge\">\n", | ||
"<title>agg_0->suf_var_2_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M380.92,-92.46C397.59,-87.44 417.02,-81.58 434.75,-76.24\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"435.84,-79.57 444.4,-73.33 433.82,-72.87 435.84,-79.57\"/>\n", | ||
"</g>\n", | ||
"<!-- policy_policy_1_0->agg_0 -->\n", | ||
"<g id=\"edge1\" class=\"edge\">\n", | ||
"<title>policy_policy_1_0->agg_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M258.14,-79.61C267.47,-82.6 277.01,-85.66 286.1,-88.57\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"285.16,-91.95 295.75,-91.67 287.3,-85.28 285.16,-91.95\"/>\n", | ||
"</g>\n", | ||
"<!-- policy_policy_2_0->agg_0 -->\n", | ||
"<g id=\"edge2\" class=\"edge\">\n", | ||
"<title>policy_policy_2_0->agg_0</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M258.14,-130.39C267.47,-127.4 277.01,-124.34 286.1,-121.43\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"287.3,-124.72 295.75,-118.33 285.16,-118.05 287.3,-124.72\"/>\n", | ||
"</g>\n", | ||
"<!-- state_1 -->\n", | ||
"<g id=\"node9\" class=\"node\">\n", | ||
"<title>state_1</title>\n", | ||
"<ellipse fill=\"none\" stroke=\"black\" cx=\"633.39\" cy=\"-105\" rx=\"36\" ry=\"18\"/>\n", | ||
"<text text-anchor=\"middle\" x=\"633.39\" y=\"-101.3\" font-family=\"Times,serif\" font-size=\"14.00\">state_1</text>\n", | ||
"</g>\n", | ||
"<!-- suf_var_1_0->state_1 -->\n", | ||
"<g id=\"edge10\" class=\"edge\">\n", | ||
"<title>suf_var_1_0->state_1</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M534.72,-136.01C553.37,-130.09 574.92,-123.24 593.03,-117.5\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"594.23,-120.79 602.7,-114.43 592.11,-114.12 594.23,-120.79\"/>\n", | ||
"</g>\n", | ||
"<!-- suf_var_2_0->state_1 -->\n", | ||
"<g id=\"edge11\" class=\"edge\">\n", | ||
"<title>suf_var_2_0->state_1</title>\n", | ||
"<path fill=\"none\" stroke=\"black\" d=\"M534.72,-73.99C553.37,-79.91 574.92,-86.76 593.03,-92.5\"/>\n", | ||
"<polygon fill=\"black\" stroke=\"black\" points=\"592.11,-95.88 602.7,-95.57 594.23,-89.21 592.11,-95.88\"/>\n", | ||
"</g>\n", | ||
"</g>\n", | ||
"</svg>\n" | ||
], | ||
"text/plain": [ | ||
"<graphviz.dot.Digraph at 0x7f28a138d590>" | ||
] | ||
}, | ||
"execution_count": 10, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"from cadCAD_diagram.config_diagram import diagram\n", | ||
"\n", | ||
"diagram(initial_state, params, psubs)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"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.7.6" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ pathos>=0.2.8 | |
numpy>=1.22.0 | ||
pytz>=2021.1 | ||
setuptools>=69.0.2 | ||
graphviz>=0.20.1 |