Ejemplo n.º 1
0
def test_add_edges():
    net = NetworkBuilder('V1')
    net.add_nodes(N=10, cell_type='Scnna1', ei='e')
    net.add_nodes(N=10, cell_type='PV1', ei='i')
    net.add_nodes(N=10, cell_type='PV2', ei='i')
    net.add_edges(
        source={'ei': 'i'},
        target={'ei': 'e'},
        connection_rule=lambda s, t: 1,
        edge_arg='i2e'
    )
    net.add_edges(
        source=net.nodes(cell_type='Scnna1'),
        target=net.nodes(cell_type='PV1'),
        connection_rule=2,
        edge_arg='e2i'
    )
    net.build()
    assert(net.nedges == 200 + 200)
    assert(net.edges_built is True)

    for e in net.edges(target_nodes=net.nodes(cell_type='Scnna1')):
        assert(e['edge_arg'] == 'i2e')
        assert(e['nsyns'] == 1)

    for e in net.edges(target_nodes=net.nodes(cell_type='PV1')):
        assert(e['edge_arg'] == 'e2i')
        assert(e['nsyns'] == 2)
Ejemplo n.º 2
0
def test_save_multinetwork_1():
    net1 = NetworkBuilder('NET1')
    net1.add_nodes(N=100, position=[(0.0, 1.0, -1.0)] * 100, cell_type='Scnna1', ei='e')
    net1.add_edges(source={'ei': 'e'}, target={'ei': 'e'}, connection_rule=5, ctype_1='n1_rec')
    net1.build()

    net2 = NetworkBuilder('NET2')
    net2.add_nodes(N=10, position=[(0.0, 1.0, -1.0)] * 10, cell_type='PV1', ei='i')
    net2.add_edges(connection_rule=10, ctype_1='n2_rec')
    net2.add_edges(source=net1.nodes(), target={'ei': 'i'}, connection_rule=1, ctype_2='n1_n2')
    net2.add_edges(target=net1.nodes(cell_type='Scnna1'), source={'cell_type': 'PV1'}, connection_rule=2,
                   ctype_2='n2_n1')
    net2.build()
    net_dir = tempfile.mkdtemp()
    net2.save_edges(edges_file_name='NET2_NET1_edges.h5', edge_types_file_name='NET2_NET1_edge_types.csv',
                    output_dir=net_dir, src_network='NET2')

    n1_n2_fname = '{}/{}_{}'.format(net_dir, 'NET2', 'NET1')
    edges_h5 = h5py.File(n1_n2_fname + '_edges.h5', 'r')
    assert(len(edges_h5['/edges/NET2_to_NET1/target_node_id']) == 100*10)
    assert(len(edges_h5['/edges/NET2_to_NET1/0/nsyns']) == 100*10)
    assert(edges_h5['/edges/NET2_to_NET1/0/nsyns'][0] == 2)
    edge_types_csv = pd.read_csv(n1_n2_fname + '_edge_types.csv', sep=' ')
    assert(len(edge_types_csv) == 1)
    assert('ctype_1' not in edge_types_csv.columns.values)
    assert(edge_types_csv['ctype_2'].iloc[0] == 'n2_n1')
Ejemplo n.º 3
0
def test_duplicate_node_ids():
    # Check if the same node_id is being used twice
    net = NetworkBuilder('V1')
    net.add_nodes(N=1, node_id=[100])

    with pytest.raises(ValueError):
        net.add_nodes(N=1, node_id=[100])
Ejemplo n.º 4
0
def test_node_sets():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=100, prop_n='prop1', pool1='p1', sp='sp', param1=range(100))
    net.add_nodes(N=100, prop_n='prop2', pool2='p2', sp='sp', param1=range(100))
    net.add_nodes(N=100, prop_n='prop3', pool3='p3', sp='sp', param1=range(100))
    node_pool_1 = net.nodes(prop_n='prop1')
    assert(len(node_pool_1) == 100)
    assert(node_pool_1.filter_str == "prop_n=='prop1'")
    for n in node_pool_1:
        assert('pool1' in n and n['prop_n'] == 'prop1')

    node_pool_2 = net.nodes(sp='sp')
    assert(node_pool_2.filter_str == "sp=='sp'")
    assert(len(node_pool_2) == 300)
    for n in node_pool_2:
        assert(n['sp'] == 'sp')

    node_pool_3 = net.nodes(param1=10)
    assert(len(node_pool_3) == 3)
    assert(node_pool_3.filter_str == "param1=='10'")
    nodes = list(node_pool_3)
    assert(nodes[0]['node_id'] == 10)
    assert(nodes[1]['node_id'] == 110)
    assert(nodes[2]['node_id'] == 210)
    assert(nodes[0]['node_type_id'] != nodes[1]['node_type_id'] != nodes[2]['node_type_id'])
