Skip to content
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

.connect() and fully_connect() methods #197

Merged
merged 12 commits into from
Dec 12, 2023
Merged

.connect() and fully_connect() methods #197

merged 12 commits into from
Dec 12, 2023

Conversation

michaeldeistler
Copy link
Contributor

@michaeldeistler michaeldeistler commented Dec 11, 2023

Closes #180. FYI @jnsbck @kyralianaka @lappalainenj

Single connections

Following the API of NEURON, this PR implements the following:

net = Network(cells)

pre = net.cell(0).branch(0).comp(0.0)
post = net.cell(1).branch(0).comp(0.0)
pre.connect(post, GlutamateSynapse())

which is equivalent to:

connectivities = [
    [GlutamateSynapse(), [jx.Connection(0, 0, 0.0, 1, 0, 0.0)]]
]

net = Network(cells, connectivities)

Fully (or sparsely) connected layers

net = Network(cells)

pre = net.cell([0, 1, 2])
post = net.cell([3, 4])
pre.fully_connect(post, GlutamateSynapse())

p = 0.2  # Connection probability
pre.sparse_connect(post, p, GlutamateSynapse())

Copy link
Contributor

@lappalainenj lappalainenj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Minor suggestions for improvement in inline comments.

def connect(self, post: "CompartmentView", synapse_type):
"""Connect two compartments with a chemical synapse."""
synapse_name = type(synapse_type).__name__
is_new_type = True if synapse_name not in self.pointer.synapse_names else False
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would start with a short paragraph as a comment describing the implementation strategy to scaffold the information for any dev, reviewer, user.

# High-level strategy
# We need to first check if the compartment [branch, cell, network ?] already has a type of this synapse, else we need to register it as a new synapse in a bunch of dictionaries which track synapse parameters, state and meta information [Is this correctly inferred from the code?]. 
# Next, we register the new connection in the synapse dataframe.
# Then, we update synapse parameter and state arrays with the new connection.
# Finally, we update synapse meta information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, copied it almost verbatim into the docstring. And yes, your description is correctly inferred from the code.

jaxley/modules/compartment.py Outdated Show resolved Hide resolved
jaxley/modules/compartment.py Outdated Show resolved Hide resolved
jaxley/modules/compartment.py Outdated Show resolved Hide resolved
jaxley/modules/compartment.py Outdated Show resolved Hide resolved
jaxley/synapses/test.py Show resolved Hide resolved
def loc_of_index(global_comp_index, nseg):
"""Return location corresponding to index."""
index = global_comp_index % nseg
possible_locs = np.linspace(1, 0, nseg)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why reversed from 1 to 0 instead of 0 to 1? Cause I would expect that index 0 corresponds to location 0.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, indeed, this is unintitive. See #30

tests/test_api_equivalence.py Outdated Show resolved Hide resolved
tests/test_api_equivalence.py Show resolved Hide resolved
tests/test_make_trainable.py Show resolved Hide resolved
@michaeldeistler michaeldeistler changed the title .connect() method .connect() and fully_connect() method Dec 12, 2023
@michaeldeistler michaeldeistler changed the title .connect() and fully_connect() method .connect() and fully_connect() methods Dec 12, 2023
@michaeldeistler michaeldeistler merged commit 6907c0b into main Dec 12, 2023
1 check passed
@michaeldeistler michaeldeistler deleted the connect2 branch December 12, 2023 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

.connect() method
2 participants