예제 #1
0
 def test_selector_concat_empty(self):
     s = Selector.concat(Selector(''), Selector(''))
     self.assertEqual(len(s), 0)
     self.assertTrue(not s.nonempty)
     self.assertEqual(s.expanded, ((),))
     self.assertEqual(s.max_levels, 0)
     self.assertEqual(s.str, '')
예제 #2
0
 def test_selector_add_empty(self):
     s = Selector('') + Selector('')
     assert len(s) == 0
     assert not s.nonempty
     assert s.expanded == ((), )
     assert s.max_levels == 0
     assert s.str == ''
예제 #3
0
 def test_selector_concat_empty(self):
     s = Selector.concat(Selector(''), Selector(''))
     assert len(s) == 0
     assert not s.nonempty
     assert s.expanded == ((), )
     assert s.max_levels == 0
     assert s.str == ''
예제 #4
0
 def test_selector_union_empty_nonempty(self):
     a = Selector('')
     b = Selector('/x[0:3]')
     c = Selector.union(a, b)
     assert len(c) == 3
     assert c.expanded == (('x', 0), ('x', 1), ('x', 2))
     assert c.max_levels == 2
     assert c.str == '/x/0,/x/1,/x/2'
예제 #5
0
 def test_selector_union_empty(self):
     a = Selector('')
     b = Selector('')
     c = Selector.union(a, b)
     assert len(c) == 0
     assert c.expanded == ((), )
     assert c.max_levels == 0
     assert c.str == ''
예제 #6
0
 def test_selector_union_empty(self):
     a = Selector('')
     b = Selector('')
     c = Selector.union(a, b)
     self.assertEqual(len(c), 0)
     self.assertEqual(c.expanded, ((),))
     self.assertEqual(c.max_levels, 0)
     self.assertEqual(c.str, '')
예제 #7
0
 def test_selector_union_empty_nonempty(self):
     a = Selector('')
     b = Selector('/x[0:3]')
     c = Selector.union(a, b)
     self.assertEqual(len(c), 3)
     self.assertEqual(c.expanded, (('x', 0), ('x', 1), ('x', 2)))
     self.assertEqual(c.max_levels, 2)
     self.assertEqual(c.str, '/x/0,/x/1,/x/2')
예제 #8
0
 def test_selector_iter(self):
     sel = Selector('/x[0:3]')
     self.assertSequenceEqual([s for s in sel],
                              [(('x', 0),),
                               (('x', 1),),
                               (('x', 2),)])
     sel = Selector('')
     self.assertSequenceEqual([s for s in sel],
                              [((),)])
예제 #9
0
    def test_selector_concat_nonempty(self):
        s = Selector.concat(Selector('[x,y]'), Selector('[0,1]'))
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('x', 0), ('y', 1))
        assert s.max_levels == 2
        assert s.str == '/x/0,/y/1'

        self.assertRaises(Exception, Selector.concat, Selector('[x,y]'),
                          Selector('[0:3]'))
예제 #10
0
    def test_selector_concat_nonempty(self):
        s = Selector.concat(Selector('[x,y]'), Selector('[0,1]'))
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0), ('y', 1)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/x/0,/y/1')

        self.assertRaises(Exception, Selector.concat, Selector('[x,y]'),
                          Selector('[0:3]'))
예제 #11
0
def make_sels(sel_in_gpot, sel_out_gpot, sel_in_spike, sel_out_spike):
    sel_in_gpot = Selector(sel_in_gpot)
    sel_out_gpot = Selector(sel_out_gpot)
    sel_in_spike = Selector(sel_in_spike)
    sel_out_spike = Selector(sel_out_spike)

    sel = sel_in_gpot + sel_out_gpot + sel_in_spike + sel_out_spike
    sel_in = sel_in_gpot + sel_in_spike
    sel_out = sel_out_gpot + sel_out_spike
    sel_gpot = sel_in_gpot + sel_out_gpot
    sel_spike = sel_in_spike + sel_out_spike

    return sel, sel_in, sel_out, sel_gpot, sel_spike