Ejemplo n.º 5
0
def build_injective_inputs(target_net):
    print('Building External Network')

    input_network_model = {
        'external': {
            'N': len(target_net.nodes()
                     ),  # Need one virtual node for every LIF_network node
            'ei': 'e',
            'pop_name': 'input_network',
            'model_type': 'virtual'
        }
    }

    inputNetwork = NetworkBuilder("external")
    inputNetwork.add_nodes(**input_network_model['external'])

    inputNetwork.add_edges(
        target=target_net.nodes(pop_name='LIF_exc'),
        connection_rule=injective_connections,
        iterator='all_to_one',  # will make building a little faster
        syn_weight=200,
        delay=D,
        dynamics_params='ExcToExc.json',
        model_template='static_synapse')

    inputNetwork.add_edges(target=target_net.nodes(pop_name='LIF_inh'),
                           connection_rule=injective_connections,
                           iterator='all_to_one',
                           syn_weight=100,
                           delay=D,
                           dynamics_params='ExcToExc.json',
                           model_template='static_synapse')

    inputNetwork.build()
    inputNetwork.save(output_dir='network')
Ejemplo n.º 6
0
def test_cross_population_edges():
    tmp_dir = make_tmp_dir()
    edges_file = make_tmp_file(suffix='.h5')
    edge_types_file = make_tmp_file(suffix='.csv')

    net_a1 = NetworkBuilder('A1')
    net_a1.add_nodes(N=100, model='A')
    net_a1.build()

    net_a2 = NetworkBuilder('A2')
    net_a2.add_nodes(N=100, model='B')
    net_a2.add_edges(
        source=net_a1.nodes(),
        target=net_a2.nodes(),
        connection_rule=lambda s, t: 1 if s.node_id == t.node_id else 0
    )
    net_a2.build()
    net_a2.save_edges(
        edges_file_name=edges_file,
        edge_types_file_name=edge_types_file,
        output_dir=tmp_dir,
        name='A1_A2'
    )

    edges_h5_path = os.path.join(tmp_dir, edges_file)
    assert(os.path.exists(edges_h5_path))
    with h5py.File(edges_h5_path, 'r') as h5:
        assert('/edges/A1_A2' in h5)
        assert(len(h5['/edges/A1_A2/source_node_id']) == 100)
        assert(h5['/edges/A1_A2/source_node_id'].attrs['node_population'] == 'A1')
        assert(len(h5['/edges/A1_A2/target_node_id']) == 100)
        assert(h5['/edges/A1_A2/target_node_id'].attrs['node_population'] == 'A2')

    barrier()
Ejemplo n.º 7
0
def test_add_edges_custom_params():
    # Uses connection map functionality to create edges with unique parameters
    net = NetworkBuilder('V1')
    net.add_nodes(N=10, arg_list=range(10), arg_ctype='e')
    net.add_nodes(N=5, arg_list=range(10, 15), arg_ctype='i')

    cm = net.add_edges(
        source={'arg_ctype': 'e'},
        target={'arg_ctype': 'i'},
        connection_rule=2
    )
    cm.add_properties('syn_weight', rule=0.5, dtypes=float)
    cm.add_properties(
        ['src_num', 'trg_num'],
        rule=lambda s, t: [s['node_id'], t['node_id']],
        dtypes=[int, int]
    )
    net.build()

    assert(net.nedges == 2*50)
    assert(net.edges_built is True)

    for e in net.edges():
        assert(e['syn_weight'] == 0.5)
        assert(e['src_num'] == e.source_node_id)
        assert(e['trg_num'] == e.target_node_id)
Ejemplo n.º 8
0
def test_single_node():
    net = NetworkBuilder('NET1')
    net.add_nodes(prop1='prop1', prop2='prop2', param1=['param1'])
    nodes = list(net.nodes())
    assert (len(nodes) == 1)
    assert (nodes[0]['param1'] == 'param1')
    assert (nodes[0]['prop1'] == 'prop1')
    assert (nodes[0]['prop2'] == 'prop2')
