Unexpected merging behavior in utils.connect() #647
-
Hello Jaxley community: I was connecting pre and post synaptic sites and wrote code like this pre = net.cell(range(len(synapse_locations))).branch(0).loc(0.5)
branches, locs = zip(*synapse_locations)
# all connect to last cell of net
post = net.cell(len(synapse_locations)).branch(list(branches)).loc(list(locs))
connect(pre, post, AlphaSynapse()) But got error saying I am wondering if there is any merging behavior of pre/post views that caused this error as the code seems quite self-contained. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hey! Thanks for starting this discussion! TL;DR: you can fix it as follows: import pandas as pd
filtered_nodes = pd.concat(
[net.cell(len(synapse_locations)).branch(b).loc(l).nodes for b, l in zip(branches, locs)]
)
post = net.select(nodes=filtered_nodes.index) Longer explanationThe reason that this is failing is that you are trying to match pairs of ncomp = 2
comp = jx.Compartment()
branch = jx.Branch(comp, ncomp)
cell = jx.Cell(branch, [-1, 0, 0, 1, 1])
branches = [0, 1]
locs = [0.1, 0.9]
cell.branch(branches).loc(locs).nodes # Display the nodes in a jupyter notebook. This will show four rows. Why? If you want to match pairs of filtered_nodes = pd.concat(
[net.cell(len(synapse_locations)).branch(b).loc(l).nodes for b, l in zip(branches, locs)]
) Does this make sense? Self-contained exampleFor future reference, here is a self-contained example: import pandas as pd
import jaxley as jx
from jaxley.synapses import IonotropicSynapse
from jaxley.connect import connect
ncomp = 2
comp = jx.Compartment()
branch = jx.Branch(comp, ncomp)
cell = jx.Cell(branch, [-1, 0, 0, 1, 1])
net = jx.Network([cell, cell, cell, cell])
branches = [0, 1, 2]
locs = [0.1, 0.9, 0.9]
pre = net.cell(range(len(branches))).branch(0).loc(0.5)
filtered_nodes = pd.concat(
[net.cell(len(branches)).branch(b).loc(l).nodes for b, l in zip(branches, locs)]
)
post = net.select(nodes=filtered_nodes.index)
connect(pre, post, IonotropicSynapse()) Michael |
Beta Was this translation helpful? Give feedback.
-
I see, thank you for the solution and explanation of the dimension mismatch! |
Beta Was this translation helpful? Give feedback.
Hey! Thanks for starting this discussion!
TL;DR: you can fix it as follows:
Longer explanation
The reason that this is failing is that you are trying to match pairs of
branches
andlocs
at the same time. This is, by default, not supported. To see what is going wrong, consider the following: