def __init__(self, sel, sel_in_gpot, sel_in_spike, sel_out_gpot, sel_out_spike, data_gpot, data_spike, port_data, port_ctrl, port_time, id): super(TestModule, self).__init__(sel, Selector.add(sel_in_gpot, sel_out_gpot), Selector.add(sel_in_spike, sel_out_spike), data_gpot, data_spike, ['interface', 'io', 'type'], port_data, port_ctrl, port_time, id, None, True, True) assert SelectorMethods.is_in(sel_in_gpot, sel) assert SelectorMethods.is_in(sel_out_gpot, sel) assert SelectorMethods.are_disjoint(sel_in_gpot, sel_out_gpot) assert SelectorMethods.is_in(sel_in_spike, sel) assert SelectorMethods.is_in(sel_out_spike, sel) assert SelectorMethods.are_disjoint(sel_in_spike, sel_out_spike) self.interface[sel_in_gpot, 'io', 'type'] = ['in', 'gpot'] self.interface[sel_out_gpot, 'io', 'type'] = ['out', 'gpot'] self.interface[sel_in_spike, 'io', 'type'] = ['in', 'spike'] self.interface[sel_out_spike, 'io', 'type'] = ['out', 'spike']
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
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