Ejemplo n.º 9
0
def test_failed_search():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=100, p1='p1', q1=range(100))
    node_pool = net.nodes(p1='p2')
    assert (len(node_pool) == 0)

    node_pool = net.nodes(q2=10)
    assert (len(node_pool) == 0)
Ejemplo n.º 10
0
def test_multi_search():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=10, prop_n='prop1', sp='sp1', param1=range(0, 10))
    net.add_nodes(N=10, prop_n='prop1', sp='sp2', param1=range(5, 15))
    net.add_nodes(N=20, prop_n='prop2', sp='sp2', param1=range(20))
    node_pool = net.nodes(prop_n='prop1', param1=5)
    assert (len(node_pool) == 2)
    nodes = list(node_pool)
    assert (nodes[0]['node_id'] == 5)
    assert (nodes[1]['node_id'] == 10)
Ejemplo n.º 11
0
def test_connection_map():
    tmp_dir = tempfile.mkdtemp()
    edges_file = make_tmp_file(suffix='.h5')
    edge_types_file = make_tmp_file(suffix='.csv')

    net = NetworkBuilder('test')
    net.add_nodes(N=10, x=range(10), model='A')
    net.add_nodes(N=20, x=range(10, 30), model='B')

    net.add_edges(source={'model': 'A'}, target={'model': 'B'}, connection_rule=1, edge_model='A')

    cm = net.add_edges(source={'model': 'B'}, target={'model': 'B'}, connection_rule=2, edge_model='B')
    cm.add_properties(names='a', rule=5, dtypes=int)

    cm = net.add_edges(source={'model': 'B'}, target={'x': 0}, connection_rule=3, edge_model='C')
    cm.add_properties(names='b', rule=0.5, dtypes=float)
    cm.add_properties(names='c', rule=lambda *_: 2, dtypes=int)

    net.build()
    net.save_edges(
        edges_file_name=edges_file,
        edge_types_file_name=edge_types_file,
        output_dir=tmp_dir,
        name='test_test'
    )

    edges_h5_path = os.path.join(tmp_dir, edges_file)
    assert(os.path.exists(edges_h5_path))
    with h5py.File(edges_h5_path, 'r') as h5:
        n_edges = 10*20*1 + 20*20*2 + 20*1*3
        assert('/edges/test_test' in h5)
        assert(len(h5['/edges/test_test/target_node_id']) == n_edges)
        assert(h5['/edges/test_test/target_node_id'].attrs['node_population'] == 'test')
        assert(len(h5['/edges/test_test/source_node_id']) == n_edges)
        assert(h5['/edges/test_test/source_node_id'].attrs['node_population'] == 'test')
        assert(len(h5['/edges/test_test/edge_type_id']) == n_edges)
        assert(len(h5['/edges/test_test/edge_group_id']) == n_edges)
        assert(len(h5['/edges/test_test/edge_group_index']) == n_edges)
        assert(len(np.unique(h5['/edges/test_test/edge_type_id'])) == 3)
        assert(len(np.unique(h5['/edges/test_test/edge_group_id'])) == 3)

        for grp_id, grp in h5['/edges/test_test'].items():
            if not isinstance(grp, h5py.Group) or grp_id in ['indicies', 'indices']:
                continue
            assert(int('nsyns' in grp) + int('a' in grp) + int('c' in grp and 'c' in grp) == 1)

    edge_type_csv_path = os.path.join(tmp_dir, edge_types_file)
    assert(os.path.exists(edge_type_csv_path))
    edge_types_df = pd.read_csv(edge_type_csv_path, sep=' ')
    assert(len(edge_types_df) == 3)
    assert('edge_type_id' in edge_types_df.columns)
    assert('edge_model' in edge_types_df.columns)

    barrier()
Ejemplo n.º 12
0
def test_nsyn_edges():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=100, cell_type='Scnna1', ei='e')
    net.add_nodes(N=100, cell_type='PV1', ei='i')
    net.add_nodes(N=100, cell_type='PV2', ei='i')
    net.add_edges(source={'ei': 'i'}, target={'ei': 'e'}, connection_rule=lambda s, t: 1)  # 200*100 = 20000 edges
    net.add_edges(source=net.nodes(cell_type='Scnna1'), target=net.nodes(cell_type='PV1'),
                  connection_rule=lambda s, t: 2)  # 100*100*2 = 20000
    net.build()
    assert(net.nedges == 20000 + 20000)
    assert(net.edges_built is True)
