Beispiel #1
0
def init_run(path=None):
    if not path:
        run_id = runlib.mkid()
        path = os.path.join(var.runs_dir(), run_id)
    else:
        run_id = os.path.basename(path)
    return runlib.Run(run_id, path)
Beispiel #2
0
def run_for_run_dir(run_dir):
    if run_dir[:1] == ".":
        run_dir = os.path.abspath(run_dir)
    if not os.path.isabs(run_dir):
        return None
    run_id = os.path.basename(run_dir)
    return runlib.Run(run_id, run_dir)
Beispiel #3
0
def _apply_batch_run_args(batch_run, args):
    proto_path = batch_run.guild_path("proto")
    if not os.path.exists(proto_path):
        cli.error("cannot find operation proto in %s" % proto_path)
    proto = runlib.Run("", proto_path)
    _gen_apply_run_args(proto, args)
    if not args.optimizer:
        args.optimizer = batch_run.opref.to_opspec()
def _check_needed_restart(op, args):
    assert os.path.exists(op.run_dir), op.run_dir
    run_id = os.path.basename(op.run_dir)
    assert run_id.startswith(args.restart), (run_id, args.restart)
    run = runlib.Run(run_id, op.run_dir)
    if not op_util.restart_needed(run, op.flag_vals):
        cli.out("Skipping run because flags have not changed " "(--needed specified)")
        raise SystemExit(0)
Beispiel #5
0
def _run_for_pid(pid):
    pid = _try_int(pid)
    if pid is None:
        return None
    for run_id, run_dir in var.iter_run_dirs():
        run = runlib.Run(run_id, run_dir)
        if run.pid and (run.pid == pid or _parent_pid(run.pid) == pid):
            return run
    cli.error("cannot find run for pid %i" % pid)
Beispiel #6
0
def _init_step_run(parent_run):
    """Returns the run dir for a step run.

    Directory is based on a new, unique run ID but is not created.
    """
    runs_dir = os.path.dirname(parent_run.path)
    step_run_id = runlib.mkid()
    step_run_dir = os.path.join(runs_dir, step_run_id)
    return runlib.Run(step_run_id, step_run_dir)
Beispiel #7
0
 def trial_run(self, required=False):
     trial_link = self._trial_link()
     if not os.path.exists(trial_link):
         if required:
             raise RuntimeError(
                 "trial not initialized - needs call to init")
         return None
     run_dir = os.path.realpath(trial_link)
     return runlib.Run(self.run_id, run_dir)
Beispiel #8
0
 def _init_trial_run(self, run_dir=None):
     assert isinstance(self.flags, dict), self.flags
     run_dir = run_dir or os.path.join(var.runs_dir(), self.run_id)
     run = runlib.Run(self.run_id, run_dir)
     if run.get("batch") != self.batch.batch_run.id:
         util.copytree(self.batch.proto_run.path, run_dir)
         for name, val in self.attrs.items():
             run.write_attr(name, val)
         run.write_attr("initialized", runlib.timestamp())
         run.write_attr("flags", self.flags)
         run.write_attr("batch", self.batch.batch_run.id)
     return run
Beispiel #9
0
def _apply_batch_desc(base_desc, run, seen_protos):
    proto_dir = _safe_guild_path(run, "proto", "")
    if not os.path.exists(proto_dir):
        return base_desc
    if proto_dir in seen_protos:
        # We have a cycle - drop this proto_dir
        return base_desc
    proto_run = runlib.Run("", proto_dir)
    proto_op_desc = format_operation(proto_run, seen_protos)
    parts = [proto_op_desc]
    if not base_desc.startswith("+"):
        parts.append("+")
    parts.append(base_desc)
    return "".join(parts)
Beispiel #10
0
 def f(data, y, _x):
     run_short_id = data[y][0]
     if run_short_id == NO_RUNS_CAPTION:
         return ("\nPress 'r' in the main screen to refresh the list.",
                 "There are no matching runs currently")
     title = "Run {}".format(run_short_id)
     try:
         run_id, path = next(var.find_runs(run_short_id))
     except StopIteration:
         return "This run no longer exists.", title
     else:
         run = runlib.Run(run_id, path)
         index.refresh([run], ["scalar"])
         detail = _format_run_detail(run, index)
         return detail, title
Beispiel #11
0
def _mark_impl(view, flag):
    if not view.data:
        return
    run_short_id = view.data[view.y][0]
    try:
        run_id, path = next(var.find_runs(run_short_id))
    except StopIteration:
        view.text_box(
            "This run no longer exists.\n"
            "\n"
            "Press 'q' to exist this screen and then press 'r' to "
            "refresh the list.", run_short_id)
    else:
        run = runlib.Run(run_id, path)
        _mark_run(run, flag)
        _try_mark_operation(view, flag)
Beispiel #12
0
def _init_run():
    run_id, run_dir = _run_environ()
    return runlib.Run(run_id, run_dir)
Beispiel #13
0
def one_run(run_id_prefix):
    runs = [runlib.Run(id, path) for id, path in var.find_runs(run_id_prefix)]
    return cmd_impl_support.one_run(runs, run_id_prefix)
Beispiel #14
0
def get_run(run_id, root=None):
    root = root or runs_dir()
    path = os.path.join(root, run_id)
    if os.path.exists(path):
        return runlib.Run(run_id, path)
    raise LookupError(run_id)
Beispiel #15
0
def _all_runs(root):
    return [runlib.Run(name, path) for name, path in _iter_dirs(root)]
Beispiel #16
0
def _match_proto_run(batch_run, proto_op):
    proto_run = runlib.Run("", batch_run.guild_path("proto"))
    return (proto_op.opref.is_op_run(proto_run)
            and _match_run_flags(proto_run, proto_op.flag_vals))
Beispiel #17
0
def _maybe_print_proto_flags(run, out):
    proto_dir = run.guild_path("proto")
    if os.path.exists(proto_dir):
        proto_run = runlib.Run("", proto_dir)
        out("proto-flags:", nl=False)
        out(run_util.format_attr(proto_run.get("flags", "")))
Beispiel #18
0
def _run_from_dir(run_dir):
    if not os.path.isdir(run_dir):
        return None
    run_id = os.path.basename(run_dir)
    return runlib.Run(run_id, run_dir)
Beispiel #19
0
def _init_run():
    run_id = runlib.mkid()
    run_dir = os.path.join(var.runs_dir(), run_id)
    run = runlib.Run(run_id, run_dir)
    run.init_skel()
    return run
Beispiel #20
0
 def _init_proto_run(self):
     proto_path = self.batch_run.guild_path("proto")
     if not os.path.exists(proto_path):
         raise MissingProtoError("missing operation proto in %s" %
                                 proto_path)
     return runlib.Run("", proto_path)