예제 #12
0
    def test_selector_add_nonempty(self):
        s = Selector('/foo[0]')+Selector('/bar[0]')
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('foo', 0), ('bar', 0)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/foo/0,/bar/0')

        s = Selector('')+Selector('/foo[0:0]')
        self.assertEqual(len(s), 0)
        self.assertTrue(not s.nonempty)
        self.assertEqual(s.expanded, ((),))
        self.assertEqual(s.max_levels, 0)
        self.assertEqual(s.str, '')
예제 #13
0
    def test_selector_add_nonempty(self):
        s = Selector('/foo[0]') + Selector('/bar[0]')
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('foo', 0), ('bar', 0))
        assert s.max_levels == 2
        assert s.str == '/foo/0,/bar/0'

        s = Selector('') + Selector('/foo[0:0]')
        assert len(s) == 0
        assert not s.nonempty
        assert s.expanded == ((), )
        assert s.max_levels == 0
        assert s.str == ''
예제 #14
0
    def test_selector_prod_nonempty(self):
        s = Selector.prod(Selector('/x'), Selector('[0,1]'))
        assert len(s) == 2
        assert s.nonempty
        assert s.expanded == (('x', 0), ('x', 1))
        assert s.max_levels == 2
        assert s.str == '/x/0,/x/1'

        s = Selector.prod(Selector('/x[0:2]'), Selector('[a,b,c]'))
        assert len(s) == 6
        assert s.nonempty
        assert s.expanded == (('x', 0, 'a'), ('x', 0, 'b'), ('x', 0, 'c'),
                              ('x', 1, 'a'), ('x', 1, 'b'), ('x', 1, 'c'))
        assert s.str == '/x/0/a,/x/0/b,/x/0/c,/x/1/a,/x/1/b,/x/1/c'
예제 #15
0
    def test_selector_prod_nonempty(self):
        s = Selector.prod(Selector('/x'), Selector('[0,1]'))
        self.assertEqual(len(s), 2)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0), ('x', 1)))
        self.assertEqual(s.max_levels, 2)
        self.assertEqual(s.str, '/x/0,/x/1')

        s = Selector.prod(Selector('/x[0:2]'), Selector('[a,b,c]'))
        self.assertEqual(len(s), 6)
        self.assertTrue(s.nonempty)
        self.assertEqual(s.expanded, (('x', 0, 'a'), ('x', 0, 'b'), ('x', 0, 'c'),
                              ('x', 1, 'a'), ('x', 1, 'b'), ('x', 1, 'c')))
        self.assertEqual(s.str, '/x/0/a,/x/0/b,/x/0/c,/x/1/a,/x/1/b,/x/1/c')
예제 #16
0
    def test_expand_pad(self):
        result = self.sel.expand('/foo/bar[0:2],/moo', float('inf'))
        self.assertSequenceEqual(result, [('foo', 'bar', 0), ('foo', 'bar', 1),
                                          ('moo', '', '')])
        result = self.sel.expand('/foo/bar[0:2],/moo', 4)
        self.assertSequenceEqual(result, [('foo', 'bar', 0, ''),
                                          ('foo', 'bar', 1, ''),
                                          ('moo', '', '', '')])

        result = self.sel.expand(Selector('/foo/bar[0:2],/moo'), float('inf'))
        self.assertSequenceEqual(result, [('foo', 'bar', 0), ('foo', 'bar', 1),
                                          ('moo', '', '')])
        result = self.sel.expand(Selector('/foo/bar[0:2],/moo'), 4)
        self.assertSequenceEqual(result, [('foo', 'bar', 0, ''),
                                          ('foo', 'bar', 1, ''),
                                          ('moo', '', '', '')])
