Skip to content

Commit

Permalink
update drive and network tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rythorpe committed Jul 29, 2021
1 parent e07d0cc commit 91c03be
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 30 deletions.
28 changes: 19 additions & 9 deletions hnn_core/tests/test_drives.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -129,9 +130,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')
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
Expand All @@ -144,9 +148,12 @@ def test_add_drives():
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
Expand All @@ -159,9 +166,12 @@ def test_add_drives():
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,
Expand Down
41 changes: 20 additions & 21 deletions hnn_core/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,20 +82,13 @@ def test_network():
n_drive_cells = net.external_drives[dn]['n_drive_cells']
assert len(net.gid_ranges[dn]) == n_drive_cells

# Check src_gids match between drives/connections
for conn in net.connectivity:
src_type = conn['src_type']
target_type = conn['target_type']
if src_type not in net.cell_types.keys():
assert set(conn['gid_pairs'].keys()) == set(
net.external_drives[src_type]['conn'][target_type]['src_gids'])

# Check drive dict structure for each external drive
for drive in net.external_drives.values():
# Check that connectivity sources correspond to gid_ranges
this_src_gids = set([gid for drive_conn in
drive['conn'].values() for
gid in drive_conn['src_gids']]) # NB set: globals
conn_idxs = pick_connection(net, src_gids=drive['name'])
this_src_gids = set([gid for conn_idx in conn_idxs
for gid in net.connectivity[conn_idx]['src_gids']
]) # NB set: globals
assert sorted(this_src_gids) == list(net.gid_ranges[drive['name']])
# Check type-specific dynamics and events
n_drive_cells = drive['n_drive_cells']
Expand Down Expand Up @@ -148,22 +141,28 @@ def test_network():
'L5_pyramidal': 0.000024}
}
for drive_name in target_weights:
for cellname in target_weights[drive_name]:
assert_allclose(
net.external_drives[
drive_name]['conn'][cellname]['ampa']['A_weight'],
target_weights[drive_name][cellname], rtol=1e-12)
for target_type in target_weights[drive_name]:
conn_idxs = pick_connection(net, src_gids=drive_name,
target_gids=target_type,
receptor='ampa')
for conn_idx in conn_idxs:
drive_conn = net.connectivity[conn_idx]
assert_allclose(drive_conn['nc_dict']['A_weight'],
target_weights[target_type], rtol=1e-12)

# check select synaptic delays
target_delays = {'evdist1': {'L2_basket': 0.1, 'L5_pyramidal': 0.1},
'evprox1': {'L2_basket': 0.1, 'L5_pyramidal': 1.},
'evprox2': {'L2_basket': 0.1, 'L5_pyramidal': 1.}}
for drive_name in target_delays:
for cellname in target_delays[drive_name]:
assert_allclose(
net.external_drives[
drive_name]['conn'][cellname]['ampa']['A_delay'],
target_delays[drive_name][cellname], rtol=1e-12)
for target_type in target_delays[drive_name]:
conn_idxs = pick_connection(net, src_gids=drive_name,
target_gids=target_type,
receptor='ampa')
for conn_idx in conn_idxs:
drive_conn = net.connectivity[conn_idx]
assert_allclose(drive_conn['nc_dict']['A_delay'],
target_delays[target_type], rtol=1e-12)

# array of simulation times is created in Network.__init__, but passed
# to CellResponse-constructor for storage (Network is agnostic of time)
Expand Down

0 comments on commit 91c03be

Please sign in to comment.