Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeldeistler committed Nov 3, 2023
1 parent 3046bf7 commit 6a1f70a
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 29 deletions.
2 changes: 1 addition & 1 deletion neurax/modules/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def show(
self.view, channel_name, indices, params, states
)

def set_global_index_and_index(nodes):
def set_global_index_and_index(self, nodes):
"""Use the global compartment, branch, and cell index as the index."""
nodes = nodes.drop("controlled_by_param", axis=1)
nodes = nodes.drop("comp_index", axis=1)
Expand Down
6 changes: 3 additions & 3 deletions neurax/modules/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ def __getattr__(self, key):

if key == "comp":
view = deepcopy(self.nodes)
view["original_comp_index"] = view["comp_index"]
view["original_branch_index"] = view["branch_index"]
view["original_cell_index"] = view["cell_index"]
view["global_comp_index"] = view["comp_index"]
view["global_branch_index"] = view["branch_index"]
view["global_cell_index"] = view["cell_index"]
return CompartmentView(self, view)
elif key in self.group_views:
return self.group_views[key]
Expand Down
6 changes: 3 additions & 3 deletions neurax/modules/cell.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ def __getattr__(self, key):

if key == "branch":
view = deepcopy(self.nodes)
view["original_comp_index"] = view["comp_index"]
view["original_branch_index"] = view["branch_index"]
view["original_cell_index"] = view["cell_index"]
view["global_comp_index"] = view["comp_index"]
view["global_branch_index"] = view["branch_index"]
view["global_cell_index"] = view["cell_index"]
return BranchView(self, view)
elif key in self.group_views:
return self.group_views[key]
Expand Down
6 changes: 3 additions & 3 deletions neurax/modules/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ def __getattr__(self, key):

