Commit 164443df authored by David M. Rogers's avatar David M. Rogers
Browse files

Updated rule-firing logic in graph.py.

parent a3be0f3a
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -34,9 +34,25 @@ def gen_targets(params):
                fmt = {var: n}
                yield ttype, out.format(**fmt)

# FIXME: prevent gen_targets from running too many times
#  1. remove 'loop' from rules - don't inherit
#  2. add 'n = ...' to Rule __repr__ class (so comparison is possible!
# Determine if dirname / tname must be generated by pmake
def must_generate(dirname, tname, types):
    fname = dirname / tname
    if not fname.exists():
        return True
    try:
        nrule, ftype = types[tname]
    except KeyError:
        return False # don't know how to generate

    # Check for newer inputs.
    mtime = fname.stat().st_mtime
    for t,f in gen_targets(nrule.params): # need to re-run
        f = dirname / f
        if f.exists() and f.stat().st_mtime > mtime:
            print("File %s is newer than %s - re-running %s"%
                        (f, p, nrule.params['rulename']))
            return True
    return False

# G       : networkx.DiGraph of the current computation
# types   : RuleTypes object
@@ -50,19 +66,7 @@ def append_graph(G, types, rule, args, verb=False):
      rule = addl.pop()
      for ttype, tname in gen_targets(rule.params):
        p = rule.params['dirname'] / tname
        if p.exists():
            try:
                nrule, ftype = types[tname]
            except KeyError:
                continue # no creating job found
            # Check for newer inputs.
            mtime = p.stat().st_mtime
            for t,f in gen_targets(nrule.params): # need to re-run
                f = rule.params['dirname'] / f
                if f.exists() and f.stat().st_mtime > mtime:
                    print("File %s is newer than %s - re-running %s"%(f, p, nrule.params['rulename']))
                    break
            else:
        if not must_generate(rule.params['dirname'], tname, types):
            continue
        try:
            nrule, ftype = types[tname]
+1 −0
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ class Rule:
          'setup': "",
          'mpirun': ""
    }
    varname = None
    # These variables cannot be overridden by kws to init.
    uniq = ['rulename', 'inp', 'out', 'resource', 'setup', 'script', 'loop']