From 144a59c3709b94470d0445064602df74e2bd0b4a Mon Sep 17 00:00:00 2001 From: Michael Deistler Date: Fri, 3 Nov 2023 16:33:32 +0100 Subject: [PATCH] bugfix --- neurax/modules/base.py | 2 +- neurax/modules/branch.py | 6 +- neurax/modules/cell.py | 6 +- neurax/modules/network.py | 6 +- tutorials/01_small_network.ipynb | 205 ++++++++++++++++++++++++++++--- 5 files changed, 196 insertions(+), 29 deletions(-) diff --git a/neurax/modules/base.py b/neurax/modules/base.py index 593bf0cc..cd03922b 100644 --- a/neurax/modules/base.py +++ b/neurax/modules/base.py @@ -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) diff --git a/neurax/modules/branch.py b/neurax/modules/branch.py index c179a580..9f31e321 100644 --- a/neurax/modules/branch.py +++ b/neurax/modules/branch.py @@ -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] diff --git a/neurax/modules/cell.py b/neurax/modules/cell.py index 54bcbe0d..4c34ad65 100644 --- a/neurax/modules/cell.py +++ b/neurax/modules/cell.py @@ -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] diff --git a/neurax/modules/network.py b/neurax/modules/network.py index d6c19a5b..7f78f29d 100644 --- a/neurax/modules/network.py +++ b/neurax/modules/network.py @@ -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) diff --git a/tutorials/01_small_network.ipynb b/tutorials/01_small_network.ipynb index 807a7e15..e737bf89 100644 --- a/tutorials/01_small_network.ipynb +++ b/tutorials/01_small_network.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 58, "id": "0e225f21", "metadata": {}, "outputs": [], @@ -76,7 +76,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 59, "id": "9b671afc", "metadata": {}, "outputs": [], @@ -94,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 60, "id": "9819bbf4", "metadata": {}, "outputs": [], @@ -105,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 61, "id": "e89ededa-18ed-4184-860d-93c59e653201", "metadata": {}, "outputs": [], @@ -135,7 +135,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 62, "id": "70c241e7", "metadata": {}, "outputs": [], @@ -147,7 +147,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 63, "id": "564e96a7", "metadata": {}, "outputs": [], @@ -165,7 +165,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 64, "id": "22f304f0", "metadata": {}, "outputs": [ @@ -198,7 +198,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 65, "id": "e277f94b", "metadata": {}, "outputs": [], @@ -208,7 +208,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 66, "id": "f2129ef3", "metadata": {}, "outputs": [], @@ -229,7 +229,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 67, "id": "1dffee93", "metadata": {}, "outputs": [], @@ -247,7 +247,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 68, "id": "1c989a32", "metadata": {}, "outputs": [], @@ -265,7 +265,7 @@ }, { "cell_type": "code", - "execution_count": 29, + "execution_count": null, "id": "d6d4d560", "metadata": {}, "outputs": [], @@ -288,16 +288,183 @@ }, { "cell_type": "code", - "execution_count": 37, + "execution_count": 56, + "id": "ae789787-226f-463e-a3a0-b80a26026489", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
original_comp_indexoriginal_branch_indexoriginal_cell_index
7700
127127151
247247302
367367453
487487604
607607755
727727906
8478471057
9679671208
108710871359
1207120715010
1327132716511
1447144718012
1567156719513
1687168721014
1807180722515
\n", + "
" + ], + "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\u001b[0m in \u001b[0;36m\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'" ] } ], @@ -359,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": 38, + "execution_count": null, "id": "42fd990f-ee7d-45da-bf6a-717fb573c134", "metadata": {}, "outputs": [