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

[MRG] BUG: Update gid_ranges after using clear_drives #812

Merged
merged 9 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ Bug
- Fix drive seeding so that event times are unique across multiple trials,
by `Nick Tolley`_ in :gh:`810`.

- Fix bug in :func:`~hnn_core/network/clear_drives` where gid_ranges are not
ntolley marked this conversation as resolved.
Show resolved Hide resolved
accurately updated, by `Nick Tolley`_ in :gh:`812`.

API
~~~
- :func:`~hnn_core.CellResponse.write` and :func:`~hnn_core.Cell_response.read_spikes`
Expand Down
15 changes: 10 additions & 5 deletions hnn_core/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1374,12 +1374,17 @@ def clear_connectivity(self):

def clear_drives(self):
"""Remove all drives defined in Network.connectivity"""
connectivity = list()
for conn in self.connectivity:
if conn['src_type'] not in self.external_drives.keys():
connectivity.append(conn)
self.connectivity = [conn for conn in self.connectivity if
conn['src_type'] if conn['src_type'] not
in self.external_drives.keys()]

gtdang marked this conversation as resolved.
Show resolved Hide resolved
for cell_type in list(self.gid_ranges.keys()):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Probably a matter of semantics but are drive names also "cell types"? I think in other parts of the codebase "cell_types" usually just refers to the neocortical cell names? At least the Network["cell_types"] is only those cells. Maybe something like "range_name" would be clearer.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah we have a bit of inconsistency here ... how about calling it cell_name like we do in the rest of the repo. The variable name cell_type and cell_template are a bit interchangeable and confusing

if cell_type in self.external_drives:
self._n_gids -= len(self.gid_ranges[cell_type])
del self.gid_ranges[cell_type]
del self.pos_dict[cell_type]

self.external_drives = dict()
self.connectivity = connectivity

def add_electrode_array(self, name, electrode_pos, *, conductivity=0.3,
method='psa', min_distance=0.5):
Expand Down
28 changes: 26 additions & 2 deletions hnn_core/tests/test_drives.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def test_external_drive_times():
def test_drive_seeds(setup_net):
"""Test that unique spike times are generated across trials"""
net = setup_net
weights_ampa = {'L2_basket': 0.000003, 'L2_pyramidal': 1.438840,
'L5_basket': 0.008958, 'L5_pyramidal': 0.684013}
weights_ampa = {'L2_basket': 0.3, 'L2_pyramidal': 0.3,
'L5_basket': 0.3, 'L5_pyramidal': 0.3}
synaptic_delays = {'L2_basket': 0.1, 'L2_pyramidal': 0.1,
'L5_basket': 1., 'L5_pyramidal': 1.}
net.add_evoked_drive(
Expand All @@ -116,6 +116,30 @@ def test_drive_seeds(setup_net):
assert ~np.any(np.allclose(trial1_spikes, trial2_spikes))


def test_clear_drives(setup_net):
"""Test clearing drives updates Network"""
net = setup_net
weights_ampa = {'L5_pyramidal': 0.3}
synaptic_delays = {'L5_pyramidal': 1.}

n_gids = net._n_gids
net.add_evoked_drive(
gtdang marked this conversation as resolved.
Show resolved Hide resolved
'prox', mu=40, sigma=8.33, numspikes=1,
weights_ampa=weights_ampa, location='proximal',
synaptic_delays=synaptic_delays, cell_specific=True)

assert len(net.external_drives) > 0
assert 'prox' in net.external_drives
assert 'prox' in net.gid_ranges
assert net._n_gids == n_gids + len(net.gid_ranges['L5_pyramidal'])

net.clear_drives()
assert len(net.external_drives) == 0
assert 'prox' not in net.external_drives
assert 'prox' not in net.gid_ranges
assert net._n_gids == n_gids

Copy link
Collaborator

Choose a reason for hiding this comment

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

Perhaps we can test adding a new drive after clearing drives to make sure the Network still works after clearing the drives?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Mostly a check that the ranges and positions are populated as expected after resetting them.


def test_add_drives():
"""Test methods for adding drives to a Network."""
hnn_core_root = op.dirname(hnn_core.__file__)
Expand Down
Loading