def add_worker_LPU(config, retina_index, retina, manager): gexf_filename = config['Retina']['gexf_file'] suffix = config['General']['file_suffix'] dt = config['General']['dt'] debug = config['Retina']['debug'] time_sync = config['Retina']['time_sync'] worker_num = config['Retina']['worker_num'] gexf_file = '{}{}_{}{}.gexf.gz'.format(gexf_filename, 0, retina_index, suffix) G = retina.get_worker_graph(retina_index + 1, worker_num) #G = nx.convert_node_labels_to_integers(G) nx.write_gexf(G, gexf_file) worker_dev = retina_index (comp_dict, conns) = LPU.lpu_parser(gexf_file) worker_id = get_worker_id(retina_index) extra_comps = [Photoreceptor] manager.add(LPU, worker_id, dt, comp_dict, conns, device=worker_dev, debug=debug, time_sync=time_sync, extra_comps=extra_comps)
def main(): import neurokernel.mpi_relaunch logger = setup_logger(file_name=None, screen=True) parser = argparse.ArgumentParser() parser.add_argument( "-l", "--layers", dest="num_layers", type=int, default=16, help="number of layers of ommatidia on circle" ) parser.add_argument("-i", "--input", action="store_true", help="generates input if set") parser.add_argument("-g", "--gexf", action="store_true", help="generates gexf of LPU if set") parser.add_argument("--steps", default=100, type=int, help="simulation steps") args = parser.parse_args() dt = 1e-4 GEXF_FILE = "retina.gexf.gz" INPUT_FILE = "vision_input.h5" IMAGE_FILE = "image1.mat" OUTPUT_FILE = "retina_output.h5" if args.input: print("Generating input of model from image file") generate_input(INPUT_FILE, IMAGE_FILE, args.num_layers) if args.gexf: print("Writing retina lpu") n = args.num_layers photoreceptor_num = 6 * (3 * n * (n + 1) + 1) generate_gexf(GEXF_FILE, photoreceptor_num) man = core_gpu.Manager() print("Parsing lpu data") n_dict_ret, s_dict_ret = LPU.lpu_parser(GEXF_FILE) print("Initializing LPU") man.add( LPU, "retina", dt, n_dict_ret, s_dict_ret, input_file=INPUT_FILE, output_file=OUTPUT_FILE, device=0, debug=True, time_sync=False, ) man.spawn() print("Starting simulation") start_time = time.time() man.start(steps=args.steps) man.wait() print("Simulation complete: Duration {} seconds".format(time.time() - start_time))
def add_master_LPU(config, retina_index, retina, manager): dt = config['General']['dt'] debug = config['Retina']['debug'] time_sync = config['Retina']['time_sync'] input_filename = config['Retina']['input_file'] output_filename = config['Retina']['output_file'] gexf_filename = config['Retina']['gexf_file'] suffix = config['General']['file_suffix'] output_file = '{}{}{}.h5'.format(output_filename, retina_index, suffix) gexf_file = '{}{}{}.gexf.gz'.format(gexf_filename, retina_index, suffix) inputmethod = config['Retina']['inputmethod'] if inputmethod == 'read': print('Generating input files') with Timer('input generation'): input_processor = RetinaFileInputProcessor(config, retina) else: print('Using input generating function') input_processor = RetinaInputProcessor(config, retina) input_processor = get_input_gen(config, retina) uids_to_record = [ 'ret_{}_{}'.format(name, i) for i in range(retina.num_elements) for name in ['R1', 'R2', 'R3', 'R4', 'R5', 'R6'] ] output_processor = FileOutputProcessor([('V', uids_to_record)], output_file, sample_interval=1) G = retina.get_master_graph() nx.write_gexf(G, gexf_file) (comp_dict, conns) = LPU.lpu_parser(gexf_file) master_id = get_master_id(retina_index) extra_comps = [BufferPhoton, BufferVoltage] manager.add(LPU, master_id, dt, comp_dict, conns, device=retina_index, input_processors=[input_processor], output_processors=[output_processor], debug=debug, time_sync=time_sync, extra_comps=extra_comps)
if args.log.lower() in ['screen', 'both']: screen = True logger = base.setup_logger(file_name, screen) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() # Load configurations for lamina, medulla and antennal lobe models: (n_dict_al, s_dict_al) = LPU.lpu_parser('./data/antennallobe.gexf.gz') lpu_al = LPU(dt, n_dict_al, s_dict_al, input_file='./data/olfactory_input.h5', output_file='antennallobe_output.h5', port_ctrl=man.port_ctrl, port_data=man.port_data, device=args.al_dev, id='antennallobe') man.add_mod(lpu_al) (n_dict_lam, s_dict_lam) = LPU.lpu_parser('./data/lamina.gexf.gz') lpu_lam = LPU(dt, n_dict_lam, s_dict_lam,
import h5py import networkx as nx import argparse import itertools import random import pickle import neurokernel.mpi_relaunch import neurokernel.core_gpu as core from neurokernel.LPU.InputProcessors.StepInputProcessor import StepInputProcessor from neurokernel.LPU.InputProcessors.FileInputProcessor import FileInputProcessor from neurokernel.tools.logging import setup_logger from neurokernel.LPU.LPU import LPU (comp_dict, conns) = LPU.lpu_parser('neuroballad_temp_model.gexf.gz') with open('run_parameters.pickle', 'rb') as f: run_parameters = pickle.load(f) with open('record_parameters.pickle', 'rb') as f: record_parameters = pickle.load(f) dur = 1.0 dt = 1e-4 dur = run_parameters[0] dt = run_parameters[1] fl_input_processor = FileInputProcessor('neuroballad_temp_model_input.h5') from neurokernel.LPU.OutputProcessors.FileOutputProcessor import FileOutputProcessor output_processor = FileOutputProcessor(record_parameters, 'neuroballad_temp_model_output.h5', sample_interval=1)
n = args.num_layers photoreceptor_num = 6*(3*n*(n+1)+1) generate_gexf(GEXF_FILE, photoreceptor_num) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() print('Parsing lpu data') n_dict_ret, s_dict_ret = LPU.lpu_parser(GEXF_FILE) print('Initializing LPU') lpu_ret = LPU(dt, n_dict_ret, s_dict_ret, input_file=INPUT_FILE, output_file=OUTPUT_FILE, port_ctrl=port_ctrl, port_data=port_data, device=args.ret_dev, id='retina', debug=False) man.add_mod(lpu_ret) print('Starting simulation') start_time = time.time() man.start(steps=args.steps) man.stop() print('Simulation complete: Duration {} seconds'.format(time.time() - start_time))
def run(connected): if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl out_name = 'un' if not connected else 'co' man = core.Manager(port_data, port_ctrl) 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) ge_0_id = 'ge_0' ge_0 = LPU(dt, n_dict_0, s_dict_0, input_file='./data/generic_input_0.h5', output_file='generic_output_0_%s.h5' % out_name, port_ctrl=port_ctrl, port_data=port_data, device=args.gpu_dev[0], id=ge_0_id, debug=args.debug) man.add_mod(ge_0) ge_1_id = 'ge_1' ge_1 = LPU(dt, n_dict_1, s_dict_1, input_file='./data/generic_input_1.h5', output_file='generic_output_1_%s.h5' % out_name, port_ctrl=port_ctrl, port_data=port_data, device=args.gpu_dev[1], id=ge_1_id, debug=args.debug) man.add_mod(ge_1) # Connect the public neurons in the two LPUs: df_neu_0, df_syn_0 = neurokernel.tools.graph.graph_to_df(nx.read_gexf(lpu_file_0)) df_neu_1, df_syn_1 = neurokernel.tools.graph.graph_to_df(nx.read_gexf(lpu_file_1)) # Number of public neurons in each LPU: N_spike_0 = len(df_neu_0[(df_neu_0['spiking']==True)&(df_neu_0['public']==True)]) N_gpot_0 = len(df_neu_0[(df_neu_0['spiking']==False)&(df_neu_0['public']==True)]) N_spike_1 = len(df_neu_1[(df_neu_1['spiking']==True)&(df_neu_1['public']==True)]) N_gpot_1 = len(df_neu_1[(df_neu_1['spiking']==False)&(df_neu_1['public']==True)]) # Alpha function synaptic parameters: alphasynapse_type_params = {'AlphaSynapse': ['ad', 'ar', 'gmax', 'id', 'class', 'conductance', 'reverse']} if connected: conn = core.Connectivity(N_gpot_0, N_spike_0, N_gpot_1, N_spike_1, 1, ge_0.id, ge_1.id, alphasynapse_type_params) for id, (i, j) in enumerate(itertools.product(xrange(N_spike_0), xrange(N_spike_1))): conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j] = 1 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'name'] = 'int_0to1_%s_%s' % (i, j) conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'model'] = 'AlphaSynapse' conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'ad'] = 0.19*1000 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'ar'] = 1.1*100 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'class'] = 0 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'conductance'] = True conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'gmax'] = 0.003 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'id'] = id conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'reverse'] = 0.065 man.connect(ge_0, ge_1, conn) man.start(steps=args.steps) man.stop()
# Set up several LPUs: man = core.Manager() for i, neu_num in neu_dict.iteritems(): lpu_entry = {} if i == 0: in_file_name = in_file_name_0 else: in_file_name = None lpu_file_name = 'generic_lpu_%s.gexf.gz' % i out_file_name = 'generic_lpu_%s_output.h5' % i id = 'lpu_%s' % i g.create_lpu(lpu_file_name, id, *neu_num) (n_dict, s_dict) = LPU.lpu_parser(lpu_file_name) man.add(LPU, id, dt, n_dict, s_dict, input_file=in_file_name, output_file=out_file_name, device=i, debug=args.debug, time_sync=args.time_sync) lpu_entry['lpu_file_name'] = lpu_file_name lpu_entry['in_file_name'] = in_file_name lpu_entry['out_file_name'] = out_file_name
help='GPU for medulla [default: 1]') args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() lam_id = 'lamina' (n_dict_lam, s_dict_lam) = LPU.lpu_parser('./data/lamina.gexf.gz') man.add(LPU, lam_id, dt, n_dict_lam, s_dict_lam, input_file='./data/vision_input.h5', output_file='lamina_output.h5', device=args.lam_dev, time_sync=args.time_sync) med_id = 'medulla' (n_dict_med, s_dict_med) = LPU.lpu_parser('./data/medulla.gexf.gz') man.add(LPU, med_id, dt, n_dict_med, s_dict_med, output_file='medulla_output.h5', device=args.med_dev, time_sync=args.time_sync) pat = pattern.Pattern.from_graph(nx.read_gexf('./data/lam_med.gexf.gz')) man.connect(lam_id, med_id, pat, 0, 1) man.spawn()
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()
n = args.num_layers photoreceptor_num = 6 * (3 * n * (n + 1) + 1) generate_gexf(GEXF_FILE, photoreceptor_num) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() print('Parsing lpu data') n_dict_ret, s_dict_ret = LPU.lpu_parser(GEXF_FILE) print('Initializing LPU') lpu_ret = LPU(dt, n_dict_ret, s_dict_ret, input_file=INPUT_FILE, output_file=OUTPUT_FILE, port_ctrl=port_ctrl, port_data=port_data, device=0, id='retina', debug=False) man.add_mod(lpu_ret) print('Starting simulation')
def run(connected): if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl out_name = 'un' if not connected else 'co' man = core.Manager(port_data, port_ctrl) 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) ge_0_id = 'ge_0' ge_0 = LPU(dt, n_dict_0, s_dict_0, input_file='./data/generic_input_0.h5', output_file='generic_output_0_%s.h5' % out_name, port_ctrl=port_ctrl, port_data=port_data, device=args.gpu_dev[0], id=ge_0_id, debug=args.debug) man.add_mod(ge_0) ge_1_id = 'ge_1' ge_1 = LPU(dt, n_dict_1, s_dict_1, input_file='./data/generic_input_1.h5', output_file='generic_output_1_%s.h5' % out_name, port_ctrl=port_ctrl, port_data=port_data, device=args.gpu_dev[1], id=ge_1_id, debug=args.debug) man.add_mod(ge_1) # Connect the public neurons in the two LPUs: df_neu_0, df_syn_0 = neurokernel.tools.graph.graph_to_df( nx.read_gexf(lpu_file_0)) df_neu_1, df_syn_1 = neurokernel.tools.graph.graph_to_df( nx.read_gexf(lpu_file_1)) # Number of public neurons in each LPU: N_spike_0 = len(df_neu_0[(df_neu_0['spiking'] == True) & (df_neu_0['public'] == True)]) N_gpot_0 = len(df_neu_0[(df_neu_0['spiking'] == False) & (df_neu_0['public'] == True)]) N_spike_1 = len(df_neu_1[(df_neu_1['spiking'] == True) & (df_neu_1['public'] == True)]) N_gpot_1 = len(df_neu_1[(df_neu_1['spiking'] == False) & (df_neu_1['public'] == True)]) # Alpha function synaptic parameters: alphasynapse_type_params = { 'AlphaSynapse': ['ad', 'ar', 'gmax', 'id', 'class', 'conductance', 'reverse'] } if connected: conn = core.Connectivity(N_gpot_0, N_spike_0, N_gpot_1, N_spike_1, 1, ge_0.id, ge_1.id, alphasynapse_type_params) for id, (i, j) in enumerate( itertools.product(xrange(N_spike_0), xrange(N_spike_1))): conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j] = 1 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'name'] = 'int_0to1_%s_%s' % (i, j) conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'model'] = 'AlphaSynapse' conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'ad'] = 0.19 * 1000 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'ar'] = 1.1 * 100 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'class'] = 0 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'conductance'] = True conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'gmax'] = 0.003 conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'id'] = id conn[ge_0_id, 'spike', i, ge_1_id, 'spike', j, 0, 'reverse'] = 0.065 man.connect(ge_0, ge_1, conn) man.start(steps=args.steps) man.stop()
help='Number of steps [default: %s]' % steps) parser.add_argument('-g', '--gpu_dev', default=0, type=int, help='GPU device number [default: 0]') args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() (comp_dict, conns) = LPU.lpu_parser('./data/generic_lpu.gexf.gz') #st_input_processor = StepInputProcessor('I', ['73','74','75','76','77'] , 10, 0.1,0.4) fl_input_processor = FileInputProcessor('./data/generic_input.h5') fl_output_processor = FileOutputProcessor([('V',None),('spike_state',None)], 'new_output.h5', sample_interval=1) ''' a = LPU(dt, comp_dict, conns, device=args.gpu_dev, input_processors = [st_input_processor], id='ge') ''' man.add(LPU, 'ge', dt, comp_dict, conns, device=args.gpu_dev, input_processors = [fl_input_processor], output_processors = [fl_output_processor], debug=args.debug) man.spawn() man.start(steps=args.steps) man.wait()
help='Number of steps [default: %s]' % steps) parser.add_argument('-g', '--gpu_dev', default=0, type=int, help='GPU device number [default: 0]') args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() (comp_dict, conns) = LPU.lpu_parser('./data/generic_path_integration.gexf.gz') fl_input_processor_h = FileInputProcessor('./data/h.h5') fl_input_processor_vx = FileInputProcessor('./data/vx.h5') fl_input_processor_vy = FileInputProcessor('./data/vy.h5') fl_output_processor = FileOutputProcessor([('r',None)], 'r_output.h5', sample_interval=1) man.add(LPU, 'ge', dt, comp_dict, conns, device=args.gpu_dev, input_processors = [fl_input_processor_vx, fl_input_processor_vy, fl_input_processor_h], output_processors = [fl_output_processor], debug=args.debug) man.spawn() man.start(steps=args.steps) man.wait()
else: in_file_name = None fl_input_processors = [] lpu_file_name = 'generic_lpu_%s.gexf.gz' % i out_file_name = 'generic_lpu_%s_output.h5' % i fl_output_processors = [ FileOutputProcessor([('V', None), ('spike_state', None)], out_file_name, sample_interval=1) ] id = 'lpu_%s' % i g.create_lpu(lpu_file_name, id, *neu_num) (comp_dict, conns) = LPU.lpu_parser(lpu_file_name) man.add(LPU, id, dt, comp_dict, conns, input_processors=fl_input_processors, output_processors=fl_output_processors, device=i, debug=args.debug, time_sync=args.time_sync) lpu_entry['lpu_file_name'] = lpu_file_name lpu_entry['in_file_name'] = in_file_name lpu_entry['out_file_name'] = out_file_name
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()
print('Writing lamina lpu') eyemodel.write_lamina(LAM_GEXF_FILE) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl if not args.suppress: man = core.Manager(port_data, port_ctrl) man.add_brok() print('Parsing retina lpu data') n_dict_ret, s_dict_ret = LPU.lpu_parser(RET_GEXF_FILE) print('Initializing retina LPU') lpu_ret = LPU(dt, n_dict_ret, s_dict_ret, input_file=INPUT_FILE, output_file=RET_OUTPUT_FILE, port_ctrl=port_ctrl, port_data=port_data, device=args.ret_dev, id='retina', debug=True) man.add_mod(lpu_ret) if not args.retina_only: print('Parsing lamina lpu data')
file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = base.setup_logger(file_name, screen) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() (n_dict, s_dict) = LPU.lpu_parser('./data/olfactory_lpu.gexf.gz') olf = LPU(dt, n_dict, s_dict, input_file='./data/olfactory_input.h5', output_file='olfactory_output.h5', port_ctrl=port_ctrl, port_data=port_data, device=args.gpu_dev, id='olf', debug=args.debug) man.add_mod(olf) man.start(steps=args.steps) man.stop()
help='GPU for integration [default:3]') args = parser.parse_args() dt = 1e-4 dur = 1.4 Nt = args.steps or int(dur/dt) file_name = 'neurokernel.log' if args.log.lower() in ['file', 'both'] else None screen = True if args.log.lower() in ['screen', 'both'] else False logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() # Load configurations for lamina, medulla and antennal lobe models: al_id = 'antennallobe' (n_dict_al, s_dict_al) = LPU.lpu_parser( './data/antennallobe.gexf.gz') man.add(LPU, al_id, dt, n_dict_al, s_dict_al, input_file='./data/olfactory_input.h5', output_file='antennallobe_output.h5', device=args.al_dev, time_sync=args.time_sync) lam_id = 'lamina' (n_dict_lam, s_dict_lam) = LPU.lpu_parser('./data/lamina.gexf.gz') man.add(LPU, lam_id, dt, n_dict_lam, s_dict_lam, input_file='./data/vision_input.h5', output_file='lamina_output.h5', device=args.al_dev, time_sync=args.time_sync) med_id = 'medulla' (n_dict_med, s_dict_med) = LPU.lpu_parser('./data/medulla.gexf.gz') man.add(LPU, med_id, dt, n_dict_med, s_dict_med,
file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = base.setup_logger(file_name, screen) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() (n_dict, s_dict) = LPU.lpu_parser('./data/generic_lpu.gexf.gz') ge = LPU(dt, n_dict, s_dict, input_file='./data/generic_input.h5', output_file='generic_output.h5', port_ctrl=port_ctrl, port_data=port_data, device=args.gpu_dev, id='ge', debug=args.debug) man.add_mod(ge) man.start(steps=args.steps) man.stop()
def main(): import neurokernel.mpi_relaunch logger = setup_logger(file_name=None, screen=True) parser = argparse.ArgumentParser() parser.add_argument('-l', '--layers', dest='num_layers', type=int, default=16, help='number of layers of ommatidia on circle') parser.add_argument('-i', '--input', action="store_true", help='generates input if set') parser.add_argument('-g', '--gexf', action="store_true", help='generates gexf of LPU if set') parser.add_argument('--steps', default=100, type=int, help='simulation steps') args = parser.parse_args() dt = 1e-4 GEXF_FILE = 'retina.gexf.gz' INPUT_FILE = 'vision_input.h5' IMAGE_FILE = 'image1.mat' OUTPUT_FILE = 'retina_output.h5' if args.input: print('Generating input of model from image file') generate_input(INPUT_FILE, IMAGE_FILE, args.num_layers) if args.gexf: print('Writing retina lpu') n = args.num_layers photoreceptor_num = 6 * (3 * n * (n + 1) + 1) generate_gexf(GEXF_FILE, photoreceptor_num) man = core_gpu.Manager() print('Parsing lpu data') n_dict_ret, s_dict_ret = LPU.lpu_parser(GEXF_FILE) print('Initializing LPU') man.add(LPU, 'retina', dt, n_dict_ret, s_dict_ret, input_file=INPUT_FILE, output_file=OUTPUT_FILE, device=0, debug=True, time_sync=False) man.spawn() print('Starting simulation') start_time = time.time() man.start(steps=args.steps) man.wait() print('Simulation complete: Duration {} seconds'.format(time.time() - start_time))
file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = base.setup_logger(file_name, screen) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() (n_dict, s_dict) = LPU.lpu_parser('./data/olfactory_lpu.gexf.gz') olf = LPU(dt, n_dict, s_dict, input_file='./data/olfactory_input.h5', output_file='olfactory_output.h5', port_ctrl=port_ctrl, port_data=port_data, device=args.gpu_dev, id='olf', debug=args.debug) man.add_mod(olf) man.start(steps=args.steps) man.stop()
print('Writing lamina lpu') eyemodel.write_lamina(LAM_GEXF_FILE) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl if not args.suppress: man = core.Manager(port_data, port_ctrl) man.add_brok() print('Parsing retina lpu data') n_dict_ret, s_dict_ret = LPU.lpu_parser(RET_GEXF_FILE) print('Initializing retina LPU') lpu_ret = LPU(dt, n_dict_ret, s_dict_ret, input_file=INPUT_FILE, output_file=RET_OUTPUT_FILE, port_ctrl=port_ctrl, port_data=port_data, device=args.ret_dev, id='retina', debug=True) man.add_mod(lpu_ret) if not args.retina_only: print('Parsing lamina lpu data') n_dict_lam, s_dict_lam = LPU.lpu_parser(LAM_GEXF_FILE) print('Initializing lamina LPU') lpu_lam = LPU(dt, n_dict_lam, s_dict_lam, input_file=None, output_file=LAM_OUTPUT_FILE, port_ctrl=port_ctrl,
else: port_data = args.port_data port_ctrl = args.port_ctrl for i, neu_num in neu_dict.iteritems(): lpu_entry = {} if i == 0: in_file_name = in_file_name_0 else: in_file_name = None lpu_file_name = 'generic_lpu_%s.gexf.gz' % i out_file_name = 'generic_output_%s.h5' % i g.create_lpu(lpu_file_name, *neu_num) (n_dict, s_dict) = LPU.lpu_parser(lpu_file_name) id = 'lpu_%s' % i lpu = LPU(dt, n_dict, s_dict, input_file=in_file_name, output_file=out_file_name, port_ctrl=port_ctrl, port_data=port_data, device=i, id=id, debug=args.debug) lpu_entry['lpu_file_name'] = lpu_file_name lpu_entry['in_file_name'] = in_file_name lpu_entry['out_file_name'] = out_file_name lpu_entry['lpu'] = lpu lpu_entry['id'] = id lpu_dict[i] = lpu_entry
G.node[nn] = { 'model': 'Photoreceptor', 'name' : 'neuron_0' , 'extern' : True, 'public' : False, 'spiking' : False, 'Vinit' : -0.07, 'SA' : 0.6982, 'SI' : 0.000066517, 'DRA' : 0.2285, 'DRI' : 0.00012048 } nx.write_gexf(G, 'simple_lpu.gexf.gz') (n_dict, s_dict) = LPU.lpu_parser('simple_lpu.gexf.gz') t = np.arange(0, dt*Nt, dt) I = np.zeros((Nt, 1), dtype=np.double) I[np.logical_and(t>start, t<stop)] = I_max with h5py.File('simple_input.h5', 'w') as f: f.create_dataset('array', (Nt,1), dtype=np.double, data=I) port_data = get_random_port() port_ctrl = get_random_port() lpu = LPU_retina(dt, n_dict, s_dict, input_file='retina_inputs.h5', output_file='retina_output.h5', port_ctrl=port_ctrl, port_data=port_data, device=0, id='simple', debug=False) man = Manager(port_data, port_ctrl) man.add_brok() man.add_mod(lpu)
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()
args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = base.setup_logger(file_name=file_name, screen=screen) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() (n_dict_lam, s_dict_lam) = LPU.lpu_parser('./data/lamina.gexf.gz') lpu_lam = LPU(dt, n_dict_lam, s_dict_lam, input_file='./data/vision_input.h5', output_file='lamina_output.h5', port_ctrl=port_ctrl, port_data=port_data, device=args.lam_dev, id='lamina') man.add_mod(lpu_lam) man.start(steps=args.steps) man.stop()
'--al_dev', default=0, type=int, help='GPU for antennal lobe [default:0]') args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() (n_dict, s_dict) = LPU.lpu_parser('./data/antennallobe.gexf.gz') man.add(LPU, 'al', dt, n_dict, s_dict, input_file='./data/olfactory_input.h5', output_file='olfactory_output.h5', debug=args.debug) man.spawn() man.start(steps=args.steps) man.wait()
file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = base.setup_logger(file_name=file_name, screen=screen) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl port_time = get_random_port() man = core.Manager(port_data, port_ctrl, port_time) man.add_brok() (n_dict, s_dict) = LPU.lpu_parser('./data/antennallobe.gexf.gz') al = LPU(dt, n_dict, s_dict, input_file='./data/olfactory_input.h5', output_file='olfactory_output.h5', port_ctrl=port_ctrl, port_data=port_data, device=args.al_dev, id='al', debug=args.debug) man.add_mod(al) man.start(steps=args.steps) man.stop()
args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = base.setup_logger(file_name, screen) if args.port_data is None and args.port_ctrl is None: port_data = get_random_port() port_ctrl = get_random_port() else: port_data = args.port_data port_ctrl = args.port_ctrl man = core.Manager(port_data, port_ctrl) man.add_brok() (n_dict_lam, s_dict_lam) = LPU.lpu_parser('./data/lamina.gexf.gz') lpu_lam = LPU(dt, n_dict_lam, s_dict_lam, input_file='./data/vision_input.h5', output_file='lamina_output.h5', port_ctrl=port_ctrl, port_data=port_data, device=args.lam_dev, id='lamina') man.add_mod(lpu_lam) man.start(steps=args.steps) man.stop()
help='Write connectivity structures and inter-LPU routed data in debug folder') parser.add_argument('-l', '--log', default='none', type=str, help='Log output to screen [file, screen, both, or none; default:none]') parser.add_argument('-s', '--steps', default=steps, type=int, help='Number of steps [default: %s]' % steps) parser.add_argument('-g', '--gpu_dev', default=0, type=int, help='GPU device number [default: 0]') args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() (n_dict, s_dict) = LPU.lpu_parser('./data/generic_lpu.gexf.gz') man.add(LPU, 'ge', dt, n_dict, s_dict, input_file='./data/generic_input.h5', output_file='generic_output.h5', device=args.gpu_dev, debug=args.debug) man.spawn() man.start(steps=args.steps) man.wait()
help='GPU for medulla [default: 1]') args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() lam_id = 'lamina' (n_dict_lam, s_dict_lam) = LPU.lpu_parser('./data/lamina.gexf.gz') man.add(LPU, lam_id, dt, n_dict_lam, s_dict_lam, input_file='./data/vision_input.h5', output_file='lamina_output.h5', device=args.lam_dev, time_sync=args.time_sync) med_id = 'medulla' (n_dict_med, s_dict_med) = LPU.lpu_parser('./data/medulla.gexf.gz') man.add(LPU, med_id, dt,
def main(): import neurokernel.mpi_relaunch import neurokernel.core_gpu as core (comp_dict, conns) = LPU.lpu_parser('neuroballad_temp_model.gexf.gz') with open('run_parameters.pickle', 'rb') as f: run_parameters = pickle.load(f) with open('record_parameters.pickle', 'rb') as f: record_parameters = pickle.load(f) dur = 1.0 dt = 1e-4 dur = run_parameters[0] dt = run_parameters[1] fl_input_processor = FileInputProcessor('neuroballad_temp_model_input.h5') from neurokernel.LPU.OutputProcessors.FileOutputProcessor import FileOutputProcessor output_processor = FileOutputProcessor(record_parameters, 'neuroballad_temp_model_output.h5', sample_interval=1) #Parse extra arguments parser = argparse.ArgumentParser() parser.add_argument( '--debug', default=False, dest='debug', action='store_true', help= 'Write connectivity structures and inter-LPU routed data in debug folder' ) parser.add_argument( '-l', '--log', default='file', type=str, help='Log output to screen [file, screen, both, or none; default:none]' ) parser.add_argument('-r', '--time_sync', default=False, action='store_true', help='Time data reception throughput [default: False]') parser.add_argument('-g', '--gpu_dev', default=[0, 1], type=int, nargs='+', help='GPU device numbers [default: 0 1]') parser.add_argument('-d', '--disconnect', default=False, action='store_true', help='Run with disconnected LPUs [default: False]') args = parser.parse_args() file_name = None screen = False if args.log.lower() in ['file', 'both']: file_name = 'neurokernel.log' if args.log.lower() in ['screen', 'both']: screen = True logger = setup_logger(file_name=file_name, screen=screen) man = core.Manager() man.add(LPU, 'lpu', dt, comp_dict, conns, input_processors=[fl_input_processor], output_processors=[output_processor], device=args.gpu_dev[1], debug=True) steps = int(dur / dt) man.spawn() man.start(steps=steps) man.wait()