-
Notifications
You must be signed in to change notification settings - Fork 50
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+1] unify cell connectivity and drive connectivity #369
Changes from 20 commits
2790911
829d144
3c68bcf
8cf01d5
48a1c07
87e0512
1c1b118
50ea4bb
fc98b8c
ce3e83e
e134695
7a2b11f
7364f9d
997ff45
7d83505
0810052
959a181
2b12102
e5e2a9e
bc48a8b
3663826
22f5906
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -177,15 +177,15 @@ def _extract_drive_specs_from_hnn_params(params, cellname_list): | |
if cname_ampa in par: | ||
ampa_weight = par[cname_ampa][0] | ||
ampa_delay = par[cname_ampa][1] | ||
if ampa_weight > 0.: | ||
if ampa_weight >= 0.: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since most param files contain zero-weighted drive connection parameters, this allows these param files to still be instantiated in hnn-core without throwing an error in drives.py L33-35. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you update |
||
drive['weights_ampa'][cellname] = ampa_weight | ||
|
||
# NB synaptic delay same for NMDA, read only for AMPA | ||
drive['synaptic_delays'][cellname] = ampa_delay | ||
|
||
if cname_nmda in par: | ||
nmda_weight = par[cname_nmda][0] | ||
if nmda_weight > 0.: | ||
if nmda_weight >= 0.: | ||
drive['weights_nmda'][cellname] = nmda_weight | ||
|
||
drive_specs[feed_name] = drive | ||
|
@@ -228,9 +228,9 @@ def _extract_drive_specs_from_hnn_params(params, cellname_list): | |
ampa_weight = par[cellname][0] | ||
nmda_weight = par[cellname][1] | ||
synaptic_delays = par[cellname][2] | ||
if ampa_weight > 0.: | ||
if ampa_weight >= 0.: | ||
drive['weights_ampa'][cellname] = ampa_weight | ||
if nmda_weight > 0.: | ||
if nmda_weight >= 0.: | ||
drive['weights_nmda'][cellname] = nmda_weight | ||
drive['synaptic_delays'][cellname] = synaptic_delays | ||
|
||
|
@@ -249,7 +249,7 @@ def _extract_drive_specs_from_hnn_params(params, cellname_list): | |
if cellname in par: | ||
ampa_weight = par[cellname][0] | ||
synaptic_delays = par[cellname][3] | ||
if ampa_weight > 0.: | ||
if ampa_weight >= 0.: | ||
drive['weights_ampa'][cellname] = ampa_weight | ||
drive['synaptic_delays'][cellname] = synaptic_delays | ||
|
||
|
@@ -272,9 +272,9 @@ def _extract_drive_specs_from_hnn_params(params, cellname_list): | |
ampa_weight = par[cellname][0] | ||
nmda_weight = par[cellname][1] | ||
synaptic_delays = par[cellname][2] | ||
if ampa_weight > 0.: | ||
if ampa_weight >= 0.: | ||
drive['weights_ampa'][cellname] = ampa_weight | ||
if nmda_weight > 0.: | ||
if nmda_weight >= 0.: | ||
drive['weights_nmda'][cellname] = nmda_weight | ||
drive['synaptic_delays'][cellname] = synaptic_delays | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
from hnn_core.drives import (drive_event_times, _get_prng, _create_extpois, | ||
_create_bursty_input) | ||
from hnn_core.params import create_pext | ||
from hnn_core.network import pick_connection | ||
|
||
|
||
def test_external_drive_times(): | ||
|
@@ -115,10 +116,8 @@ def test_add_drives(): | |
net = Network(params, legacy_mode=False) | ||
|
||
# Ensure weights and delays are updated | ||
weights_ampa = {'L2_basket': 1.0, 'L2_pyramidal': 3.0, | ||
'L5_basket': 2.0, 'L5_pyramidal': 4.0} | ||
syn_delays = {'L2_basket': 1.0, 'L2_pyramidal': 2.0, | ||
'L5_basket': 3.0, 'L5_pyramidal': 4.0} | ||
weights_ampa = {'L2_basket': 1.0, 'L2_pyramidal': 3.0, 'L5_pyramidal': 4.0} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removed to check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you referring to the |
||
syn_delays = {'L2_basket': 1.0, 'L2_pyramidal': 2.0, 'L5_pyramidal': 4.0} | ||
|
||
n_drive_cells = 10 | ||
cell_specific = False # default for bursty drive | ||
|
@@ -129,9 +128,12 @@ def test_add_drives(): | |
|
||
assert net.external_drives['bursty']['n_drive_cells'] == n_drive_cells | ||
assert net.external_drives['bursty']['cell_specific'] == cell_specific | ||
for type_name, drive in net.external_drives['bursty']['conn'].items(): | ||
assert drive['ampa']['A_weight'] == weights_ampa[type_name] | ||
assert drive['ampa']['A_delay'] == syn_delays[type_name] | ||
conn_idxs = pick_connection(net, src_gids='bursty') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't believe it took me so long to make this function. So much easier... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so much weekend activity. Catching up now :) I think the name of the function should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any objections? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's do separate PR :) I think it would make it harder to read |
||
for conn_idx in conn_idxs: | ||
drive_conn = net.connectivity[conn_idx] | ||
target_type = drive_conn['target_type'] | ||
assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type] | ||
assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type] | ||
|
||
n_drive_cells = 'n_cells' # default for evoked drive | ||
cell_specific = True | ||
|
@@ -140,13 +142,16 @@ def test_add_drives(): | |
weights_ampa=weights_ampa, location='distal', | ||
synaptic_delays=syn_delays, cell_specific=True) | ||
|
||
n_dist_targets = 270 # 235 with non-legacy mode | ||
n_dist_targets = 235 # 270 with legacy mode | ||
assert (net.external_drives['evoked_dist'] | ||
['n_drive_cells'] == n_dist_targets) | ||
assert net.external_drives['evoked_dist']['cell_specific'] == cell_specific | ||
for type_name, drive in net.external_drives['evoked_dist']['conn'].items(): | ||
assert drive['ampa']['A_weight'] == weights_ampa[type_name] | ||
assert drive['ampa']['A_delay'] == syn_delays[type_name] | ||
conn_idxs = pick_connection(net, src_gids='evoked_dist') | ||
for conn_idx in conn_idxs: | ||
drive_conn = net.connectivity[conn_idx] | ||
target_type = drive_conn['target_type'] | ||
assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type] | ||
assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type] | ||
|
||
n_drive_cells = 'n_cells' # default for poisson drive | ||
cell_specific = True | ||
|
@@ -155,13 +160,16 @@ def test_add_drives(): | |
location='distal', synaptic_delays=syn_delays, | ||
cell_specific=cell_specific) | ||
|
||
n_dist_targets = 270 # 235 with non-legacy mode | ||
n_dist_targets = 235 # 270 with non-legacy mode | ||
assert (net.external_drives['poisson'] | ||
['n_drive_cells'] == n_dist_targets) | ||
assert net.external_drives['poisson']['cell_specific'] == cell_specific | ||
for type_name, drive in net.external_drives['poisson']['conn'].items(): | ||
assert drive['ampa']['A_weight'] == weights_ampa[type_name] | ||
assert drive['ampa']['A_delay'] == syn_delays[type_name] | ||
conn_idxs = pick_connection(net, src_gids='poisson') | ||
for conn_idx in conn_idxs: | ||
drive_conn = net.connectivity[conn_idx] | ||
target_type = drive_conn['target_type'] | ||
assert drive_conn['nc_dict']['A_weight'] == weights_ampa[target_type] | ||
assert drive_conn['nc_dict']['A_delay'] == syn_delays[target_type] | ||
|
||
# evoked | ||
with pytest.raises(ValueError, | ||
|
@@ -182,6 +190,17 @@ def test_add_drives(): | |
match='Drive evoked_dist already defined'): | ||
net.add_evoked_drive('evoked_dist', mu=10, sigma=1, numspikes=1, | ||
location='distal') | ||
with pytest.raises(ValueError, | ||
match='No target cell types have been given a synaptic ' | ||
'weight'): | ||
net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1, | ||
location='distal') | ||
with pytest.raises(ValueError, | ||
match='When adding a distal drive, synaptic weight ' | ||
'cannot be defined for the L5_basket cell type'): | ||
net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1, | ||
location='distal', weights_ampa={'L5_basket': 1.}, | ||
synaptic_delays={'L5_basket': .1}) | ||
with pytest.raises(ValueError, | ||
match='If cell_specific is True, n_drive_cells'): | ||
net.add_evoked_drive('evdist1', mu=10, sigma=1, numspikes=1, | ||
|
@@ -217,18 +236,24 @@ def test_add_drives(): | |
with pytest.raises(ValueError, | ||
match='Rate constant must be positive'): | ||
net.add_poisson_drive('poisson1', location='distal', | ||
rate_constant=0.) | ||
rate_constant=0., | ||
weights_ampa=weights_ampa, | ||
synaptic_delays=syn_delays) | ||
|
||
with pytest.raises(ValueError, | ||
match='Rate constants not provided for all target'): | ||
net.add_poisson_drive('poisson1', location='distal', | ||
rate_constant={'L2_pyramidal': 10.}, | ||
weights_ampa={'L5_pyramidal': .01}) | ||
weights_ampa=weights_ampa, | ||
synaptic_delays=syn_delays) | ||
with pytest.raises(ValueError, | ||
match='Rate constant provided for unknown target cell'): | ||
net.add_poisson_drive('poisson1', location='distal', | ||
rate_constant={'L2_pyramidal': 10., | ||
'bogus_celltype': 20.}) | ||
'bogus_celltype': 20.}, | ||
weights_ampa={'L2_pyramidal': .01, | ||
'bogus_celltype': .01}, | ||
synaptic_delays=0.1) | ||
|
||
with pytest.raises(ValueError, | ||
match='Drives specific to cell types are only ' | ||
|
@@ -267,19 +292,24 @@ def test_add_drives(): | |
with pytest.raises(ValueError, | ||
match='Drive evoked_dist already defined'): | ||
net.add_poisson_drive('evoked_dist', location='distal', | ||
rate_constant=10.) | ||
rate_constant=10., | ||
weights_ampa=weights_ampa, | ||
synaptic_delays=syn_delays) | ||
with pytest.raises(ValueError, | ||
match='Allowed drive target locations are:'): | ||
net.add_poisson_drive('weird_poisson', location='inbetween', | ||
rate_constant=10.) | ||
rate_constant=10., | ||
weights_ampa=weights_ampa, | ||
synaptic_delays=syn_delays) | ||
with pytest.raises(ValueError, | ||
match='Allowed drive target cell types are:'): | ||
net.add_poisson_drive('cell_unknown', location='proximal', | ||
rate_constant=10., | ||
weights_ampa={'CA1_pyramidal': 1.}) | ||
weights_ampa={'CA1_pyramidal': 1.}, | ||
synaptic_delays=.01) | ||
with pytest.raises(ValueError, | ||
match='synaptic_delays is either a common float or ' | ||
'needs to be specified as a dict for each cell'): | ||
'needs to be specified as a dict for each of the cell'): | ||
net.add_poisson_drive('cell_unknown', location='proximal', | ||
rate_constant=10., | ||
weights_ampa={'L2_pyramidal': 1.}, | ||
|
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.
You should think of "what affects the user" when updating this. User does not care about code path. They care about:
net.connectivity
. It has more elements now and probably not in the same order. If someone hard codednet.connectivity[32]
it would now break. So that's an API change.drive['conns']
. It no longer exists. If someone relied on it in their code, it would break nowThere 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.
What do you think of 3663826 @jasmainak?
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.
Looks good!