def parse_cmdline(self, args): usage = u""" pssh [options] pssh [user@site [cmd]] """ parser = OptionParser(self.chan, usage=usage) # add options from a mapping or a Registry callback self.add_cmdline_options(parser) return parser.parse_args(args)
def parse_options(): import config from options import OptionParser options = OptionParser(usage=usage, version=version, description=brief_copyright) option = options.add_option group = options.set_group listener_modes = ("on", "off", "auto") # Help options option('-B', "--build-info", action="store_true", default=False, help="Show build information") option('-C', "--copyright", action="store_true", default=False, help="Show full copyright information") option('-R', "--readme", action="store_true", default=False, help="Show the readme") # Options for configuring the base simulator option('-d', "--outdir", metavar="DIR", default="m5out", help="Set the output directory to DIR [Default: %default]") option('-r', "--redirect-stdout", action="store_true", default=False, help="Redirect stdout (& stderr, without -e) to file") option('-e', "--redirect-stderr", action="store_true", default=False, help="Redirect stderr to file") option("--stdout-file", metavar="FILE", default="simout", help="Filename for -r redirection [Default: %default]") option("--stderr-file", metavar="FILE", default="simerr", help="Filename for -e redirection [Default: %default]") option("--listener-mode", metavar="{on,off,auto}", choices=listener_modes, default="auto", help="Port (e.g., gdb) listener mode (auto: Enable if running " \ "interactively) [Default: %default]") option("--listener-loopback-only", action="store_true", default=False, help="Port listeners will only accept connections over the " \ "loopback device") option('-i', "--interactive", action="store_true", default=False, help="Invoke the interactive interpreter after running the script") option("--pdb", action="store_true", default=False, help="Invoke the python debugger before running the script") option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', help="Prepend PATH to the system path when invoking the script") option('-q', "--quiet", action="count", default=0, help="Reduce verbosity") option('-v', "--verbose", action="count", default=0, help="Increase verbosity") # Statistics options group("Statistics Options") option("--stats-file", metavar="FILE", default="stats.txt", help="Sets the output file for statistics [Default: %default]") # Configuration Options group("Configuration Options") option("--dump-config", metavar="FILE", default="config.ini", help="Dump configuration output file [Default: %default]") option("--json-config", metavar="FILE", default="config.json", help="Create JSON output of the configuration [Default: %default]") option( "--dot-config", metavar="FILE", default="config.dot", help="Create DOT & pdf outputs of the configuration [Default: %default]" ) option("--dot-dvfs-config", metavar="FILE", default=None, help="Create DOT & pdf outputs of the DVFS configuration" + \ " [Default: %default]") # Debugging options group("Debugging Options") option("--debug-break", metavar="TICK[,TICK]", action='append', split=',', help="Create breakpoint(s) at TICK(s) " \ "(kills process if no debugger attached)") option("--debug-help", action='store_true', help="Print help on debug flags") option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',', help="Sets the flags for debug output (-FLAG disables a flag)") option("--debug-start", metavar="TICK", type='int', help="Start debug output at TICK") option("--debug-end", metavar="TICK", type='int', help="End debug output at TICK") option("--debug-file", metavar="FILE", default="cout", help="Sets the output file for debug [Default: %default]") option("--debug-ignore", metavar="EXPR", action='append', split=':', help="Ignore EXPR sim objects") option("--remote-gdb-port", type='int', default=7000, help="Remote gdb base port (set to 0 to disable listening)") # Help options group("Help Options") option( "--list-sim-objects", action='store_true', default=False, help="List all built-in SimObjects, their params and default values") # load the options.py config file to allow people to set their own # default options options_file = config.get('options.py') if options_file: scope = {'options': options} execfile(options_file, scope) arguments = options.parse_args() return options, arguments
def parse_options(): import config from options import OptionParser options = OptionParser(usage=usage, version=version, description=brief_copyright) option = options.add_option group = options.set_group # Help options option('-B', "--build-info", action="store_true", default=False, help="Show build information") option('-C', "--copyright", action="store_true", default=False, help="Show full copyright information") option('-R', "--readme", action="store_true", default=False, help="Show the readme") # Options for configuring the base simulator option('-d', "--outdir", metavar="DIR", default="m5out", help="Set the output directory to DIR [Default: %default]") option('-r', "--redirect-stdout", action="store_true", default=False, help="Redirect stdout (& stderr, without -e) to file") option('-e', "--redirect-stderr", action="store_true", default=False, help="Redirect stderr to file") option("--stdout-file", metavar="FILE", default="simout", help="Filename for -r redirection [Default: %default]") option("--stderr-file", metavar="FILE", default="simerr", help="Filename for -e redirection [Default: %default]") option('-i', "--interactive", action="store_true", default=False, help="Invoke the interactive interpreter after running the script") option("--pdb", action="store_true", default=False, help="Invoke the python debugger before running the script") option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', help="Prepend PATH to the system path when invoking the script") option('-q', "--quiet", action="count", default=0, help="Reduce verbosity") option('-v', "--verbose", action="count", default=0, help="Increase verbosity") # Statistics options group("Statistics Options") option("--stats-file", metavar="FILE", default="stats.txt", help="Sets the output file for statistics [Default: %default]") # Configuration Options group("Configuration Options") option("--dump-config", metavar="FILE", default="config.ini", help="Dump configuration output file [Default: %default]") option("--json-config", metavar="FILE", default="config.json", help="Create JSON output of the configuration [Default: %default]") option( "--dot-config", metavar="FILE", default="config.dot", help="Create DOT & pdf outputs of the configuration [Default: %default]" ) # Debugging options group("Debugging Options") option("--debug-break", metavar="TIME[,TIME]", action='append', split=',', help="Cycle to create a breakpoint") option("--debug-help", action='store_true', help="Print help on trace flags") option("--debug-flags", metavar="FLAG[,FLAG]", action='append', split=',', help="Sets the flags for tracing (-FLAG disables a flag)") option("--remote-gdb-port", type='int', default=7000, help="Remote gdb base port (set to 0 to disable listening)") # Tracing options group("Trace Options") option("--trace-start", metavar="TIME", type='int', help="Start tracing at TIME (must be in ticks)") option("--trace-file", metavar="FILE", default="cout", help="Sets the output file for tracing [Default: %default]") option("--trace-ignore", metavar="EXPR", action='append', split=':', help="Ignore EXPR sim objects") # Help options group("Help Options") option( "--list-sim-objects", action='store_true', default=False, help="List all built-in SimObjects, their params and default values") # load the options.py config file to allow people to set their own # default options options_file = config.get('options.py') if options_file: scope = {'options': options} execfile(options_file, scope) arguments = options.parse_args() return options, arguments
evaluator = WEREvaluator() elif args.evaluator == "cer": evaluator = CEREvaluator() else: raise RuntimeError("Unkonwn evaluation metric {}".format( args.evaluator)) ref_corpus = read_data(args.ref_file) hyp_corpus = read_data(args.hyp_file) len_before = len(hyp_corpus) ref_corpus, hyp_corpus = zip( *filter(lambda x: NO_DECODING_ATTEMPTED not in x[1], zip(ref_corpus, hyp_corpus))) if len(ref_corpus) < len_before: print("> ignoring %s out of %s test sentences." % (len_before - len(ref_corpus), len_before)) eval_score = evaluator.evaluate(ref_corpus, hyp_corpus) return eval_score if __name__ == "__main__": parser = OptionParser() parser.add_task("evaluate", options) args = parser.args_from_command_line("evaluate", sys.argv[1:]) score = xnmt_evaluate(args) print("{} Score = {}".format(args.evaluator, score))
help="use visualization") argparser.add_argument("--dynet-gpu", action='store_true', help="use GPU acceleration") argparser.add_argument("--dynet-gpu-ids", type=int) argparser.add_argument("--generate-doc", action='store_true', help="Do not run, output documentation instead") argparser.add_argument("experiments_file") argparser.add_argument("experiment_name", nargs='*', help="Run only the specified experiments") argparser.set_defaults(generate_doc=False) args = argparser.parse_args() config_parser = OptionParser() config_parser.add_task("preproc", xnmt_preproc.options) config_parser.add_task("train", xnmt_train.options) config_parser.add_task("decode", xnmt_decode.options) config_parser.add_task("evaluate", xnmt_evaluate.options) # Tweak the options to make config files less repetitive: # - Delete evaluate:evaluator, replace with exp:eval_metrics # - Delete decode:hyp_file, evaluate:hyp_file, replace with exp:hyp_file # - Delete train:model, decode:model_file, replace with exp:model_file config_parser.remove_option("evaluate", "evaluator") config_parser.remove_option("decode", "trg_file") config_parser.remove_option("evaluate", "hyp_file") config_parser.remove_option("train", "model_file") config_parser.remove_option("decode", "model_file")
from util import attrdict, fatal import config from options import OptionParser __all__ = [ 'options', 'arguments', 'main' ] usage="%prog [m5 options] script.py [script options]" version="%prog 2.0" brief_copyright=''' Copyright (c) 2001-2008 The Regents of The University of Michigan All Rights Reserved ''' options = OptionParser(usage=usage, version=version, description=brief_copyright) add_option = options.add_option set_group = options.set_group usage = options.usage # Help options add_option('-A', "--authors", action="store_true", default=False, help="Show author information") add_option('-B', "--build-info", action="store_true", default=False, help="Show build information") add_option('-C', "--copyright", action="store_true", default=False, help="Show full copyright information") add_option('-R', "--readme", action="store_true", default=False, help="Show the readme") add_option('-N', "--release-notes", action="store_true", default=False, help="Show the release notes")