Ejemplo n.º 13
0
def test_build_nodes1():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=3, node_id=[100, 200, 300], node_type_id=101, name=['one', 'two', 'three'])
    node_one = list(net.nodes(name='one'))[0]
    assert(node_one['name'] == 'one')
    assert(node_one['node_id'] == 100)
    assert(node_one['node_type_id'] == 101)

    node_three = list(net.nodes(name='three'))[0]
    assert(node_three['name'] == 'three')
    assert(node_three['node_id'] == 300)
    assert(node_three['node_type_id'] == 101)
Ejemplo n.º 14
0
def test_add_nodes_ids():
    # Special case if parameters node_id and node_type_id are explicitly defined by the user
    net = NetworkBuilder('V1')
    net.add_nodes(N=3, node_id=[100, 200, 300], node_type_id=101, name=['one', 'two', 'three'])
    node_one = list(net.nodes(name='one'))[0]
    assert(node_one['name'] == 'one')
    assert(node_one['node_id'] == 100)
    assert(node_one['node_type_id'] == 101)

    node_three = list(net.nodes(name='three'))[0]
    assert(node_three['name'] == 'three')
    assert(node_three['node_id'] == 300)
    assert(node_three['node_type_id'] == 101)
Ejemplo n.º 15
0
def test_node_set():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=100, prop1='prop1', param1=range(100))
    node_pool = net.nodes()
    assert (node_pool.filter_str == '*')

    nodes = list(node_pool)
    assert (len(nodes) == 100)
    assert (nodes[0]['prop1'] == 'prop1')
    assert (nodes[0]['param1'] == 0)
    assert (nodes[99]['prop1'] == 'prop1')
    assert (nodes[99]['param1'] == 99)
    assert (nodes[0]['node_type_id'] == nodes[99]['node_type_id'])
    assert (nodes[0]['node_id'] != nodes[99]['node_id'])
Ejemplo n.º 16
0
def test_cross_pop_edges():
    # Uses connection map functionality to create edges with unique parameters
    net1 = NetworkBuilder('V1')
    net1.add_nodes(N=10, arg_list=range(10), arg_ctype='e')
    net1.build()

    net2 = NetworkBuilder('V2')
    net2.add_nodes(N=5, arg_list=range(10, 15), arg_ctype='i')

    net2.add_edges(source={'arg_ctype': 'i'}, target=net1.nodes(arg_ctype='e'),
                  connection_rule=lambda s, t: 1,
                  edge_arg='i2e')
    net2.build()
    assert(net2.nedges == 50)
Ejemplo n.º 17
0
def test_add_nodes_tuples():
    # Should be able to store tuples of values in single parameters for a given node
    net = NetworkBuilder('V1')
    net.add_nodes(N=10,
                  arg_list=range(10),
                  arg_tuples=[(r, r+1) for r in range(10)],
                  arg_const=('a', 'b'))
    net.build()

    assert(net.nodes_built is True)
    assert(net.nnodes == 10)
    for node in net.nodes():
        assert(len(node['arg_tuples']) == 2)
        assert(node['arg_tuples'][0] == node['arg_list'] and node['arg_tuples'][1] == node['arg_list']+1)
        assert(len(node['arg_const']) == 2)
        assert(node['arg_const'][0] == 'a' and node['arg_const'][1] == 'b')
