Skip to content

Instantly share code, notes, and snippets.

@jonsedar
Last active October 21, 2023 11:07
Show Gist options
  • Save jonsedar/f6d475f67325f3683ac82577baf4119f to your computer and use it in GitHub Desktop.
Save jonsedar/f6d475f67325f3683ac82577baf4119f to your computer and use it in GitHub Desktop.
800_issue_potential_debug
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# 800_issue_potential_debug\n",
"\n",
"Simple model with a **Potential likelihood and Deterministic re-constructed predictions**\n",
"\n",
"Issue: model.debug() errors out"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"# Setup"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Author: jonathan.sedar@oreum.io\n",
"\n",
"Last updated: 2023-10-21 15:06:43\n",
"\n",
"Python implementation: CPython\n",
"Python version : 3.10.12\n",
"IPython version : 8.16.1\n",
"\n",
"pymc : 5.9.0\n",
"pytensor: 2.17.3\n",
"\n",
"Compiler : Clang 15.0.7 \n",
"OS : Darwin\n",
"Release : 22.6.0\n",
"Machine : x86_64\n",
"Processor : i386\n",
"CPU cores : 8\n",
"Architecture: 64bit\n",
"\n"
]
}
],
"source": [
"%load_ext watermark\n",
"%watermark -a \"jonathan.sedar@oreum.io\" -udtmv -iv -p pymc,pytensor"
]
},
{
"cell_type": "code",
"execution_count": 2,
"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 8.1.0 (0)\n",
" -->\n",
"<!-- Pages: 1 -->\n",
"<svg width=\"348pt\" height=\"258pt\"\n",
" viewBox=\"0.00 0.00 348.33 257.93\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
"<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 253.93)\">\n",
"<polygon fill=\"white\" stroke=\"none\" points=\"-4,4 -4,-253.93 344.33,-253.93 344.33,4 -4,4\"/>\n",
"<g id=\"clust1\" class=\"cluster\">\n",
"<title>cluster100</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M20,-8C20,-8 110,-8 110,-8 116,-8 122,-14 122,-20 122,-20 122,-229.93 122,-229.93 122,-235.93 116,-241.93 110,-241.93 110,-241.93 20,-241.93 20,-241.93 14,-241.93 8,-235.93 8,-229.93 8,-229.93 8,-20 8,-20 8,-14 14,-8 20,-8\"/>\n",
"<text text-anchor=\"middle\" x=\"103.88\" y=\"-15.2\" font-family=\"Times,serif\" font-size=\"14.00\">100</text>\n",
"</g>\n",
"<!-- pot_yhat -->\n",
"<g id=\"node1\" class=\"node\">\n",
"<title>pot_yhat</title>\n",
"<polygon fill=\"lightgrey\" stroke=\"black\" points=\"113.98,-66.28 113.98,-102.74 85.29,-128.52 44.71,-128.52 16.02,-102.74 16.02,-66.28 44.71,-40.5 85.29,-40.5 113.98,-66.28\"/>\n",
"<text text-anchor=\"middle\" x=\"65\" y=\"-95.96\" font-family=\"Times,serif\" font-size=\"14.00\">pot_yhat</text>\n",
"<text text-anchor=\"middle\" x=\"65\" y=\"-79.46\" font-family=\"Times,serif\" font-size=\"14.00\">~</text>\n",
"<text text-anchor=\"middle\" x=\"65\" y=\"-62.96\" font-family=\"Times,serif\" font-size=\"14.00\">Potential</text>\n",
"</g>\n",
"<!-- y -->\n",
"<g id=\"node2\" class=\"node\">\n",
"<title>y</title>\n",
"<path fill=\"lightgrey\" stroke=\"black\" d=\"M96.62,-233.93C96.62,-233.93 33.38,-233.93 33.38,-233.93 27.38,-233.93 21.38,-227.93 21.38,-221.93 21.38,-221.93 21.38,-188.43 21.38,-188.43 21.38,-182.43 27.38,-176.43 33.38,-176.43 33.38,-176.43 96.62,-176.43 96.62,-176.43 102.62,-176.43 108.62,-182.43 108.62,-188.43 108.62,-188.43 108.62,-221.93 108.62,-221.93 108.62,-227.93 102.62,-233.93 96.62,-233.93\"/>\n",
"<text text-anchor=\"middle\" x=\"65\" y=\"-216.63\" font-family=\"Times,serif\" font-size=\"14.00\">y</text>\n",
"<text text-anchor=\"middle\" x=\"65\" y=\"-200.13\" font-family=\"Times,serif\" font-size=\"14.00\">~</text>\n",
"<text text-anchor=\"middle\" x=\"65\" y=\"-183.63\" font-family=\"Times,serif\" font-size=\"14.00\">MutableData</text>\n",
"</g>\n",
"<!-- y&#45;&gt;pot_yhat -->\n",
"<g id=\"edge2\" class=\"edge\">\n",
"<title>y&#45;&gt;pot_yhat</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M65,-176.05C65,-165.13 65,-152.24 65,-139.66\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"68.5,-139.75 65,-129.75 61.5,-139.75 68.5,-139.75\"/>\n",
"</g>\n",
"<!-- mu -->\n",
"<g id=\"node3\" class=\"node\">\n",
"<title>mu</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"171\" cy=\"-205.18\" rx=\"41.01\" ry=\"40.66\"/>\n",
"<text text-anchor=\"middle\" x=\"171\" y=\"-216.63\" font-family=\"Times,serif\" font-size=\"14.00\">mu</text>\n",
"<text text-anchor=\"middle\" x=\"171\" y=\"-200.13\" font-family=\"Times,serif\" font-size=\"14.00\">~</text>\n",
"<text text-anchor=\"middle\" x=\"171\" y=\"-183.63\" font-family=\"Times,serif\" font-size=\"14.00\">Normal</text>\n",
"</g>\n",
"<!-- mu&#45;&gt;pot_yhat -->\n",
"<g id=\"edge1\" class=\"edge\">\n",
"<title>mu&#45;&gt;pot_yhat</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M144.25,-174.23C131.61,-160.08 116.31,-142.95 102.53,-127.53\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"105.76,-125.77 96.49,-120.64 100.54,-130.43 105.76,-125.77\"/>\n",
"</g>\n",
"<!-- sigma -->\n",
"<g id=\"node4\" class=\"node\">\n",
"<title>sigma</title>\n",
"<ellipse fill=\"none\" stroke=\"black\" cx=\"285\" cy=\"-205.18\" rx=\"55.33\" ry=\"40.66\"/>\n",
"<text text-anchor=\"middle\" x=\"285\" y=\"-216.63\" font-family=\"Times,serif\" font-size=\"14.00\">sigma</text>\n",
"<text text-anchor=\"middle\" x=\"285\" y=\"-200.13\" font-family=\"Times,serif\" font-size=\"14.00\">~</text>\n",
"<text text-anchor=\"middle\" x=\"285\" y=\"-183.63\" font-family=\"Times,serif\" font-size=\"14.00\">InvGamma</text>\n",
"</g>\n",
"<!-- sigma&#45;&gt;pot_yhat -->\n",
"<g id=\"edge3\" class=\"edge\">\n",
"<title>sigma&#45;&gt;pot_yhat</title>\n",
"<path fill=\"none\" stroke=\"black\" d=\"M243.65,-177.84C236.18,-173.28 228.41,-168.68 221,-164.52 187.8,-145.87 149.69,-126.53 119.44,-111.65\"/>\n",
"<polygon fill=\"black\" stroke=\"black\" points=\"121.44,-108.24 110.92,-106.98 118.36,-114.53 121.44,-108.24\"/>\n",
"</g>\n",
"</g>\n",
"</svg>\n"
],
"text/plain": [
"<graphviz.graphs.Digraph at 0x14d6f26b0>"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import pymc as pm\n",
"\n",
"rng = np.random.default_rng(42)\n",
"n = 100\n",
"y_obs = rng.normal(size=n)\n",
"\n",
"with pm.Model() as mdl:\n",
" y = pm.MutableData('y', y_obs)\n",
" \n",
" mu = pm.Normal('mu', mu=0.0, sigma=1.0)\n",
" sigma = pm.InverseGamma('sigma', alpha=5.0, beta=4.0)\n",
" norm_d = pm.Normal.dist(mu=mu, sigma=sigma, size=n)\n",
" _ = pm.Potential('pot_yhat', pm.logp(norm_d, y))\n",
"\n",
"pm.model_graph.model_to_graphviz(mdl, formatting='plain')\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Quick pass with [`model.debug()`](https://github.com/pymc-devs/pymc/blob/5f29b255127088abc552079fd03c40eb19d83bdd/pymc/model/core.py#L1739)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Random:\n",
"\n",
"point={'mu': array(0.), 'sigma_log__': array(0.)}\n",
"\n",
"No problems found\n",
"\n",
"\n",
"logP:\n",
"\n",
"point={'mu': array(0.), 'sigma_log__': array(0.)}\n",
"\n"
]
},
{
"ename": "ValueError",
"evalue": "Length of pot_yhat cannot be determined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m/Users/jon/workspace/oreum/oreum_lab2/notebooks/800_issue_potential_debug.ipynb Cell 6\u001b[0m line \u001b[0;36m4\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/jon/workspace/oreum/oreum_lab2/notebooks/800_issue_potential_debug.ipynb#X11sZmlsZQ%3D%3D?line=1'>2</a>\u001b[0m mdl\u001b[39m.\u001b[39mdebug(fn\u001b[39m=\u001b[39m\u001b[39m'\u001b[39m\u001b[39mrandom\u001b[39m\u001b[39m'\u001b[39m, verbose\u001b[39m=\u001b[39m\u001b[39mTrue\u001b[39;00m)\n\u001b[1;32m <a href='vscode-notebook-cell:/Users/jon/workspace/oreum/oreum_lab2/notebooks/800_issue_potential_debug.ipynb#X11sZmlsZQ%3D%3D?line=2'>3</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m'\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39mlogP:\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m'\u001b[39m)\n\u001b[0;32m----> <a href='vscode-notebook-cell:/Users/jon/workspace/oreum/oreum_lab2/notebooks/800_issue_potential_debug.ipynb#X11sZmlsZQ%3D%3D?line=3'>4</a>\u001b[0m mdl\u001b[39m.\u001b[39;49mdebug(fn\u001b[39m=\u001b[39;49m\u001b[39m'\u001b[39;49m\u001b[39mlogp\u001b[39;49m\u001b[39m'\u001b[39;49m, verbose\u001b[39m=\u001b[39;49m\u001b[39mTrue\u001b[39;49;00m)\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pymc/model/core.py:1811\u001b[0m, in \u001b[0;36mModel.debug\u001b[0;34m(self, point, fn, verbose)\u001b[0m\n\u001b[1;32m 1809\u001b[0m rvs_to_check \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mbasic_RVs)\n\u001b[1;32m 1810\u001b[0m \u001b[39mif\u001b[39;00m fn \u001b[39min\u001b[39;00m (\u001b[39m\"\u001b[39m\u001b[39mlogp\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mdlogp\u001b[39m\u001b[39m\"\u001b[39m):\n\u001b[0;32m-> 1811\u001b[0m rvs_to_check \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m [\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mreplace_rvs_by_values(p) \u001b[39mfor\u001b[39;00m p \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpotentials]\n\u001b[1;32m 1813\u001b[0m found_problem \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n\u001b[1;32m 1814\u001b[0m \u001b[39mfor\u001b[39;00m rv \u001b[39min\u001b[39;00m rvs_to_check:\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pymc/model/core.py:1811\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 1809\u001b[0m rvs_to_check \u001b[39m=\u001b[39m \u001b[39mlist\u001b[39m(\u001b[39mself\u001b[39m\u001b[39m.\u001b[39mbasic_RVs)\n\u001b[1;32m 1810\u001b[0m \u001b[39mif\u001b[39;00m fn \u001b[39min\u001b[39;00m (\u001b[39m\"\u001b[39m\u001b[39mlogp\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mdlogp\u001b[39m\u001b[39m\"\u001b[39m):\n\u001b[0;32m-> 1811\u001b[0m rvs_to_check \u001b[39m+\u001b[39m\u001b[39m=\u001b[39m [\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mreplace_rvs_by_values(p) \u001b[39mfor\u001b[39;00m p \u001b[39min\u001b[39;00m \u001b[39mself\u001b[39m\u001b[39m.\u001b[39mpotentials]\n\u001b[1;32m 1813\u001b[0m found_problem \u001b[39m=\u001b[39m \u001b[39mFalse\u001b[39;00m\n\u001b[1;32m 1814\u001b[0m \u001b[39mfor\u001b[39;00m rv \u001b[39min\u001b[39;00m rvs_to_check:\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pymc/model/core.py:1541\u001b[0m, in \u001b[0;36mModel.replace_rvs_by_values\u001b[0;34m(self, graphs, **kwargs)\u001b[0m\n\u001b[1;32m 1527\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mreplace_rvs_by_values\u001b[39m(\n\u001b[1;32m 1528\u001b[0m \u001b[39mself\u001b[39m,\n\u001b[1;32m 1529\u001b[0m graphs: Sequence[TensorVariable],\n\u001b[1;32m 1530\u001b[0m \u001b[39m*\u001b[39m\u001b[39m*\u001b[39mkwargs,\n\u001b[1;32m 1531\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m List[TensorVariable]:\n\u001b[1;32m 1532\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"Clone and replace random variables in graphs with their value variables.\u001b[39;00m\n\u001b[1;32m 1533\u001b[0m \n\u001b[1;32m 1534\u001b[0m \u001b[39m This will *not* recompute test values in the resulting graphs.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 1539\u001b[0m \u001b[39m The graphs in which to perform the replacements.\u001b[39;00m\n\u001b[1;32m 1540\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m-> 1541\u001b[0m \u001b[39mreturn\u001b[39;00m replace_rvs_by_values(\n\u001b[1;32m 1542\u001b[0m graphs,\n\u001b[1;32m 1543\u001b[0m rvs_to_values\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mrvs_to_values,\n\u001b[1;32m 1544\u001b[0m rvs_to_transforms\u001b[39m=\u001b[39;49m\u001b[39mself\u001b[39;49m\u001b[39m.\u001b[39;49mrvs_to_transforms,\n\u001b[1;32m 1545\u001b[0m )\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pymc/pytensorf.py:356\u001b[0m, in \u001b[0;36mreplace_rvs_by_values\u001b[0;34m(graphs, rvs_to_values, rvs_to_transforms, **kwargs)\u001b[0m\n\u001b[1;32m 341\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Clone and replace random variables in graphs with their value variables.\u001b[39;00m\n\u001b[1;32m 342\u001b[0m \n\u001b[1;32m 343\u001b[0m \u001b[39mThis will *not* recompute test values in the resulting graphs.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 352\u001b[0m \u001b[39m Mapping between the original graph RVs and respective value transforms\u001b[39;00m\n\u001b[1;32m 353\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 355\u001b[0m \u001b[39m# Clone original graphs so that we don't modify variables in place\u001b[39;00m\n\u001b[0;32m--> 356\u001b[0m inputs \u001b[39m=\u001b[39m [i \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m graph_inputs(graphs) \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(i, Constant)]\n\u001b[1;32m 357\u001b[0m equiv \u001b[39m=\u001b[39m clone_get_equiv(inputs, graphs, \u001b[39mFalse\u001b[39;00m, \u001b[39mFalse\u001b[39;00m, {})\n\u001b[1;32m 358\u001b[0m graphs \u001b[39m=\u001b[39m [equiv[n] \u001b[39mfor\u001b[39;00m n \u001b[39min\u001b[39;00m graphs]\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pymc/pytensorf.py:356\u001b[0m, in \u001b[0;36m<listcomp>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 341\u001b[0m \u001b[39m\u001b[39m\u001b[39m\"\"\"Clone and replace random variables in graphs with their value variables.\u001b[39;00m\n\u001b[1;32m 342\u001b[0m \n\u001b[1;32m 343\u001b[0m \u001b[39mThis will *not* recompute test values in the resulting graphs.\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 352\u001b[0m \u001b[39m Mapping between the original graph RVs and respective value transforms\u001b[39;00m\n\u001b[1;32m 353\u001b[0m \u001b[39m\"\"\"\u001b[39;00m\n\u001b[1;32m 355\u001b[0m \u001b[39m# Clone original graphs so that we don't modify variables in place\u001b[39;00m\n\u001b[0;32m--> 356\u001b[0m inputs \u001b[39m=\u001b[39m [i \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m graph_inputs(graphs) \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39misinstance\u001b[39m(i, Constant)]\n\u001b[1;32m 357\u001b[0m equiv \u001b[39m=\u001b[39m clone_get_equiv(inputs, graphs, \u001b[39mFalse\u001b[39;00m, \u001b[39mFalse\u001b[39;00m, {})\n\u001b[1;32m 358\u001b[0m graphs \u001b[39m=\u001b[39m [equiv[n] \u001b[39mfor\u001b[39;00m n \u001b[39min\u001b[39;00m graphs]\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pytensor/graph/basic.py:919\u001b[0m, in \u001b[0;36mgraph_inputs\u001b[0;34m(graphs, blockers)\u001b[0m\n\u001b[1;32m 899\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mgraph_inputs\u001b[39m(\n\u001b[1;32m 900\u001b[0m graphs: Iterable[Variable], blockers: Optional[Collection[Variable]] \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 901\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Generator[Variable, \u001b[39mNone\u001b[39;00m, \u001b[39mNone\u001b[39;00m]:\n\u001b[1;32m 902\u001b[0m \u001b[39m \u001b[39m\u001b[39mr\u001b[39m\u001b[39m\"\"\"Return the inputs required to compute the given Variables.\u001b[39;00m\n\u001b[1;32m 903\u001b[0m \n\u001b[1;32m 904\u001b[0m \u001b[39m Parameters\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 917\u001b[0m \n\u001b[1;32m 918\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 919\u001b[0m \u001b[39myield from\u001b[39;00m (r \u001b[39mfor\u001b[39;00m r \u001b[39min\u001b[39;00m ancestors(graphs, blockers) \u001b[39mif\u001b[39;00m r\u001b[39m.\u001b[39mowner \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m)\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pytensor/graph/basic.py:919\u001b[0m, in \u001b[0;36m<genexpr>\u001b[0;34m(.0)\u001b[0m\n\u001b[1;32m 899\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mgraph_inputs\u001b[39m(\n\u001b[1;32m 900\u001b[0m graphs: Iterable[Variable], blockers: Optional[Collection[Variable]] \u001b[39m=\u001b[39m \u001b[39mNone\u001b[39;00m\n\u001b[1;32m 901\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Generator[Variable, \u001b[39mNone\u001b[39;00m, \u001b[39mNone\u001b[39;00m]:\n\u001b[1;32m 902\u001b[0m \u001b[39m \u001b[39m\u001b[39mr\u001b[39m\u001b[39m\"\"\"Return the inputs required to compute the given Variables.\u001b[39;00m\n\u001b[1;32m 903\u001b[0m \n\u001b[1;32m 904\u001b[0m \u001b[39m Parameters\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 917\u001b[0m \n\u001b[1;32m 918\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 919\u001b[0m \u001b[39myield from\u001b[39;00m (r \u001b[39mfor\u001b[39;00m r \u001b[39min\u001b[39;00m ancestors(graphs, blockers) \u001b[39mif\u001b[39;00m r\u001b[39m.\u001b[39mowner \u001b[39mis\u001b[39;00m \u001b[39mNone\u001b[39;00m)\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pytensor/graph/basic.py:896\u001b[0m, in \u001b[0;36mancestors\u001b[0;34m(graphs, blockers)\u001b[0m\n\u001b[1;32m 893\u001b[0m \u001b[39mif\u001b[39;00m r\u001b[39m.\u001b[39mowner \u001b[39mand\u001b[39;00m (\u001b[39mnot\u001b[39;00m blockers \u001b[39mor\u001b[39;00m r \u001b[39mnot\u001b[39;00m \u001b[39min\u001b[39;00m blockers):\n\u001b[1;32m 894\u001b[0m \u001b[39mreturn\u001b[39;00m \u001b[39mreversed\u001b[39m(r\u001b[39m.\u001b[39mowner\u001b[39m.\u001b[39minputs)\n\u001b[0;32m--> 896\u001b[0m \u001b[39myield from\u001b[39;00m cast(Generator[Variable, \u001b[39mNone\u001b[39;00m, \u001b[39mNone\u001b[39;00m], walk(graphs, expand, \u001b[39mFalse\u001b[39;00m))\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pytensor/graph/basic.py:841\u001b[0m, in \u001b[0;36mwalk\u001b[0;34m(nodes, expand, bfs, return_children, hash_fn)\u001b[0m\n\u001b[1;32m 808\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39mwalk\u001b[39m(\n\u001b[1;32m 809\u001b[0m nodes: Iterable[T],\n\u001b[1;32m 810\u001b[0m expand: Callable[[T], Optional[Iterable[T]]],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 813\u001b[0m hash_fn: Callable[[T], \u001b[39mint\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mid\u001b[39m,\n\u001b[1;32m 814\u001b[0m ) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m Generator[Union[T, NodeAndChildren], \u001b[39mNone\u001b[39;00m, \u001b[39mNone\u001b[39;00m]:\n\u001b[1;32m 815\u001b[0m \u001b[39m \u001b[39m\u001b[39mr\u001b[39m\u001b[39m\"\"\"Walk through a graph, either breadth- or depth-first.\u001b[39;00m\n\u001b[1;32m 816\u001b[0m \n\u001b[1;32m 817\u001b[0m \u001b[39m Parameters\u001b[39;00m\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 838\u001b[0m \n\u001b[1;32m 839\u001b[0m \u001b[39m \"\"\"\u001b[39;00m\n\u001b[0;32m--> 841\u001b[0m nodes \u001b[39m=\u001b[39m deque(nodes)\n\u001b[1;32m 843\u001b[0m rval_set: Set[\u001b[39mint\u001b[39m] \u001b[39m=\u001b[39m \u001b[39mset\u001b[39m()\n\u001b[1;32m 845\u001b[0m nodes_pop: Callable[[], T]\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pytensor/tensor/variable.py:611\u001b[0m, in \u001b[0;36m_tensor_py_operators.__iter__\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 609\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m__iter__\u001b[39m(\u001b[39mself\u001b[39m):\n\u001b[1;32m 610\u001b[0m \u001b[39mtry\u001b[39;00m:\n\u001b[0;32m--> 611\u001b[0m \u001b[39mfor\u001b[39;00m i \u001b[39min\u001b[39;00m \u001b[39mrange\u001b[39m(at\u001b[39m.\u001b[39;49mbasic\u001b[39m.\u001b[39;49mget_vector_length(\u001b[39mself\u001b[39;49m)):\n\u001b[1;32m 612\u001b[0m \u001b[39myield\u001b[39;00m \u001b[39mself\u001b[39m[i]\n\u001b[1;32m 613\u001b[0m \u001b[39mexcept\u001b[39;00m \u001b[39mTypeError\u001b[39;00m:\n\u001b[1;32m 614\u001b[0m \u001b[39m# This prevents accidental iteration via sum(self)\u001b[39;00m\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pytensor/tensor/__init__.py:87\u001b[0m, in \u001b[0;36mget_vector_length\u001b[0;34m(v)\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[39mif\u001b[39;00m static_shape \u001b[39mis\u001b[39;00m \u001b[39mnot\u001b[39;00m \u001b[39mNone\u001b[39;00m:\n\u001b[1;32m 85\u001b[0m \u001b[39mreturn\u001b[39;00m static_shape\n\u001b[0;32m---> 87\u001b[0m \u001b[39mreturn\u001b[39;00m _get_vector_length(\u001b[39mgetattr\u001b[39;49m(v\u001b[39m.\u001b[39;49mowner, \u001b[39m\"\u001b[39;49m\u001b[39mop\u001b[39;49m\u001b[39m\"\u001b[39;49m, v), v)\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/functools.py:889\u001b[0m, in \u001b[0;36msingledispatch.<locals>.wrapper\u001b[0;34m(*args, **kw)\u001b[0m\n\u001b[1;32m 885\u001b[0m \u001b[39mif\u001b[39;00m \u001b[39mnot\u001b[39;00m args:\n\u001b[1;32m 886\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mTypeError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m'\u001b[39m\u001b[39m{\u001b[39;00mfuncname\u001b[39m}\u001b[39;00m\u001b[39m requires at least \u001b[39m\u001b[39m'\u001b[39m\n\u001b[1;32m 887\u001b[0m \u001b[39m'\u001b[39m\u001b[39m1 positional argument\u001b[39m\u001b[39m'\u001b[39m)\n\u001b[0;32m--> 889\u001b[0m \u001b[39mreturn\u001b[39;00m dispatch(args[\u001b[39m0\u001b[39;49m]\u001b[39m.\u001b[39;49m\u001b[39m__class__\u001b[39;49m)(\u001b[39m*\u001b[39;49margs, \u001b[39m*\u001b[39;49m\u001b[39m*\u001b[39;49mkw)\n",
"File \u001b[0;32m~/miniforge/envs/oreum_lab2/lib/python3.10/site-packages/pytensor/tensor/__init__.py:93\u001b[0m, in \u001b[0;36m_get_vector_length\u001b[0;34m(op, var)\u001b[0m\n\u001b[1;32m 90\u001b[0m \u001b[39m@singledispatch\u001b[39m\n\u001b[1;32m 91\u001b[0m \u001b[39mdef\u001b[39;00m \u001b[39m_get_vector_length\u001b[39m(op: Union[Op, Variable], var: Variable) \u001b[39m-\u001b[39m\u001b[39m>\u001b[39m \u001b[39mint\u001b[39m:\n\u001b[1;32m 92\u001b[0m \u001b[39m \u001b[39m\u001b[39m\"\"\"`Op`-based dispatch for `get_vector_length`.\"\"\"\u001b[39;00m\n\u001b[0;32m---> 93\u001b[0m \u001b[39mraise\u001b[39;00m \u001b[39mValueError\u001b[39;00m(\u001b[39mf\u001b[39m\u001b[39m\"\u001b[39m\u001b[39mLength of \u001b[39m\u001b[39m{\u001b[39;00mvar\u001b[39m}\u001b[39;00m\u001b[39m cannot be determined\u001b[39m\u001b[39m\"\u001b[39m)\n",
"\u001b[0;31mValueError\u001b[0m: Length of pot_yhat cannot be determined"
]
}
],
"source": [
"print('Random:\\n')\n",
"mdl.debug(fn='random', verbose=True)\n",
"print('\\n\\nlogP:\\n')\n",
"mdl.debug(fn='logp', verbose=True)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "oreum_lab",
"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.10.12"
},
"pycharm": {
"stem_cell": {
"cell_type": "raw",
"metadata": {
"collapsed": false
},
"source": []
}
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": true,
"sideBar": true,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": true,
"toc_window_display": false
},
"vscode": {
"interpreter": {
"hash": "8a5edab282632443219e051e4ade2d1d5bbc671c781051bf1437897cbdfea0f1"
}
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment