def initialize(): try: opts, args = getopt.getopt(sys.argv[1:], 'M:chf:t:v:s:Tp:o:v:w:k:', [ 'help', 'citation', 'input_path=', 'output_path=', 'graph_type', 'seed=', 'test', 'params=', 'visualizer=', 'verbose=', 'planar=', 'metrics:' ]) except Exception as inst: print('Error parsing options:') print(inst) show_usage() sys.exit(1) input_path = None sgiven = False graph_type = 'AUTODETECT' verbose = True write_graph = True compare_replica = True input_path = None output_path = None visualizer = None planar = False params = {} if opts == []: try: return input_prompter() except: show_usage() sys.exit(1) for o, a in opts: if o in ('-c', '--citation'): print("Please cite:") print("\n".join(citation)) sys.exit(0) if o in ('-h', '--help'): show_usage() sys.exit(0) elif o in ('-f', '--input_path'): input_path = a elif o in ('-M', '--metrics'): compare_replica = (a.lower() == 'true') elif o in ('-o', '--output_path'): output_path = a elif o in ('-p', '--params'): try: params.update(eval(a.strip())) except Exception as inst: print('Error parsing parameters! Given:') print(a) raise elif o in ('-s', '--seed'): sgiven = True random.seed(int(a)) npr.seed(int(a)) print('Warning: the random SEED was specified.') elif o in ('-t', '--graph_type'): graph_type = a elif o in ('-T', '--test'): simpletesters.smoke_test() sys.exit(0) elif o in ('-v', '--visualizer'): visualizer = a elif o in ('--verbose'): verbose = (a.lower() != 'false') params['verbose'] = verbose elif o in ('-w', '--write_graph'): write_graph = (a.lower() != 'false') elif o in ('-k', '--planar'): planar = (a.lower() != 'false') else: print('Unrecognized option: %s' % o) show_usage() sys.exit(1) if input_path == None or not os.path.exists(input_path): raise IOError('Cannot open: ' + str(input_path)) if not sgiven: seed = npr.randint(1E6) if verbose: print('random number generator seed: %d' % seed) random.seed(seed) npr.seed(seed) ret = { 'params': params, 'input_path': input_path, 'graph_type': graph_type, 'visualizer': output_path, 'output_path': output_path, 'visualizer': visualizer, 'verbose': verbose, 'compare_replica': compare_replica, 'write_graph': write_graph, 'planar': planar } return ret
elif o in ("-p", "--params"): try: params.update(eval(a.strip())) except Exception, inst: print "Error parsing parameters! Given:" print a raise elif o in ("-s", "--seed"): sgiven = True random.seed(int(a)) npr.seed(int(a)) print "Warning: the random SEED was specified." elif o in ("-t", "--graph_type"): graph_type = a elif o in ("-T", "--test"): simpletesters.smoke_test() sys.exit(0) elif o in ("-v", "--visualizer"): visualizer = a elif o in ("--verbose"): verbose = a.lower() != "false" params["verbose"] = verbose elif o in ("-w", "--write_graph"): write_graph = a.lower() != "false" else: print "Unrecognized option: %s" % o show_usage() sys.exit(1) if input_path == None or not os.path.exists(input_path): raise IOError, "Cannot open: " + str(input_path)
elif o in ('-p', '--params'): try: params.update(eval(a.strip())) except Exception, inst: print 'Error parsing parameters! Given:' print a raise elif o in ('-s', '--seed'): sgiven = True random.seed(int(a)) npr.seed(int(a)) print 'Warning: the random SEED was specified.' elif o in ('-t', '--graph_type'): graph_type = a elif o in ('-T', '--test'): simpletesters.smoke_test() sys.exit(0) elif o in ('-v', '--visualizer'): visualizer = a elif o in ('--verbose'): verbose = (a.lower() != 'false') params['verbose'] = verbose elif o in ('-w', '--write_graph'): write_graph = (a.lower() != 'false') else: print 'Unrecognized option: %s' % o show_usage() sys.exit(1) if input_path == None or not os.path.exists(input_path): raise IOError, 'Cannot open: ' + str(input_path)
def initialize(): try: opts, args = getopt.getopt(sys.argv[1:], 'M:chf:t:v:s:Tp:o:v:w:', ['help', 'citation', 'input_path=', 'output_path=', 'graph_type', 'seed=', 'test', 'params=', 'visualizer=', 'verbose=', 'metrics:']) except Exception as inst: print('Error parsing options:') print(inst) show_usage() sys.exit(1) input_path = None sgiven = False graph_type = 'AUTODETECT' verbose = True write_graph= True compare_replica = False input_path = None output_path= None visualizer = None params = {} if opts == []: try: return input_prompter() except: show_usage() sys.exit(1) for o, a in opts: if o in ('-c', '--citation'): print("Please cite:") print("\n".join(citation)) sys.exit(0) if o in ('-h', '--help'): show_usage() sys.exit(0) elif o in ('-f', '--input_path'): input_path = a elif o in ('-M', '--metrics'): compare_replica = (a.lower() == 'true') elif o in ('-o', '--output_path'): output_path = a elif o in ('-p', '--params'): try: params.update(eval(a.strip())) except Exception as inst: print('Error parsing parameters! Given:') print(a) raise elif o in ('-s', '--seed'): sgiven = True random.seed(int(a)) npr.seed(int(a)) print('Warning: the random SEED was specified.') elif o in ('-t', '--graph_type'): graph_type = a elif o in ('-T', '--test'): simpletesters.smoke_test() sys.exit(0) elif o in ('-v', '--visualizer'): visualizer = a elif o in ('--verbose'): verbose = (a.lower() != 'false') params['verbose'] = verbose elif o in ('-w', '--write_graph'): write_graph = (a.lower() != 'false') else: print('Unrecognized option: %s'%o) show_usage() sys.exit(1) if input_path == None or not os.path.exists(input_path): raise IOError('Cannot open: '+str(input_path)) if not sgiven: seed = npr.randint(1E6) if verbose: print('random number generator seed: %d'%seed) random.seed(seed) npr.seed(seed) ret = {'params':params, 'input_path':input_path, 'graph_type':graph_type, 'visualizer':output_path, 'output_path':output_path, 'visualizer':visualizer, 'verbose':verbose, 'compare_replica':compare_replica, 'write_graph':write_graph} return ret