Ejemplo n.º 18
0
def test_edge_models():
    tmp_dir = tempfile.mkdtemp()
    edges_file = make_tmp_file(suffix='.h5')
    edge_types_file = make_tmp_file(suffix='.csv')

    net = NetworkBuilder('test')
    net.add_nodes(N=100, x=range(100), model='A')
    net.add_nodes(N=100, x=range(100, 200), model='B')
    net.add_edges(source={'model': 'A'}, target={'model': 'B'}, connection_rule=1, model='A')
    net.add_edges(source={'model': 'A'}, target={'x': 0}, connection_rule=2, model='B')
    net.add_edges(source={'model': 'A'}, target={'x': [1, 2, 3]}, connection_rule=3, model='C')
    net.add_edges(source={'model': 'A', 'x': 0}, target={'model': 'B', 'x': 100}, connection_rule=4, model='D')
    net.build()
    net.save_edges(
        edges_file_name=edges_file,
        edge_types_file_name=edge_types_file,
        output_dir=tmp_dir,
        name='test_test'
    )

    edges_h5_path = os.path.join(tmp_dir, edges_file)
    assert(os.path.exists(edges_h5_path))
    with h5py.File(edges_h5_path, 'r') as h5:
        n_edges = 100*100 + 100*1 + 100*3 + 1
        assert('/edges/test_test' in h5)
        assert(len(h5['/edges/test_test/target_node_id']) == n_edges)
        assert(h5['/edges/test_test/target_node_id'].attrs['node_population'] == 'test')
        assert(len(h5['/edges/test_test/source_node_id']) == n_edges)
        assert(h5['/edges/test_test/source_node_id'].attrs['node_population'] == 'test')
        assert(len(h5['/edges/test_test/edge_type_id']) == n_edges)
        assert(len(h5['/edges/test_test/edge_group_id']) == n_edges)
        assert(len(h5['/edges/test_test/edge_group_index']) == n_edges)

        assert(len(np.unique(h5['/edges/test_test/edge_type_id'])) == 4)
        assert(len(np.unique(h5['/edges/test_test/edge_group_id'])) == 1)
        grp_id = str(h5['/edges/test_test/edge_group_id'][0])
        assert(len(h5['/edges/test_test'][grp_id]['nsyns']) == n_edges)

    edge_type_csv_path = os.path.join(tmp_dir, edge_types_file)
    assert(os.path.exists(edge_type_csv_path))
    edge_types_df = pd.read_csv(edge_type_csv_path, sep=' ')
    assert(len(edge_types_df) == 4)
    assert('edge_type_id' in edge_types_df.columns)
    assert('model' in edge_types_df.columns)

    barrier()
Ejemplo n.º 19
0
def test_mulitnet_iterator():
    net1 = NetworkBuilder('NET1')
    net1.add_nodes(N=50, cell_type='Rorb', ei='e')
    net1.build()

    net2 = NetworkBuilder('NET2')
    net2.add_nodes(N=100, cell_type='Scnna1', ei='e')
    net2.add_nodes(N=100, cell_type='PV1', ei='i')
    net2.add_edges(source={'ei': 'e'},
                   target={'ei': 'i'},
                   connection_rule=5,
                   syn_type='e2i',
                   net_type='rec')
    net2.add_edges(source=net1.nodes(),
                   target={'ei': 'e'},
                   connection_rule=1,
                   syn_type='e2e',
                   net_type='fwd')
    net2.build()

    assert (len(net2.edges()) == 50 * 100 + 100 * 100)
    assert (len(net2.edges(source_network='NET2', target_network='NET1')) == 0)
    assert (len(net2.edges(source_network='NET1',
                           target_network='NET2')) == 50 * 100)
    assert (len(net2.edges(target_network='NET2',
                           net_type='rec')) == 100 * 100)

    edges = net2.edges(source_network='NET1')
    assert (len(edges) == 50 * 100)
    for e in edges:
        assert (e['net_type'] == 'fwd')
Ejemplo n.º 20
0
def test_add_nodes():
    # Tests that mutliple models of nodes can be added to network
    net = NetworkBuilder('V1')
    net.add_nodes(N=10, arg_list=range(10), arg_const='pop1', arg_shared='global')
    net.add_nodes(N=1, arg_list=[11], arg_const='pop2', arg_shared='global')
    net.add_nodes(N=5, arg_unique=range(12, 17), arg_const='pop3', arg_shared='global')  # diff param signature
    net.build()

    assert(net.nodes_built is True)
    assert(net.nnodes == 16)
    assert(net.nedges == 0)
    assert(len(net.nodes()) == 16)
    assert(len(net.nodes(arg_const='pop1')) == 10)
    assert(len(net.nodes(arg_const='pop2')) == 1)
    assert(len(net.nodes(arg_shared='global')) == 16)
    assert(len(net.nodes(arg_shared='invalid')) == 0)

    node_set = net.nodes(arg_list=2)
    assert(len(node_set) == 1)
    node = list(node_set)[0]
    assert(node['arg_const'] == 'pop1')
    assert(node['arg_shared'] == 'global')

    node_set = net.nodes(arg_unique=12)
    assert(len(node_set) == 1)
    node = list(node_set)[0]
    assert(node['arg_const'] == 'pop3')
    assert(node['arg_shared'] == 'global')
    assert('arg_list' not in node)
