def _encode_function(flagdef, val): assert flagdef.min is not None and flagdef.max is not None func_name = flagdef.distribution or "uniform" low = op_util.format_flag_val(flagdef.min) high = op_util.format_flag_val(flagdef.max) args = [low, high] if val is not None: initial = op_util.format_flag_val(val) args.append(initial) return "%s[%s]" % (func_name, ":".join(args))
def _format_flag_choices_dl(choices, out): out.write_heading("Choices") out.indent() out.write_dl([(op_util.format_flag_val(choice.value), "\n\n".join( choice.description.split("\n"))) for choice in choices], preserve_paragraphs=True) out.dedent()
def _row_for_print_run(run, flags, labels, status): row = {"opspec": op_util.format_op_desc(run)} if flags: flags_desc = " ".join([ "%s=%s" % (name, op_util.format_flag_val(val)) for name, val in sorted(run.get("flags").items()) ]) row["flags"] = flags_desc if labels: row["label"] = run.get("label", "") if status: row["status"] = run.status return row
def _popen_args(spec=None, cwd=None, flags=None, batch_files=None, run_dir=None, restart=None, label=None, guild_home=None, extra_env=None, optimize=False, optimizer=None, minimize=None, maximize=None, opt_flags=None, max_trials=None, random_seed=None, needed=False, init_trials=False, print_cmd=False, print_trials=False, save_trials=None, quiet=False): from guild import op_util cwd = cwd or "." flags = flags or {} opt_flags = opt_flags or {} args = [sys.executable, "-um", "guild.main_bootstrap", "run", "-y"] if spec: args.append(spec) if restart: args.extend(["--restart", restart]) if label: args.extend(['--label', label]) args.extend([ "{}={}".format(name, op_util.format_flag_val(val)) for name, val in flags.items() ]) args.extend(["@%s" % path for path in (batch_files or [])]) if run_dir: args.extend(["--run-dir", run_dir]) if optimize: args.append("--optimize") if optimizer: args.extend(["--optimizer", optimizer]) if minimize: args.extend(["--minimize", minimize]) if maximize: args.extend(["--maximize", maximize]) for name, val in opt_flags.items(): args.extend( ["--opt-flag", "{}={}".format(name, op_util.format_flag_val(val))]) if max_trials is not None: args.extend(["--max-trials", str(max_trials)]) if random_seed is not None: args.extend(["--random-seed", str(random_seed)]) if needed: args.append("--needed") if print_cmd: args.append("--print-cmd") if print_trials: args.append("--print-trials") if save_trials: args.extend(["--save-trials", save_trials]) if init_trials: args.append("--init-trials") if quiet: args.append("--quiet") env = dict(os.environ) env["NO_IMPORT_FLAGS_PROGRESS"] = "1" if extra_env: env.update(extra_env) _apply_guild_home_env(env, guild_home) _apply_python_path_env(env) _apply_lang_env(env) return args, cwd, env
def _null_label(name, opdef): flag = opdef.get_flagdef(name) if flag and flag.null_label is not None: return op_util.format_flag_val(flag.null_label) return "default"
def _format_flag(name, val, opdef): if val is None: formatted = _null_label(name, opdef) else: formatted = _strip_quotes(op_util.format_flag_val(val)) return "%s: %s" % (name, formatted)
def _format_flag_choices_value_list(choices, out): vals = [c.value for c in choices] out.write_dl([("Choices:", op_util.format_flag_val(vals))])
def _default_label(val): return op_util.format_flag_val(val)