예제 #17
0
    def test_make_index_empty(self):
        idx = self.sel.make_index('')
        assert_index_equal(idx,
                           pd.MultiIndex(levels=[[]], labels=[[]], names=[0]))

        idx = self.sel.make_index(Selector(''))
        assert_index_equal(idx,
                           pd.MultiIndex(levels=[[]], labels=[[]], names=[0]))
예제 #18
0
    def test_trans_both(self):
        m0_sel_in_gpot = Selector('')
        m0_sel_in_spike = Selector('')
        m0_sel_out_gpot = Selector('/m0/out/gpot[0:5]')
        m0_sel_out_spike = Selector('/m0/out/spike[0:5]')
        m1_sel_in_gpot = Selector('/m1/in/gpot[0:5]')
        m1_sel_in_spike = Selector('/m1/in/spike[0:5]')
        m1_sel_out_gpot = Selector('')
        m1_sel_out_spike = Selector('')

        run_test(m0_sel_in_gpot, m0_sel_in_spike, m0_sel_out_gpot, m0_sel_out_spike,
                 m1_sel_in_gpot, m1_sel_in_spike, m1_sel_out_gpot, m1_sel_out_spike)
예제 #19
0
        sel_out_spike = Selector(sel_out_spike)

        sel = sel_in_gpot+sel_out_gpot+sel_in_spike+sel_out_spike
        sel_in = sel_in_gpot+sel_in_spike
        sel_out = sel_out_gpot+sel_out_spike
        sel_gpot = sel_in_gpot+sel_out_gpot
        sel_spike = sel_in_spike+sel_out_spike

        return sel, sel_in, sel_out, sel_gpot, sel_spike

    logger = mpi.setup_logger(screen=True, file_name='neurokernel.log',
                              mpi_comm=MPI.COMM_WORLD, multiline=True)

    man = Manager()

    m1_sel_in_gpot = Selector('/a/in/gpot[0:2]')
    m1_sel_out_gpot = Selector('/a/out/gpot[0:2]')
    m1_sel_in_spike = Selector('/a/in/spike[0:2]')
    m1_sel_out_spike = Selector('/a/out/spike[0:2]')
    m1_sel, m1_sel_in, m1_sel_out, m1_sel_gpot, m1_sel_spike = \
        make_sels(m1_sel_in_gpot, m1_sel_out_gpot, m1_sel_in_spike, m1_sel_out_spike)
    N1_gpot = SelectorMethods.count_ports(m1_sel_gpot)
    N1_spike = SelectorMethods.count_ports(m1_sel_spike)

    m2_sel_in_gpot = Selector('/b/in/gpot[0:2]')
    m2_sel_out_gpot = Selector('/b/out/gpot[0:2]')
    m2_sel_in_spike = Selector('/b/in/spike[0:2]')
    m2_sel_out_spike = Selector('/b/out/spike[0:2]')
    m2_sel, m2_sel_in, m2_sel_out, m2_sel_gpot, m2_sel_spike = \
        make_sels(m2_sel_in_gpot, m2_sel_out_gpot, m2_sel_in_spike, m2_sel_out_spike)
    N2_gpot = SelectorMethods.count_ports(m2_sel_gpot)
예제 #20
0
    def test_make_index_empty(self):
        idx = self.sel.make_index('')
        assert_index_equal(idx, pd.Index([], dtype='object'))

        idx = self.sel.make_index(Selector(''))
        assert_index_equal(idx, pd.Index([], dtype='object'))
예제 #21
0
 def test_select_Selector(self):
     result = self.sel.select(self.df, Selector('/foo/qux[0:2]'))
     idx = pd.MultiIndex.from_tuples([('foo','qux',0),
                                      ('foo','qux',1)], names=[0, 1, 2])
     assert_frame_equal(result, self.df.loc[idx])