Ejemplo n.º 21
0
def test_save_weights():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=100, position=[(0.0, 1.0, -1.0)]*100, cell_type='Scnna1', ei='e')
    net.add_nodes(N=100, position=[(0.0, 1.0, -1.0)]*100, cell_type='PV1', ei='i')
    net.add_nodes(N=100, position=[(0.0, 1.0, -1.0)]*100, tags=np.linspace(0, 100, 100), cell_type='PV2', ei='i')
    cm = net.add_edges(source={'ei': 'i'}, target={'ei': 'e'}, connection_rule=lambda s, t: 3,
                       p1='e2i', p2='e2i')  # 200*100 = 60000 edges
    cm.add_properties(names=['segment', 'distance'], rule=lambda s, t: [1, 0.5], dtypes=[np.int, np.float])

    net.add_edges(source=net.nodes(cell_type='Scnna1'), target=net.nodes(cell_type='PV1'),
                  connection_rule=lambda s, t: 2, p1='s2p')  # 100*100 = 20000'

    net.build()
    net_dir = tempfile.mkdtemp()
    net.save_nodes('tmp_nodes.h5', 'tmp_node_types.csv', output_dir=net_dir)
    net.save_edges('tmp_edges.h5', 'tmp_edge_types.csv', output_dir=net_dir)

    edges_h5 = h5py.File('{}/tmp_edges.h5'.format(net_dir), 'r')
    assert(net.nedges == 80000)
    assert(len(edges_h5['/edges/NET1_to_NET1/0/distance']) == 60000)
    assert(len(edges_h5['/edges/NET1_to_NET1/0/segment']) == 60000)
    assert(len(edges_h5['/edges/NET1_to_NET1/1/nsyns']) == 10000)
    assert(edges_h5['/edges/NET1_to_NET1/0/distance'][0] == 0.5)
    assert(edges_h5['/edges/NET1_to_NET1/0/segment'][0] == 1)
    assert(edges_h5['/edges/NET1_to_NET1/1/nsyns'][0] == 2)
Ejemplo n.º 22
0
def test_itr_basic():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=100,
                  position=[(0.0, 1.0, -1.0)] * 100,
                  cell_type='Scnna1',
                  ei='e')
    net.add_nodes(N=100,
                  position=[(0.0, 1.0, -1.0)] * 100,
                  cell_type='PV1',
                  ei='i')
    net.add_edges(source={'ei': 'e'},
                  target={'ei': 'i'},
                  connection_rule=5,
                  syn_type='e2i')
    net.add_edges(source={'cell_type': 'PV1'},
                  target={'cell_type': 'Scnna1'},
                  connection_rule=5,
                  syn_type='i2e')
    net.build()

    edges = net.edges()
    assert (len(edges) == 100 * 100 * 2)
    assert (edges[0]['nsyns'] == 5)
Ejemplo n.º 23
0
def build_source_network(target_net):
    input_network_model = {
        'external': {
            'N': 1,
            'ei': 'e',
            'pop_name': 'input_network',
            'model_type': 'virtual'
        }
    }

    inputNetwork = NetworkBuilder("external")
    inputNetwork.add_nodes(**input_network_model['external'])

    inputNetwork.add_edges(target=target_net.nodes(pop_name='LIF_exc'),
                           connection_rule=random_connections,
                           connection_params={'p': 0.1},
                           syn_weight=400,
                           delay=D,
                           dynamics_params='ExcToExc.json',
                           model_template='static_synapse')

    inputNetwork.add_edges(target=target_net.nodes(pop_name='LIF_inh'),
                           connection_rule=random_connections,
                           connection_params={'p': 0.1},
                           syn_weight=400,
                           delay=D,
                           dynamics_params='ExcToExc.json',
                           model_template='static_synapse')

    inputNetwork.build()
    net.save(output_dir='network')
    #inputNetwork.save_nodes(nodes_file_name='one_input_node.h5', node_types_file_name='one_input_node_type.csv',
    #                        output_dir='lif_network')
    #inputNetwork.save_edges(edges_file_name='one_input_edges.h5', edge_types_file_name='one_input_edge_type.csv',
    #                        output_dir='lif_network')
    return inputNetwork