if key == "cell":
view = deepcopy(self.nodes)
view["original_comp_index"] = view["comp_index"]
view["original_branch_index"] = view["branch_index"]
view["original_cell_index"] = view["cell_index"]
view["global_comp_index"] = view["comp_index"]
view["global_branch_index"] = view["branch_index"]
view["global_cell_index"] = view["cell_index"]
return CellView(self, view)
elif key in self.synapse_names:
return SynapseView(self, self.syn_edges, key)
Expand Down
205 changes: 186 additions & 19 deletions tutorials/01_small_network.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 58,
"id": "0e225f21",
"metadata": {},
"outputs": [],
Expand All @@ -76,7 +76,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 59,
"id": "9b671afc",
"metadata": {},
"outputs": [],
Expand All @@ -94,7 +94,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 60,
"id": "9819bbf4",
"metadata": {},
"outputs": [],
Expand All @@ -105,7 +105,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 61,
"id": "e89ededa-18ed-4184-860d-93c59e653201",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -135,7 +135,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 62,
"id": "70c241e7",
"metadata": {},
"outputs": [],
Expand All @@ -147,7 +147,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 63,
"id": "564e96a7",
"metadata": {},
"outputs": [],
Expand All @@ -165,7 +165,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 64,
"id": "22f304f0",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -198,7 +198,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 65,
"id": "e277f94b",
"metadata": {},
"outputs": [],
Expand All @@ -208,7 +208,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 66,
"id": "f2129ef3",
"metadata": {},
"outputs": [],
Expand All @@ -229,7 +229,7 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": 67,
"id": "1dffee93",
"metadata": {},
"outputs": [],
Expand All @@ -247,7 +247,7 @@
},
{
"cell_type": "code",
"execution_count": 28,
"execution_count": 68,
"id": "1c989a32",
"metadata": {},
"outputs": [],
Expand All @@ -265,7 +265,7 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": null,
"id": "d6d4d560",
"metadata": {},
"outputs": [],
Expand All @@ -288,16 +288,183 @@
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 56,
"id": "ae789787-226f-463e-a3a0-b80a26026489",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>original_comp_index</th>\n",
" <th>original_branch_index</th>\n",
" <th>original_cell_index</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>7</th>\n",
" <td>7</td>\n",
" <td>0</td>\n",
" <td>0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>127</th>\n",
" <td>127</td>\n",
" <td>15</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>247</th>\n",
" <td>247</td>\n",
" <td>30</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>367</th>\n",
" <td>367</td>\n",
" <td>45</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>487</th>\n",
" <td>487</td>\n",
" <td>60</td>\n",
" <td>4</td>\n",
" </tr>\n",
" <tr>\n",
" <th>607</th>\n",
" <td>607</td>\n",
" <td>75</td>\n",
" <td>5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>727</th>\n",
" <td>727</td>\n",
" <td>90</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>847</th>\n",
" <td>847</td>\n",
" <td>105</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>967</th>\n",
" <td>967</td>\n",
" <td>120</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1087</th>\n",
" <td>1087</td>\n",
" <td>135</td>\n",
" <td>9</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1207</th>\n",
" <td>1207</td>\n",
" <td>150</td>\n",
" <td>10</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1327</th>\n",
" <td>1327</td>\n",
" <td>165</td>\n",
" <td>11</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1447</th>\n",
" <td>1447</td>\n",
" <td>180</td>\n",
" <td>12</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1567</th>\n",
" <td>1567</td>\n",
" <td>195</td>\n",
" <td>13</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1687</th>\n",
" <td>1687</td>\n",
" <td>210</td>\n",
" <td>14</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1807</th>\n",
" <td>1807</td>\n",
" <td>225</td>\n",
" <td>15</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" original_comp_index original_branch_index original_cell_index\n",
"7 7 0 0\n",
"127 127 15 1\n",
"247 247 30 2\n",
"367 367 45 3\n",
"487 487 60 4\n",
"607 607 75 5\n",
"727 727 90 6\n",
"847 847 105 7\n",
"967 967 120 8\n",
"1087 1087 135 9\n",
"1207 1207 150 10\n",
"1327 1327 165 11\n",
"1447 1447 180 12\n",
"1567 1567 195 13\n",
"1687 1687 210 14\n",
"1807 1807 225 15"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"network.recordings"
]
},
{
"cell_type": "code",
"execution_count": 57,
"id": "26e7b8dc",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"CPU times: user 6.87 s, sys: 59.6 ms, total: 6.93 s\n",
"Wall time: 6.99 s\n"
"ename": "AttributeError",
"evalue": "'DataFrame' object has no attribute 'comp_index'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<timed exec>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n",
"\u001b[0;32m~/Documents/PhD/neurax/neurax/integrate.py\u001b[0m in \u001b[0;36mintegrate\u001b[0;34m(module, stimuli, params, t_max, delta_t, solver, tridiag_solver, checkpoint_lengths)\u001b[0m\n\u001b[1;32m 45\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0mi_current\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mi_inds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mprepare_stim\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmodule\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mstimuli\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 47\u001b[0;31m \u001b[0mrec_inds\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mmodule\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrecordings\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcomp_index\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mto_numpy\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 48\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 49\u001b[0m \u001b[0;31m# Shorten or pad stimulus depending on `t_max`.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;32m~/anaconda3/envs/jax/lib/python3.8/site-packages/pandas/core/generic.py\u001b[0m in \u001b[0;36m__getattr__\u001b[0;34m(self, name)\u001b[0m\n\u001b[1;32m 5987\u001b[0m ):\n\u001b[1;32m 5988\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 5989\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mobject\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__getattribute__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 5990\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5991\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__setattr__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mname\u001b[0m\u001b[0;34m:\u001b[0m \u001b[0mstr\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mvalue\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m->\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mAttributeError\u001b[0m: 'DataFrame' object has no attribute 'comp_index'"
]
}
],
Expand Down Expand Up @@ -359,7 +526,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": null,
"id": "42fd990f-ee7d-45da-bf6a-717fb573c134",
"metadata": {},
"outputs": [
Expand Down

0 comments on commit 6a1f70a

Please sign in to comment.