def emulate(n, steps): assert(n>1) n = str(n) # Set up emulation: man = Manager(get_random_port(), get_random_port(), get_random_port()) man.add_brok() m1_int_sel_in_gpot = '/a/in/gpot0,/a/in/gpot1' m1_int_sel_out_gpot = '/a/out/gpot0,/a/out/gpot1' m1_int_sel_in_spike = '/a/in/spike0,/a/in/spike1' m1_int_sel_out_spike = '/a/out/spike0,/a/out/spike1' m1_int_sel = ','.join([m1_int_sel_in_gpot, m1_int_sel_out_gpot, m1_int_sel_in_spike, m1_int_sel_out_spike]) m1_int_sel_in = ','.join([m1_int_sel_in_gpot, m1_int_sel_in_spike]) m1_int_sel_out = ','.join([m1_int_sel_out_gpot, m1_int_sel_out_spike]) m1_int_sel_gpot = ','.join([m1_int_sel_in_gpot, m1_int_sel_out_gpot]) m1_int_sel_spike = ','.join([m1_int_sel_in_spike, m1_int_sel_out_spike]) N1_gpot = SelectorMethods.count_ports(m1_int_sel_gpot) N1_spike = SelectorMethods.count_ports(m1_int_sel_spike) m1 = MyModule(m1_int_sel, m1_int_sel_in, m1_int_sel_out, m1_int_sel_gpot, m1_int_sel_spike, np.zeros(N1_gpot, np.float64), np.zeros(N1_spike, int), ['interface', 'io', 'type'], man.port_data, man.port_ctrl, man.port_time, 'm1', None, False, True) man.add_mod(m1) m2_int_sel_in_gpot = '/b/in/gpot0,/b/in/gpot1' m2_int_sel_out_gpot = '/b/out/gpot0,/b/out/gpot1' m2_int_sel_in_spike = '/b/in/spike0,/b/in/spike1' m2_int_sel_out_spike = '/b/out/spike0,/b/out/spike1' m2_int_sel = ','.join([m2_int_sel_in_gpot, m2_int_sel_out_gpot, m2_int_sel_in_spike, m2_int_sel_out_spike]) m2_int_sel_in = ','.join([m2_int_sel_in_gpot, m2_int_sel_in_spike]) m2_int_sel_out = ','.join([m2_int_sel_out_gpot, m2_int_sel_out_spike]) m2_int_sel_gpot = ','.join([m2_int_sel_in_gpot, m2_int_sel_out_gpot]) m2_int_sel_spike = ','.join([m2_int_sel_in_spike, m2_int_sel_out_spike]) N2_gpot = SelectorMethods.count_ports(m2_int_sel_gpot) N2_spike = SelectorMethods.count_ports(m2_int_sel_spike), m2 = MyModule(m2_int_sel, m2_int_sel_in, m2_int_sel_out, m2_int_sel_gpot, m2_int_sel_spike, np.zeros(N2_gpot, np.float64), np.zeros(N2_spike, int), ['interface', 'io', 'type'], man.port_data, man.port_ctrl, man.port_time, 'm2', None, False, True) man.add_mod(m2) # Make sure that all ports in the patterns' interfaces are set so # that they match those of the modules: pat12 = Pattern(m1_int_sel, m2_int_sel) pat12.interface[m1_int_sel_out_gpot] = [0, 'in', 'gpot'] pat12.interface[m1_int_sel_in_gpot] = [0, 'out', 'gpot'] pat12.interface[m1_int_sel_out_spike] = [0, 'in', 'spike'] pat12.interface[m1_int_sel_in_spike] = [0, 'out', 'spike'] pat12.interface[m2_int_sel_in_gpot] = [1, 'out', 'gpot'] pat12.interface[m2_int_sel_out_gpot] = [1, 'in', 'gpot'] pat12.interface[m2_int_sel_in_spike] = [1, 'out', 'spike'] pat12.interface[m2_int_sel_out_spike] = [1, 'in', 'spike'] pat12['/a/out/gpot0', '/b/in/gpot0'] = 1 pat12['/a/out/gpot1', '/b/in/gpot1'] = 1 pat12['/b/out/gpot0', '/a/in/gpot0'] = 1 pat12['/b/out/gpot1', '/a/in/gpot1'] = 1 pat12['/a/out/spike0', '/b/in/spike0'] = 1 pat12['/a/out/spike1', '/b/in/spike1'] = 1 pat12['/b/out/spike0', '/a/in/spike0'] = 1 pat12['/b/out/spike1', '/a/in/spike1'] = 1 man.connect(m1, m2, pat12, 0, 1) # To set the emulation to exit after executing a fixed number of steps, # start it as follows and remove the sleep statement: man.start(steps=steps) # man.start() # time.sleep(2) man.stop() return m1
def N(self): return len(self.data) def run_step(self, in_dict, out): super(MyModule, self).run_step(in_dict, out) out[:] = np.random.rand(self.N) def run(self): super(MyModule, self).run() # Set up logging: logger = setup_logger() # Set up emulation: man = BaseManager(get_random_port(), get_random_port()) man.add_brok() m1 = man.add_mod(MyModule(2, 'm1 ', man.port_data, man.port_ctrl)) m2 = man.add_mod(MyModule(4, 'm2 ', man.port_data, man.port_ctrl)) m3 = man.add_mod(MyModule(3, 'm3 ', man.port_data, man.port_ctrl)) m4 = man.add_mod(MyModule(2, 'm4 ', man.port_data, man.port_ctrl)) conn12 = BaseConnectivity(2, 4, 1, m1.id, m2.id) conn12[m1.id, :, m2.id, :] = np.ones((2, 4)) conn12[m2.id, :, m1.id, :] = np.ones((4, 2)) man.connect(m1, m2, conn12) conn23 = BaseConnectivity(4, 3, 1, m2.id, m3.id) conn23[m2.id, :, m3.id, :] = np.ones((4, 3)) conn23[m3.id, :, m2.id, :] = np.ones((3, 4))
# data: # temp = np.random.randint(0, 5, self.N_in_gpot) # for i in in_gpot_dict.keys(): # temp += np.random.randint(-1, 1, 1)*in_gpot_dict[i][0] # out_gpot[:] = temp out_gpot[:] = np.random.rand(self.N_gpot) # Randomly select neurons to emit spikes: # out_spike[:] = \ # sorted(set(np.random.randint(0, self.N_in_spike, # np.random.randint(0, self.N_in_spike)))) out_spike[:] = np.arange(self.N_spike) logger = base.setup_logger() man = Manager(get_random_port(), get_random_port()) man.add_brok() N1_gpot = N1_spike = 1 N2_gpot = N2_spike = 2 m1 = man.add_mod(MyModule(N1_gpot, N1_spike, man.port_data, man.port_ctrl)) m2 = man.add_mod(MyModule(N2_gpot, N2_spike, man.port_data, man.port_ctrl)) # m3 = MyModule(N, 'unconnected', man.port_data, man.port_ctrl) # man.add_mod(m3) # m4 = MyModule(N-2, 'unconnected', man.port_data, man.port_ctrl) # man.add_mod(m4) conn1 = Connectivity(N1_gpot, N1_spike, N2_gpot, N2_spike, 1, m1.id, m2.id) # c1to2['all',:,'all',:,0,'+'] = \
# data: # temp = np.random.randint(0, 5, self.N_in_gpot) # for i in in_gpot_dict.keys(): # temp += np.random.randint(-1, 1, 1)*in_gpot_dict[i][0] # out_gpot[:] = temp out_gpot[:] = np.random.rand(self.N_gpot) # Randomly select neurons to emit spikes: # out_spike[:] = \ # sorted(set(np.random.randint(0, self.N_in_spike, # np.random.randint(0, self.N_in_spike)))) out_spike[:] = np.arange(self.N_spike) logger = base.setup_logger() man = Manager(get_random_port(), get_random_port()) man.add_brok() N1_gpot = N1_spike = 1 N2_gpot = N2_spike = 2 m1 = man.add_mod(MyModule(N1_gpot, N1_spike, man.port_data, man.port_ctrl)) m2 = man.add_mod(MyModule(N2_gpot, N2_spike, man.port_data, man.port_ctrl)) # m3 = MyModule(N, 'unconnected', man.port_data, man.port_ctrl) # man.add_mod(m3) # m4 = MyModule(N-2, 'unconnected', man.port_data, man.port_ctrl) # man.add_mod(m4) conn1 = Connectivity(N1_gpot, N1_spike, N2_gpot, N2_spike, 1, m1.id, m2.id) # c1to2['all',:,'all',:,0,'+'] = \ # rand_bin_matrix((N1_gpot+N1_spike, N2_gpot+N2_spike), # (N1_gpot+N1_spike)*(N2_gpot+N2_spike)/2, int)
def N(self): return len(self.data) def run_step(self, in_dict, out): super(MyModule, self).run_step(in_dict, out) out[:] = np.random.rand(self.N) def run(self): super(MyModule, self).run() # Set up logging: logger = setup_logger() # Set up emulation: man = BaseManager(get_random_port(), get_random_port()) man.add_brok() m1 = man.add_mod(MyModule(2, 'm1 ', man.port_data, man.port_ctrl)) m2 = man.add_mod(MyModule(4, 'm2 ', man.port_data, man.port_ctrl)) m3 = man.add_mod(MyModule(3, 'm3 ', man.port_data, man.port_ctrl)) m4 = man.add_mod(MyModule(2, 'm4 ', man.port_data, man.port_ctrl)) conn12 = BaseConnectivity(2, 4, 1, m1.id, m2.id) conn12[m1.id, :, m2.id, :] = np.ones((2, 4)) conn12[m2.id, :, m1.id, :] = np.ones((4, 2)) man.connect(m1, m2, conn12) conn23 = BaseConnectivity(4, 3, 1, m2.id, m3.id) conn23[m2.id, :, m3.id, :] = np.ones((4, 3)) conn23[m3.id, :, m2.id, :] = np.ones((3, 4))