Skip to content

Commit

Permalink
A possible solution to the problem
Browse files Browse the repository at this point in the history
  • Loading branch information
twomagpi committed Sep 2, 2024
1 parent 3b50be7 commit bbd0854
Showing 1 changed file with 101 additions and 4 deletions.
105 changes: 101 additions & 4 deletions notebooks/sympy_bug_hunt.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"{t, N, S, I, beta}\n"
"{S, t, I, beta, N}\n"
]
}
],
Expand Down Expand Up @@ -188,11 +188,108 @@
"print(state in eqn.free_symbols)\n",
"print(sympy.diff(eqn, state))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n"
]
}
],
"source": [
"# So I think this is because the t used in eqn is new (created in the check equantion function)\n",
"# but the t we want is model._t which gets into _pramDict in line 97 of base_ode_model.py\n",
"print(model._paramDict['t'] == model._t)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"# which as before is _not_ in the equation\n",
"print(model._t in eqn.free_symbols)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/latex": [
"$\\displaystyle t$"
],
"text/plain": [
"t"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# So lets get the t in the equation and replace it with model_t\n",
"\n",
"# can't index sets\n",
"eqn_t = [symb for symb in eqn.free_symbols if str(symb)=='t'][0]\n",
"eqn_t"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"# A little bit of light substitution\n",
"new_eqn = eqn.subs(eqn_t, model._t)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"t\n",
"True\n",
"-0.62172*I*S*beta*sin(0.628*t)/N\n"
]
}
],
"source": [
"# Lets try that again\n",
"state=model._paramDict['t']\n",
"print(state)\n",
"print(state in new_eqn.free_symbols)\n",
"print(sympy.diff(new_eqn, state))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "pygom_19",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -206,9 +303,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit bbd0854

Please sign in to comment.