Ejemplo n.º 24
0
def test_multi_node_models():
    tmp_dir = make_tmp_dir()
    nodes_file = make_tmp_file(suffix='.h5')
    node_types_file = make_tmp_file(suffix='.csv')

    net = NetworkBuilder('test')
    net.add_nodes(N=10, x=np.arange(10), common=range(10), model='A', p='X')
    net.add_nodes(N=10, x=np.arange(10), common=range(10), model='B')
    net.add_nodes(N=20, y=np.arange(20), common=range(20), model='C', p='X')
    net.add_nodes(N=20, y=np.arange(20), common=range(20), model='D')
    net.add_nodes(N=30, z=np.arange(30), common=range(30), model='E')
    net.build()
    net.save_nodes(
        nodes_file_name=nodes_file,
        node_types_file_name=node_types_file,
        output_dir=tmp_dir
    )

    nodes_h5_path = os.path.join(tmp_dir, nodes_file)
    assert(os.path.exists(nodes_h5_path))
    with h5py.File(nodes_h5_path, 'r') as h5:
        assert('/nodes/test' in h5)
        assert(len(h5['/nodes/test/node_id']) == 90)
        assert(len(h5['/nodes/test/node_type_id']) == 90)
        assert(len(np.unique(h5['/nodes/test/node_type_id'])) == 5)
        assert(len(h5['/nodes/test/node_group_id']) == 90)
        assert(len(np.unique(h5['/nodes/test/node_group_id'])) == 3)
        assert(len(h5['/nodes/test/node_group_index']) == 90)

        for grp_id, grp in h5['/nodes/test'].items():
            if not isinstance(grp, h5py.Group):
                continue
            assert('common' in grp)
            assert(int('x' in grp) + int('y' in grp) + int('z' in grp) == 1)

    node_types_csv_path = os.path.join(tmp_dir, node_types_file)
    assert (os.path.exists(node_types_csv_path))
    node_types_df = pd.read_csv(node_types_csv_path, sep=' ')
    assert(len(node_types_df) == 5)
    assert('node_type_id' in node_types_df.columns)
    assert('model' in node_types_df.columns)
    assert('p' in node_types_df.columns)

    barrier()
Ejemplo n.º 25
0
def test_add_node_ids_mixed():
    net = NetworkBuilder('V1')
    net.add_nodes(N=3, node_id=[0, 2, 4], vals=[0, 2, 4])
    net.add_nodes(N=3, vals=[1, 1, 1])
    net.add_nodes(nodes_ids=[6], vals=[6])
    unique_ids = set()
    for n in net.nodes():
        unique_ids.add(n.node_id)
        if n.node_id % 2 == 0:
            assert(n['vals'] == n.node_id)
        else:
            assert(n['vals'] == 1)
    assert(len(unique_ids) == 7)
Ejemplo n.º 26
0
def test_itr_advanced_search():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=1, cell_type='Scnna1', ei='e')
    net.add_nodes(N=50, cell_type='PV1', ei='i')
    net.add_nodes(N=100, cell_type='PV2', ei='i')
    net.add_edges(source={'ei': 'e'},
                  target={'ei': 'i'},
                  connection_rule=5,
                  syn_type='e2i',
                  nm='A')
    net.add_edges(source={'cell_type': 'PV1'},
                  target={'cell_type': 'PV2'},
                  connection_rule=5,
                  syn_type='i2i',
                  nm='B')
    net.add_edges(source={'cell_type': 'PV2'},
                  target={'ei': 'i'},
                  connection_rule=5,
                  syn_type='i2i',
                  nm='C')
    net.build()

    edges = net.edges(target_nodes=net.nodes(cell_type='Scnna1'))
    assert (len(edges) == 0)

    edges = net.edges(source_nodes={'ei': 'e'}, target_nodes={'ei': 'i'})
    assert (len(edges) == 50 + 100)

    edges = net.edges(source_nodes=[n.node_id for n in net.nodes(ei='e')])
    assert (len(edges) == 50 + 100)

    edges = net.edges(source_nodes={'ei': 'i'})
    assert (len(edges) == 100 * 100 * 2)
    for e in edges:
        assert (e['syn_type'] == 'i2i')

    edges = net.edges(syn_type='i2i')
    print len(edges) == 100 * 100 * 2
    for e in edges:
        assert (e['nm'] != 'A')

    edges = net.edges(syn_type='i2i', nm='C')
    assert (len(edges) == 100 * 150)