예제 #22
0
def gen_sels(n_lpu, n_spike, n_gpot):
    """
    Generate port selectors for LPUs in benchmark test.

    Parameters
    ----------
    n_lpu : int
        Number of LPUs. Must be at least 2.
    n_spike : int
        Total number of input and output spiking ports any
        single LPU exposes to any other LPU. Each LPU will therefore
        have 2*n_spike*(n_lpu-1) total spiking ports.
    n_gpot : int
        Total number of input and output graded potential ports any
        single LPU exposes to any other LPU. Each LPU will therefore
        have 2*n_gpot*(n_lpu-1) total graded potential ports.

    Returns
    -------
    mod_sels : dict of tuples
        Ports in module interfaces; the keys are the module IDs and the values are tuples
        containing the respective selectors for all ports, all input ports, all
        output ports, all graded potential, and all spiking ports.
    pat_sels : dict of tuples
        Ports in pattern interfaces; the keys are tuples containing the two
        module IDs connected by the pattern and the values are pairs of tuples
        containing the respective selectors for all source ports, all
        destination ports, all input ports connected to the first module,
        all output ports connected to the first module, all graded potential ports
        connected to the first module, all spiking ports connected to the first
        module, all input ports connected to the second module,
        all output ports connected to the second  module, all graded potential ports
        connected to the second module, and all spiking ports connected to the second
        module.
    """

    assert n_lpu >= 2
    assert n_spike >= 0
    assert n_gpot >= 0

    mod_sels = {}
    pat_sels = {('lpu%s' % i) : {} for i in xrange(n_lpu)}

    for i in xrange(n_lpu):
        lpu_id = 'lpu%s' % i
        other_lpu_ids = '['+','.join(['lpu%s' % j for j in xrange(n_lpu) if j != i])+']'

        # Structure ports as 
        # /lpu_id/in_or_out/spike_or_gpot/[other_lpu_ids,..]/[0:n_spike]
        sel_in_gpot = Selector('/%s/in/gpot/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_gpot))
        sel_in_spike = Selector('/%s/in/spike/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_spike))
        sel_out_gpot = Selector('/%s/out/gpot/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_gpot))
        sel_out_spike = Selector('/%s/out/spike/%s/[0:%i]' % \
                    (lpu_id, other_lpu_ids, n_spike))
        mod_sels[lpu_id] = (Selector.union(sel_in_gpot, sel_in_spike,
                                           sel_out_gpot, sel_out_spike),
                            Selector.union(sel_in_gpot, sel_in_spike),
                            Selector.union(sel_out_gpot, sel_out_spike),
                            Selector.union(sel_in_gpot, sel_out_gpot),
                            Selector.union(sel_in_spike, sel_out_spike))

    for i, j in itertools.combinations(xrange(n_lpu), 2):
        lpu_i = 'lpu%s' % i
        lpu_j = 'lpu%s' % j

        sel_in_gpot_i = Selector('/%s/out/gpot/%s[0:%i]' % (lpu_i, lpu_j, n_gpot))
        sel_in_spike_i = Selector('/%s/out/spike/%s[0:%i]' % (lpu_i, lpu_j, n_spike))
        sel_out_gpot_i = Selector('/%s/in/gpot/%s[0:%i]' % (lpu_i, lpu_j, n_gpot))
        sel_out_spike_i = Selector('/%s/in/spike/%s[0:%i]' % (lpu_i, lpu_j, n_spike))

        sel_in_gpot_j = Selector('/%s/out/gpot/%s[0:%i]' % (lpu_j, lpu_i, n_gpot))
        sel_in_spike_j = Selector('/%s/out/spike/%s[0:%i]' % (lpu_j, lpu_i, n_spike))
        sel_out_gpot_j = Selector('/%s/in/gpot/%s[0:%i]' % (lpu_j, lpu_i, n_gpot))
        sel_out_spike_j = Selector('/%s/in/spike/%s[0:%i]' % (lpu_j, lpu_i, n_spike))

        # The order of these two selectors is important; the individual 'from'
        # and 'to' ports must line up properly for Pattern.from_concat to
        # produce the right pattern:
        sel_from = Selector.add(sel_in_gpot_i, sel_in_spike_i,
                                sel_in_gpot_j, sel_in_spike_j)
        sel_to = Selector.add(sel_out_gpot_j, sel_out_spike_j,
                              sel_out_gpot_i, sel_out_spike_i)
        pat_sels[(lpu_i, lpu_j)] = \
                (sel_from, sel_to,
                 Selector.union(sel_in_gpot_i, sel_in_spike_i),
                 Selector.union(sel_out_gpot_i, sel_out_spike_i),
                 Selector.union(sel_in_gpot_i, sel_out_gpot_i),
                 Selector.union(sel_in_spike_i, sel_out_spike_i),
                 Selector.union(sel_in_gpot_j, sel_in_spike_j),
                 Selector.union(sel_out_gpot_j, sel_out_spike_j),
                 Selector.union(sel_in_gpot_j, sel_out_gpot_j),
                 Selector.union(sel_in_spike_j, sel_out_spike_j))

    return mod_sels, pat_sels
예제 #23
0
 def test_selector_identifiers(self):
     a = Selector('/x[0:3]')
     self.assertEqual(a.identifiers, ['/x/0', '/x/1', '/x/2'])
예제 #24
0
    def test_transmit_spikes_one_to_many(self):
        m1_sel_in_gpot = Selector('')
        m1_sel_out_gpot = Selector('')
        m1_sel_in_spike = Selector('')
        m1_sel_out_spike = Selector('/m1/out/spike[0:4]')
        m1_sel, m1_sel_in, m1_sel_out, m1_sel_gpot, m1_sel_spike = \
            make_sels(m1_sel_in_gpot, m1_sel_out_gpot, m1_sel_in_spike, m1_sel_out_spike)
        N1_gpot = SelectorMethods.count_ports(m1_sel_gpot)
        N1_spike = SelectorMethods.count_ports(m1_sel_spike)

        m2_sel_in_gpot = Selector('')
        m2_sel_out_gpot = Selector('')
        m2_sel_in_spike = Selector('/m2/in/spike[0:4]')
        m2_sel_out_spike = Selector('')
        m2_sel, m2_sel_in, m2_sel_out, m2_sel_gpot, m2_sel_spike = \
            make_sels(m2_sel_in_gpot, m2_sel_out_gpot, m2_sel_in_spike, m2_sel_out_spike)
        N2_gpot = SelectorMethods.count_ports(m2_sel_gpot)
        N2_spike = SelectorMethods.count_ports(m2_sel_spike)

        m1_id = 'm1'
        self.man.add(MyModule1,
                     m1_id,
                     m1_sel,
                     m1_sel_in,
                     m1_sel_out,
                     m1_sel_gpot,
                     m1_sel_spike,
                     np.zeros(N1_gpot, dtype=np.double),
                     np.zeros(N1_spike, dtype=int),
                     device=0,
                     debug=debug,
                     out_spike_data=[1, 0, 0, 0])

        f, out_file_name = tempfile.mkstemp()
        os.close(f)

        m2_id = 'm2'
        self.man.add(MyModule2,
                     m2_id,
                     m2_sel,
                     m2_sel_in,
                     m2_sel_out,
                     m2_sel_gpot,
                     m2_sel_spike,
                     np.zeros(N2_gpot, dtype=np.double),
                     np.zeros(N2_spike, dtype=int),
                     device=1,
                     debug=debug,
                     out_file_name=out_file_name)

        pat12 = Pattern(m1_sel, m2_sel)
        pat12.interface[m1_sel_out_gpot] = [0, 'in', 'gpot']
        pat12.interface[m1_sel_in_gpot] = [0, 'out', 'gpot']
        pat12.interface[m1_sel_out_spike] = [0, 'in', 'spike']
        pat12.interface[m1_sel_in_spike] = [0, 'out', 'spike']
        pat12.interface[m2_sel_in_gpot] = [1, 'out', 'gpot']
        pat12.interface[m2_sel_out_gpot] = [1, 'in', 'gpot']
        pat12.interface[m2_sel_in_spike] = [1, 'out', 'spike']
        pat12.interface[m2_sel_out_spike] = [1, 'in', 'spike']
        pat12['/m1/out/spike[0]', '/m2/in/spike[0]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[1]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[2]'] = 1
        pat12['/m1/out/spike[0]', '/m2/in/spike[3]'] = 1
        self.man.connect(m1_id, m2_id, pat12, 0, 1)

        # Run emulation for 2 steps:
        self.man.spawn()
        self.man.start(2)
        self.man.wait()

        # Get output of m2:
        with open(out_file_name, 'r') as f:
            output = pickle.load(f)

        os.remove(out_file_name)
        self.assertSequenceEqual(list(output), [1, 1, 1, 1])
예제 #25
0
check_compatibility = False
if check_compatibility:
    lpu_name_to_sel_in_gpot = {}
    lpu_name_to_sel_in_spike = {}
    lpu_name_to_sel_out_gpot = {}
    lpu_name_to_sel_out_spike = {}
    lpu_name_to_sel_in = {}
    lpu_name_to_sel_out = {}
    lpu_name_to_sel_gpot = {}
    lpu_name_to_sel_spike = {}
    lpu_name_to_sel = {}

    for name in lpu_name_list:
        n_dict = lpu_name_to_n_dict[name]
        lpu_name_to_sel_in_gpot[name] = \
            Selector(LPU.extract_in_gpot(n_dict))
        lpu_name_to_sel_in_spike[name] = \
            Selector(LPU.extract_in_spk(n_dict))
        lpu_name_to_sel_out_gpot[name] = \
            Selector(LPU.extract_out_gpot(n_dict))
        lpu_name_to_sel_out_spike[name] = \
            Selector(LPU.extract_out_spk(n_dict))
        lpu_name_to_sel_in[name] = \
            Selector.union(lpu_name_to_sel_in_gpot[name], lpu_name_to_sel_in_spike[name])
        lpu_name_to_sel_out[name] = \
            Selector.union(lpu_name_to_sel_out_gpot[name], lpu_name_to_sel_out_spike[name])
        lpu_name_to_sel_gpot[name] = \
            Selector.union(lpu_name_to_sel_in_gpot[name], lpu_name_to_sel_out_gpot[name])
        lpu_name_to_sel_spike[name] = \
            Selector.union(lpu_name_to_sel_in_spike[name], lpu_name_to_sel_out_spike[name])
        lpu_name_to_sel[name] = Selector.union(lpu_name_to_sel_in[name],
예제 #26
0
def gen_sels(conn_mat, scaling=1):
    """
    Generate port selectors for LPUs in benchmark test.

    Parameters
    ----------
    conn_mat : numpy.ndarray
        Square array containing numbers of directed spiking port connections 
        between LPUs (which correspond to the row and column indices). 
    scaling : int
        Scaling factor; multiply all connection numbers by this value.

    Returns
    -------
    mod_sels : dict of tuples
        Ports in module interfaces; the keys are the module IDs and the values are tuples
        containing the respective selectors for all ports, all input ports, all
        output ports, all graded potential, and all spiking ports.
    pat_sels : dict of tuples
        Ports in pattern interfaces; the keys are tuples containing the two
        module IDs connected by the pattern and the values are pairs of tuples
        containing the respective selectors for all source ports, all
        destination ports, all input ports connected to the first module, 
        all output ports connected to the first module, all graded potential ports 
        connected to the first module, all spiking ports connected to the first
        module, all input ports connected to the second module, 
        all output ports connected to the second  module, all graded potential ports 
        connected to the second module, and all spiking ports connected to the second
        module.
    """

    conn_mat = np.asarray(conn_mat)
    r, c = conn_mat.shape
    assert r == c
    n_lpu = r

    assert scaling > 0 and isinstance(scaling, numbers.Integral)
    conn_mat *= scaling

    # Construct selectors describing the ports exposed by each module:
    mod_sels = {}
    for i in xrange(n_lpu):
        lpu_id = 'lpu%s' % i

        # Structure ports as
        # /lpu_id/in_or_out/spike_or_gpot/other_lpu_id/[0:n_spike]
        # where in_or_out is relative to module i:
        sel_in_gpot = Selector('')
        sel_out_gpot = Selector('')

        sel_in_spike = \
            Selector(','.join(['/lpu%i/in/spike/lpu%i/[0:%i]' % (i, j, n) for j, n in \
                               enumerate(conn_mat[:, i]) if (j != i and n != 0)]))
        sel_out_spike = \
            Selector(','.join(['/lpu%i/out/spike/lpu%i/[0:%i]' % (i, j, n) for j, n in \
                               enumerate(conn_mat[i, :]) if (j != i and n != 0)]))

        mod_sels[lpu_id] = (Selector.union(sel_in_gpot, sel_in_spike,
                                           sel_out_gpot, sel_out_spike),
                            Selector.union(sel_in_gpot, sel_in_spike),
                            Selector.union(sel_out_gpot, sel_out_spike),
                            Selector.union(sel_in_gpot, sel_out_gpot),
                            Selector.union(sel_in_spike, sel_out_spike))

    # Construct selectors describing the ports connected by each pattern:
    pat_sels = {}
    for i, j in itertools.combinations(xrange(n_lpu), 2):
        lpu_i = 'lpu%s' % i
        lpu_j = 'lpu%s' % j

        # The pattern's input ports are labeled "../out.." because that selector
        # describes the output ports of the connected module's interface:
        sel_in_gpot_i = Selector('')
        sel_out_gpot_i = Selector('')
        sel_in_gpot_j = Selector('')
        sel_out_gpot_j = Selector('')

        sel_in_spike_i = Selector('/%s/out/spike/%s[0:%i]' %
                                  (lpu_i, lpu_j, conn_mat[i, j]))
        sel_out_spike_i = Selector('/%s/in/spike/%s[0:%i]' %
                                   (lpu_i, lpu_j, conn_mat[j, i]))
        sel_in_spike_j = Selector('/%s/out/spike/%s[0:%i]' %
                                  (lpu_j, lpu_i, conn_mat[j, i]))
        sel_out_spike_j = Selector('/%s/in/spike/%s[0:%i]' %
                                   (lpu_j, lpu_i, conn_mat[i, j]))

        # The order of these two selectors is important; the individual 'from'
        # and 'to' ports must line up properly for Pattern.from_concat to
        # produce the right pattern:
        sel_from = Selector.add(sel_in_gpot_i, sel_in_spike_i, sel_in_gpot_j,
                                sel_in_spike_j)
        sel_to = Selector.add(sel_out_gpot_j, sel_out_spike_j, sel_out_gpot_i,
                              sel_out_spike_i)

        # Exclude scenarios where the "from" or "to" selector is empty (and
        # therefore cannot be used to construct a pattern):
        if len(sel_from) and len(sel_to):
            pat_sels[(lpu_i, lpu_j)] = \
                    (sel_from, sel_to,
                     Selector.union(sel_in_gpot_i, sel_in_spike_i),
                     Selector.union(sel_out_gpot_i, sel_out_spike_i),
                     Selector.union(sel_in_gpot_i, sel_out_gpot_i),
                     Selector.union(sel_in_spike_i, sel_out_spike_i),
                     Selector.union(sel_in_gpot_j, sel_in_spike_j),
                     Selector.union(sel_out_gpot_j, sel_out_spike_j),
                     Selector.union(sel_in_gpot_j, sel_out_gpot_j),
                     Selector.union(sel_in_spike_j, sel_out_spike_j))

    return mod_sels, pat_sels
예제 #27
0
 def test_selector_identifiers(self):
     a = Selector('/x[0:3]')
     assert a.identifiers == ['/x/0', '/x/1', '/x/2']