-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for graph operations #355
base: main
Are you sure you want to change the base?
Conversation
Currently I have only implemented comp = jx.Compartment()
branch = jx.Branch([comp for _ in range(4)])
cell = jx.Cell([branch for _ in range(5)], parents=jnp.asarray([-1, 0, 1, 2, 2]))
net = jx.Network([cell]*3)
connect(net[0,0,0], net[1,0,0], IonotropicSynapse())
connect(net[0,0,1], net[1,0,1], IonotropicSynapse())
connect(net[0,0,1], net[1,0,1], TestSynapse())
net.cell(2).add_to_group("cell2")
net.cell(2).branch(1).add_to_group("cell2brach1")
net.cell(0).insert(Na())
net.cell(0).insert(Leak())
net.cell(1).branch(1).insert(Na())
net.cell(0).insert(K())
net.compute_xyz()
net.cell(0).branch(0).loc(0.0).record()
net.cell(0).branch(0).loc(0.0).record("m")
current = jx.step_current(i_delay, i_dur, i_amp, dt, t_max)
net.cell(0).branch(2).loc(0.0).stimulate(current)
net.cell(0).branch(1).make_trainable("Na")
net.cell(1).make_trainable("K")
net.compute_xyz()
net.cell(1).move(0,30,0)
net.cell(2).move(0,-30,0) we can just module_graph = net.to_graph()
# plot the graph
pos = {i: (n["x"], n["y"]) for i, n in module_graph.nodes(data=True)}
plt.figure(figsize=(8, 8))
nx.draw(module_graph, pos, with_labels=True, node_size=200, node_color="skyblue", font_size=8, font_weight="bold", font_color="black", font_family="sans-serif")
plt.show() and look at all its properties, i.e. checking out the soma (0) and the synapse going from node 0 to node 20 print(module_graph.nodes[0])
print(module_graph.edges[(0,20)])
|
Both |
jaxley/modules/base.py
Outdated
trainable_params = {i: {} for i in trainable_inds} | ||
for i in trainable_inds: | ||
for inds, params in zip( | ||
self.indices_set_by_trainables, self.trainable_params |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaeldeistler is there a scenario where there is more than one default value for an item in Module.trainable_params
? I.e. the items are all dicts of form {"Na_gNa": np.array([0.1])}
I think. Additionally, is there a case where there is more than one entry in the dict?"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I just saw you can have multiple defaults, this code is wrong then.
But you cannot have multiple keys correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, you cannot have multiple keys.
tutorials/dev.ipynb
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignore this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will do a more thorough review on Monday, but for now: I really like that the methods are standalone. I guess in the long run we would try to use from_graph
also for reading SWC readers?
Yes, as mentioned in the PR desc, reading swc to graph is the plan. |
Potential use-case of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It took way more time than I would have suspected or liked to spend and two mayor iterations, but its finally mostly there! Both export and import from/to graph are working now and also the swc pipeline passes the tests now. Some more tests and cleanup, but then I think you can do a review @michaeldeistler. Small benefit of this PR is also that it reduces the difference of jaxley and NEURON very slightly (by about 20%). |
TLDR: I think I have a working version of the graph pipeline now, but tests are still not passing and I don't quite no why. Everything looks good to me. Help is much appreciated! I have been trying for ages to get graph = swc_to_graph(fname)
cell = from_graph(graph, nseg=8, max_branch_len=2000.0) reads an swc file into a networkx graph and imports the cell into jaxley. As part of While this all looks very promising, I have struggled to get the tests passing and I really dont know why: While they look very similar, they are all slightly delayed. The MSEs also show this.
Would really appreciate help. I will now be moving on to sth else for the moment though, so it is not urgent. Best, Jonas |
26432b5
to
c2bcb26
Compare
a1b70d8
to
fddb19a
Compare
0bb338c
to
e0e3f2a
Compare
I think this is finally ready for a first round of reviews. This has become quite the mammoth PR, but the functionality it enables is neat imo. For a rundown see the updated 08_morphologies.ipynb All tests are passing now, which turned out to be an immense amount of work, but the imported morphologies are similar enough to NEURON both at the compartment level (x,y,z,r,l) and they also simulate correctly. I have essentially cloned the tests in Notable changes are:
Lemme know your thoughts. Would also be happy to go through this in person. |
Just noting that in the branch It is a branch from this branch at the current stage. |
…ebook but not in pytest
fac9e23
to
53895a4
Compare
Here is a little update on the current state of the PR:
Also added an updated tutorial. |
This PR adds support for graph methods. It implements a
to_graph
andfrom_graph
method in module.Todos:
to_graph
to_graph
from_graph
from_graph
- [ ] ensure it works for views and modules, with MakeView
behave more likeModule
#351, this should be straight forward..swc
->nx.DiGraph
->Cell
functionalityThoughts I had while coding this up:
self.nodes
andself.edges
from it.attrs
from inmodule.edges
,module.branch_edges
andmodule.nodes
, are stored as node / edge attrs in theDiGraph
, this could also be used for plotting or invis
.DiGraph.graph
,DiGraph.nodes
,DiGraph.edges
, this could also be used to save and share modules.module.nodes
, not sure if onegroup
column that contains lists of groups or several boolean cols withgroup_name
is the better solution.View
behave more likeModule
#351 is merged, since this implements all properties that are attached to the nodes / edges for views of modules.EDIT: