Exemple #1
0
 def _run_data(self, run, index):
     formatted = run_util.format_run(run)
     return {
         "id": run.id,
         "shortId": run.short_id,
         "path": run.path,
         "operation": formatted["operation"],
         "opModel": run.opref.model_name,
         "opName": run.opref.op_name,
         "started": formatted["started"],
         "stopped": formatted["stopped"],
         "time": self._run_duration(run),
         "label": formatted["label"],
         "tags": self._format_tags(run.get("tags") or []),
         "comments": run.get("comments") or [],
         "status": run.status,
         "exitStatus": formatted["exit_status"] or None,
         "command": formatted["command"],
         "otherAttrs": self._other_attrs(run),
         "flags": run.get("flags", {}),
         "scalars": self._run_scalars(run, index),
         "env": run.get("env", {}),
         "deps": self._format_deps(run.get("deps", {})),
         "files": self._format_files(run.iter_files(), run.path),
     }
Exemple #2
0
 def _run_duration(run):
     started = run.get("started")
     if run.status == "running":
         return util.format_duration(started)
     stopped = run.get("stopped")
     if stopped:
         return util.format_duration(started, stopped)
     return ""
Exemple #3
0
def _init_steps(run):
    data = run.get("steps")
    if not data:
        return []
    if not isinstance(data, list):
        _error("invalid steps data %r: expected list" % data)
    flags = run.get("flags")
    opref = run.opref
    return [Step(step_data, flags, opref) for step_data in data]
Exemple #4
0
def format_run(run, index=None):
    return {
        "id": run.id,
        "index": _format_run_index(run, index),
        "short_index": _format_run_index(run),
        "model": run.opref.model_name,
        "op_name": run.opref.op_name,
        "operation": _format_op_desc(run.opref),
        "pkg": run.opref.pkg_name,
        "status": run.status,
        "label": run.get("label") or "",
        "pid": run.pid or "(not running)",
        "started": _format_timestamp(run.get("started")),
        "stopped": _format_timestamp(run.get("stopped")),
        "rundir": run.path,
        "command": _format_command(run.get("cmd", "")),
        "exit_status": run.get("exit_status", ""),
    }
Exemple #5
0
def run_info(args, ctx):
    runs = runs_for_args(args)
    runspec = args.run or "0"
    selected = selected_runs(runs, [runspec], ctx)
    run = cmd_impl_support.one_run(selected, runspec, ctx)
    formatted = format_run(run)
    out = cli.out
    for name in RUN_DETAIL:
        out("%s: %s" % (name, formatted[name]))
    for name in run.attr_names():
        if name not in CORE_RUN_ATTRS:
            out("%s: %s" % (name, run.get(name, "")))
    if args.env:
        out("environment:", nl=False)
        out(_format_attr_val(run.get("env", "")))
    if args.flags:
        out("flags:", nl=False)
        out(_format_attr_val(run.get("flags", "")))
    if args.files or args.all_files:
        out("files:")
        for path in sorted(run.iter_files(args.all_files)):
            out("  %s" % path)
Exemple #6
0
 def _other_attrs(run):
     return {
         name: run.get(name)
         for name in runs_impl.other_attr_names(run)
     }
Exemple #7
0
def _run_compare_attr(run):
    return run.get("compare")
Exemple #8
0
def _run_attr(run, name):
    if name in guild.run.Run.__properties__:
        return getattr(run, name)
    else:
        return run.get(name)
Exemple #9
0
def restart_needed(run, flags):
    return run.status in RESTART_NEEDED_STATUS or run.get("flags") != flags
Exemple #10
0
def run_params_for_restart(run, user_specified_params=None):
    """Returns params for use in run command for a restart of run.

    The set of applicable params in the run "run_params" attribute are
    considered. If user_specified_params contains a non-default value
    (i.e. the user has indicated she wants to use a specific value)
    that param will not be included in the result. If
    user_specified_params is None (default) then all applicable params
    for a restart that are defined in run are returned.
    """
    # Note about applicable run params:
    #
    # A limited number of params could possibly apply to args - those
    # are listed here. This list has to be maintained as new args are
    # added to the run command. Params must be included where the user
    # would reasonably assume applicability and never in cases where
    # the use of the parameter would be clearly surprising to the user
    # (e.g. reusing the 'yes' param, which would alter the expected
    # behavior of the command on a restart/rerun).
    #
    # Params that are saved as run attrs or otherwise available under
    # the run guild path (e.g. opspec, label, flags) should NOT be
    # returned in this value in the interest of elimiting redundancy
    # and potential mismtach bugs. Anyone needing those values MUST
    # read them via run attrs or applicable run interface
    # (e.g. opref in the case of opsec).
    #
    applicable_run_params = [
        "disable_plugins",
        "force_flags",
        "gpus",
        "max_trials",
        "maximize",
        "minimize",
        "no_gpus",
        "opt_flags",
        "optimizer",
        "random_seed",
    ]
    from guild.commands.run import run as run_cmd
    run_params = run.get("run_params", {})
    if not isinstance(run_params, dict):
        return
    baseline_params = run_cmd.make_context("", []).params
    result = {}
    for name in run_params:
        val = _coerce_run_param(name, run_params[name])
        if name not in applicable_run_params:
            continue
        if user_specified_params is None:
            result[name] = val
            continue
        try:
            user_specified_val = user_specified_params[name]
        except KeyError:
            result[name] = val
            continue
        if user_specified_val != baseline_params[name]:
            continue
        result[name] = val
    return result