def run(connected): """ Set `connected` to True to connect the LPUs. """ import neurokernel.mpi_relaunch out_name = 'un' if not connected else 'co' man = core.Manager() lpu_file_0 = './data/generic_lpu_0.gexf.gz' lpu_file_1 = './data/generic_lpu_1.gexf.gz' comp_dict_0, conns_0 = LPU.lpu_parser(lpu_file_0) comp_dict_1, conns_1 = LPU.lpu_parser(lpu_file_1) fl_input_processor_0 = FileInputProcessor( './data/generic_lpu_0_input.h5') fl_output_processor_0 = FileOutputProcessor( [('V', None), ('spike_state', None)], 'generic_lpu_0_%s_output.h5' % out_name, sample_interval=1) lpu_0_id = 'lpu_0' man.add(LPU, lpu_0_id, dt, comp_dict_0, conns_0, input_processors=[fl_input_processor_0], output_processors=[fl_output_processor_0], device=args.gpu_dev[0], debug=args.debug, time_sync=args.time_sync) fl_input_processor_1 = FileInputProcessor( './data/generic_lpu_1_input.h5') fl_output_processor_1 = FileOutputProcessor( [('V', None), ('spike_state', None)], 'generic_lpu_1_%s_output.h5' % out_name, sample_interval=1) lpu_1_id = 'lpu_1' man.add(LPU, lpu_1_id, dt, comp_dict_1, conns_1, input_processors=[fl_input_processor_1], output_processors=[fl_output_processor_1], device=args.gpu_dev[1], debug=args.debug, time_sync=args.time_sync) # Create random connections between the input and output ports if the LPUs # are to be connected: if connected: # Find all output and input port selectors in each LPU: out_ports_spk_0 = plsel.Selector(','.join( LPU.extract_out_spk(comp_dict_0, 'id')[0])) out_ports_gpot_0 = plsel.Selector(','.join( LPU.extract_out_gpot(comp_dict_0, 'id')[0])) out_ports_spk_1 = plsel.Selector(','.join( LPU.extract_out_spk(comp_dict_1, 'id')[0])) out_ports_gpot_1 = plsel.Selector(','.join( LPU.extract_out_gpot(comp_dict_1, 'id')[0])) in_ports_spk_0 = plsel.Selector(','.join( LPU.extract_in_spk(comp_dict_0, 'id')[0])) in_ports_gpot_0 = plsel.Selector(','.join( LPU.extract_in_gpot(comp_dict_0, 'id')[0])) in_ports_spk_1 = plsel.Selector(','.join( LPU.extract_in_spk(comp_dict_1, 'id')[0])) in_ports_gpot_1 = plsel.Selector(','.join( LPU.extract_in_gpot(comp_dict_1, 'id')[0])) out_ports_0 = plsel.Selector.union(out_ports_spk_0, out_ports_gpot_0) out_ports_1 = plsel.Selector.union(out_ports_spk_1, out_ports_gpot_1) in_ports_0 = plsel.Selector.union(in_ports_spk_0, in_ports_gpot_0) in_ports_1 = plsel.Selector.union(in_ports_spk_1, in_ports_gpot_1) # Initialize a connectivity pattern between the two sets of port # selectors: pat = pattern.Pattern( plsel.Selector.union(out_ports_0, in_ports_0), plsel.Selector.union(out_ports_1, in_ports_1)) # Create connections from the ports with identifiers matching the output # ports of one LPU to the ports with identifiers matching the input # ports of the other LPU: N_conn_spk_0_1 = min(len(out_ports_spk_0), len(in_ports_spk_1)) N_conn_gpot_0_1 = min(len(out_ports_gpot_0), len(in_ports_gpot_1)) for src, dest in zip( random.sample(out_ports_spk_0.identifiers, N_conn_spk_0_1), random.sample(in_ports_spk_1.identifiers, N_conn_spk_0_1)): pat[src, dest] = 1 pat.interface[src, 'type'] = 'spike' pat.interface[dest, 'type'] = 'spike' for src, dest in zip( random.sample(out_ports_gpot_0.identifiers, N_conn_gpot_0_1), random.sample(in_ports_gpot_1.identifiers, N_conn_gpot_0_1)): pat[src, dest] = 1 pat.interface[src, 'type'] = 'gpot' pat.interface[dest, 'type'] = 'gpot' man.connect(lpu_0_id, lpu_1_id, pat, 0, 1) man.spawn() man.start(steps=args.steps) man.wait()
s_dict_int, output_file='integrate_output.h5', device=args.al_dev, time_sync=args.time_sync) # Connect lamina to medulla: pat_lam_med = vc.create_pattern(n_dict_lam, n_dict_med) man.connect(lam_id, med_id, pat_lam_med, 0, 1, compat_check=False) # Create connectivity patterns between antennal lobe, medulla, and # integration LPUs: sel_al = LPU.extract_all(n_dict_al) sel_int = LPU.extract_all(n_dict_int) sel_med = LPU.extract_all(n_dict_med) pat_al_int = pattern.Pattern(sel_al, sel_int) pat_med_int = pattern.Pattern(sel_med, sel_int) # Define connections from antennal lobe to integration LPU: for src, dest in zip(['/al[0]/pn%d' % i for i in xrange(3)], plsel.Selector(LPU.extract_in_spk(n_dict_int))): pat_al_int[src, dest] = 1 pat_al_int.interface[src, 'type'] = 'spike' pat_al_int.interface[dest, 'type'] = 'spike' # Define connections from medulla to integration LPU: for src, dest in zip(['/medulla/Mt3%c[%d]' % (c, i) \ for c in ('h','v') for i in xrange(4)], plsel.Selector(LPU.extract_in_gpot(n_dict_int))): pat_med_int[src, dest] = 1 pat_med_int.interface[src, 'type'] = 'gpot'
in_ports_spk_0 = plsel.Selector(LPU.extract_in_spk(n_dict_0)) in_ports_gpot_0 = plsel.Selector(LPU.extract_in_gpot(n_dict_0)) in_ports_spk_1 = plsel.Selector(LPU.extract_in_spk(n_dict_1)) in_ports_gpot_1 = plsel.Selector(LPU.extract_in_gpot(n_dict_1)) out_ports_0 = plsel.Selector.union(out_ports_spk_0, out_ports_gpot_0) out_ports_1 = plsel.Selector.union(out_ports_spk_1, out_ports_gpot_1) in_ports_0 = plsel.Selector.union(in_ports_spk_0, in_ports_gpot_0) in_ports_1 = plsel.Selector.union(in_ports_spk_1, in_ports_gpot_1) # Initialize a connectivity pattern between the two sets of port # selectors: pat = pattern.Pattern(plsel.Selector.union(out_ports_0, in_ports_0), plsel.Selector.union(out_ports_1, in_ports_1)) # Create connections from the ports with identifiers matching the output # ports of one LPU to the ports with identifiers matching the input # ports of the other LPU. First, define connections from LPU0 to LPU1: N_conn_spk_0_1 = min(len(out_ports_spk_0), len(in_ports_spk_1)) N_conn_gpot_0_1 = min(len(out_ports_gpot_0), len(in_ports_gpot_1)) for src, dest in zip( random.sample(out_ports_spk_0.identifiers, N_conn_spk_0_1), random.sample(in_ports_spk_1.identifiers, N_conn_spk_0_1)): pat[src, dest] = 1 pat.interface[src, 'type'] = 'spike' pat.interface[dest, 'type'] = 'spike' for src, dest in zip( random.sample(out_ports_gpot_0.identifiers, N_conn_gpot_0_1), random.sample(in_ports_gpot_1.identifiers, N_conn_gpot_0_1)):
man.add_mod(lpu_int) tic = ptime(tic, 'Load INT LPU time') # connect lam to med pat_lam_med = vc.create_pattern(lpu_lam, lpu_med) man.connect(lpu_lam, lpu_med, pat_lam_med, 0, 1) tic = ptime(tic, 'Connect LAM and MED time') intf_al = lpu_al.interface intf_lam = lpu_lam.interface intf_med = lpu_med.interface intf_int = lpu_int.interface # Initialize connectivity patterns among LPU's pat_al_int = pattern.Pattern(','.join(intf_al.to_selectors()), ','.join(intf_int.to_selectors())) pat_med_int = pattern.Pattern(','.join(intf_med.to_selectors()), ','.join(intf_int.to_selectors())) # Create connections from antennal lobe to integration LPU for src, dest in zip(['/al[0]/pn%d' % i for i in xrange(3)], intf_int.in_ports().spike_ports().to_selectors()): pat_al_int[src, dest] = 1 pat_al_int.interface[src, 'type'] = 'spike' pat_al_int.interface[dest, 'type'] = 'spike' # Create connections from medulla to integration LPU for src, dest in zip(['/medulla/Mt3%c[%d]' % (c, i) for c in ('h','v') for i in xrange(4)], intf_int.in_ports().gpot_ports().to_selectors()): pat_med_int[src, dest] = 1 pat_med_int.interface[src, 'type'] = 'gpot'
out_ports_spk_0 = lpu_0.interface.out_ports().spike_ports().to_selectors() out_ports_gpot_0 = lpu_0.interface.out_ports().gpot_ports().to_selectors() out_ports_spk_1 = lpu_1.interface.out_ports().spike_ports().to_selectors() out_ports_gpot_1 = lpu_1.interface.out_ports().gpot_ports().to_selectors() in_ports_spk_0 = lpu_0.interface.in_ports().spike_ports().to_selectors() in_ports_gpot_0 = lpu_0.interface.in_ports().gpot_ports().to_selectors() in_ports_spk_1 = lpu_1.interface.in_ports().spike_ports().to_selectors() in_ports_gpot_1 = lpu_1.interface.in_ports().gpot_ports().to_selectors() # Initialize a connectivity pattern between the two sets of port # selectors: pat = pattern.Pattern(','.join(out_ports_0 + in_ports_0), ','.join(out_ports_1 + in_ports_1)) # Create connections from the ports with identifiers matching the output # ports of one LPU to the ports with identifiers matching the input # ports of the other LPU. First, define connections from LPU0 to LPU1: N_conn_spk_0_1 = min(len(out_ports_spk_0), len(in_ports_spk_1)) N_conn_gpot_0_1 = min(len(out_ports_gpot_0), len(in_ports_gpot_1)) for src, dest in zip(random.sample(out_ports_spk_0, N_conn_spk_0_1), random.sample(in_ports_spk_1, N_conn_spk_0_1)): pat[src, dest] = 1 pat.interface[src, 'type'] = 'spike' pat.interface[dest, 'type'] = 'spike' for src, dest in zip(random.sample(out_ports_gpot_0, N_conn_gpot_0_1), random.sample(in_ports_gpot_1, N_conn_gpot_0_1)): pat[src, dest] = 1 pat.interface[src, 'type'] = 'gpot'
def run(connected): if args.port_data is None: port_data = get_random_port() else: port_data = args.port_data if args.port_ctrl is None: port_ctrl = get_random_port() else: port_ctrl = args.port_ctrl if args.port_time is None: port_time = get_random_port() else: port_time = args.port_time out_name = 'un' if not connected else 'co' man = core.Manager(port_data, port_ctrl, port_time) man.add_brok() lpu_file_0 = './data/generic_lpu_0.gexf.gz' lpu_file_1 = './data/generic_lpu_1.gexf.gz' (n_dict_0, s_dict_0) = LPU.lpu_parser(lpu_file_0) (n_dict_1, s_dict_1) = LPU.lpu_parser(lpu_file_1) lpu_0_id = 'lpu_0' lpu_0 = LPU(dt, n_dict_0, s_dict_0, input_file='./data/generic_lpu_0_input.h5', output_file='generic_lpu_0_%s_output.h5' % out_name, port_ctrl=port_ctrl, port_data=port_data, port_time=port_time, device=args.gpu_dev[0], id=lpu_0_id, debug=args.debug, time_sync=args.time_sync) man.add_mod(lpu_0) lpu_1_id = 'lpu_1' lpu_1 = LPU(dt, n_dict_1, s_dict_1, input_file='./data/generic_lpu_1_input.h5', output_file='generic_lpu_1_%s_output.h5' % out_name, port_ctrl=port_ctrl, port_data=port_data, port_time=port_time, device=args.gpu_dev[1], id=lpu_1_id, debug=args.debug, time_sync=args.time_sync) man.add_mod(lpu_1) # Create random connections between the input and output ports if the LPUs # are to be connected: if connected: # Find all output and input port selectors in each LPU: out_ports_0 = lpu_0.interface.out_ports().to_selectors() out_ports_1 = lpu_1.interface.out_ports().to_selectors() in_ports_0 = lpu_0.interface.in_ports().to_selectors() in_ports_1 = lpu_1.interface.in_ports().to_selectors() out_ports_spk_0 = lpu_0.interface.out_ports().spike_ports().to_selectors() out_ports_gpot_0 = lpu_0.interface.out_ports().gpot_ports().to_selectors() out_ports_spk_1 = lpu_1.interface.out_ports().spike_ports().to_selectors() out_ports_gpot_1 = lpu_1.interface.out_ports().gpot_ports().to_selectors() in_ports_spk_0 = lpu_0.interface.in_ports().spike_ports().to_selectors() in_ports_gpot_0 = lpu_0.interface.in_ports().gpot_ports().to_selectors() in_ports_spk_1 = lpu_1.interface.in_ports().spike_ports().to_selectors() in_ports_gpot_1 = lpu_1.interface.in_ports().gpot_ports().to_selectors() # Initialize a connectivity pattern between the two sets of port # selectors: pat = pattern.Pattern(','.join(out_ports_0+in_ports_0), ','.join(out_ports_1+in_ports_1)) # Create connections from the ports with identifiers matching the output # ports of one LPU to the ports with identifiers matching the input # ports of the other LPU: N_conn_spk_0_1 = min(len(out_ports_spk_0), len(in_ports_spk_1)) N_conn_gpot_0_1 = min(len(out_ports_gpot_0), len(in_ports_gpot_1)) for src, dest in zip(random.sample(out_ports_spk_0, N_conn_spk_0_1), random.sample(in_ports_spk_1, N_conn_spk_0_1)): pat[src, dest] = 1 pat.interface[src, 'type'] = 'spike' pat.interface[dest, 'type'] = 'spike' for src, dest in zip(random.sample(out_ports_gpot_0, N_conn_gpot_0_1), random.sample(in_ports_gpot_1, N_conn_gpot_0_1)): pat[src, dest] = 1 pat.interface[src, 'type'] = 'gpot' pat.interface[dest, 'type'] = 'gpot' man.connect(lpu_0, lpu_1, pat, 0, 1) man.start(steps=args.steps) man.stop()