Ejemplo n.º 27
0
def test_build_nodes():
    net = NetworkBuilder('NET1')
    net.add_nodes(N=100,
                  position=[(100.0, -50.0, 50.0)] * 100,
                  tunning_angle=np.linspace(0, 365.0, 100, endpoint=False),
                  cell_type='Scnna1',
                  model_type='Biophys1',
                  location='V1',
                  ei='e')

    net.add_nodes(N=25,
                  position=np.random.rand(25, 3) * [100.0, 50.0, 100.0],
                  model_type='intfire1',
                  location='V1',
                  ei='e')

    net.add_nodes(N=150,
                  position=np.random.rand(150, 3) * [100.0, 50.0, 100.0],
                  tunning_angle=np.linspace(0, 365.0, 150, endpoint=False),
                  cell_type='SST',
                  model_type='Biophys1',
                  location='V1',
                  ei='i')

    net.build()
    assert (net.nodes_built is True)
    assert (net.nnodes == 275)
    assert (net.nedges == 0)
    assert (len(net.nodes()) == 275)
    assert (len(net.nodes(ei='e')) == 125)
    assert (len(net.nodes(model_type='Biophys1')) == 250)
    assert (len(net.nodes(location='V1', model_type='Biophys1')))

    intfire_nodes = list(net.nodes(model_type='intfire1'))
    assert (len(intfire_nodes) == 25)
    node1 = intfire_nodes[0]
    assert (node1['model_type'] == 'intfire1' and 'cell_type' not in node1)
Ejemplo n.º 28
0
from bmtk.builder import NetworkBuilder

net = NetworkBuilder('brunel')
net.add_nodes(pop_name='excitatory',
              ei='e',
              model_type='population',
              model_template='dipde:Internal',
              dynamics_params='exc_model.json')

net.add_nodes(pop_name='inhibitory',
              ei='i',
              model_type='population',
              model_template='dipde:Internal',
              dynamics_params='inh_model.json')

net.add_edges(source={'ei': 'e'}, target={'ei': 'i'},
              syn_weight=0.005,
              nsyns=20,
              delay=0.002,
              dynamics_params='ExcToInh.json')

net.add_edges(source={'ei': 'i'}, target={'ei': 'e'},
              syn_weight=-0.002,
              nsyns=10,
              delay=0.002,
              dynamics_params='InhToExc.json')

net.build()
net.save_nodes(nodes_file_name='brunel_nodes.h5', node_types_file_name='brunel_node_types.csv', output_dir='network')
net.save_edges(edges_file_name='brunel_edges.h5', edge_types_file_name='brunel_edge_types.csv', output_dir='network')
Ejemplo n.º 29
0
syn = synapses.syn_params_dicts()

# Initialize our network

net = NetworkBuilder("biophysical")

num_inh = [1]

num_exc = [1]

##################################################################################
###################################BIOPHY#########################################

net.add_nodes(N=5,
              pop_name='PyrA',
              mem_potential='e',
              model_type='biophysical',
              model_template='hoc:feng_typeA',
              morphology=None)

net.add_nodes(N=3,
              pop_name='PyrC',
              mem_potential='e',
              model_type='biophysical',
              model_template='hoc:feng_typeC',
              morphology=None)
net.add_nodes(N=2,
              pop_name='OLM',
              mem_potential='e',
              model_type='biophysical',
              model_template='hoc:SOM_Cell',
              morphology=None)
Ejemplo n.º 30
0
#     else:
#         raise Exception("no work" + str(sys.argv[-1]))

N = 1#int(inp)

np.random.seed(2129)
#np.random.seed(42)

# synapses.load()
# syn = synapses.syn_params_dicts()

net = NetworkBuilder("biophysical")

net.add_nodes(N=N, pop_name='Pyrc',
    potental='exc',
    model_type='biophysical',
    model_template='hoc:L5PCtemplate',
    morphology = None)

# exc_stim = NetworkBuilder('exc_stim')
# exc_stim.add_nodes(N=1,
#                 pop_name='exc_stim',
#                 potential='exc',
#                 model_type='virtual')
                

# # Create connections between Exc --> Pyr cells
# net.add_edges(source=exc_stim.nodes(), target=net.nodes(),
#                 connection_rule=1,
#                 syn_weight=1,
#                 target_sections=['apic', 'dend'],