blip.py
def monitor_blip(filename, treewidth, logger: Callable, outfile="temp.res",
                 timeout=10, seed=0, solver="kg", datfile=None,
                 cwidth=0, onlyfilter=False, save_as="", debug=False):
    """
    Run BLIP in monitoring mode, where each new score update is logged

    :param filename: path to jkl file
    :param treewidth: treewidth bound (ignored if in CWIDTH_MODE)
    :param logger: logging function to be used
    :param outfile: path to .res file containing learned network (volatile)
    :param timeout: total time limit on blip computation
    :param seed: random seed passed on to blip
    :param solver: blip sub-algo to use (for tw: [kg, ka, kmax], cwidth: [old, greedy, max])
    :param datfile: path to data file (with header rows, for domain sizes)
    :param cwidth: cwidth bound (if positive, activates CWIDTH_MODE)
    :param onlyfilter: only use pset filtering algo (ignored if not in CWIDTH_MODE)
    :param save_as: filepath prefix to use for saving checkpoint solutions
    :param debug: enable debug mode
    """
    CWIDTH_MODE = cwidth > 0
    if CWIDTH_MODE:
        assert solver in ("old", "greedy", "max"), \
            f"invalid solver({solver}) for monitor_blip in CWIDTH_MODE"
        basecmd = ["java", "-jar", os.path.join(SOLVER_DIR, "blip-cw.jar"),
                   f"solver.kg.adv", "-v", "1", "-src", f"cwidth-{solver}"]
        args = ["-j", filename, "-d", datfile, "-w", "0", "-cw", str(cwidth),
                "-r", outfile, "-t", str(timeout), "-seed", str(seed)]
        if onlyfilter: args.append("-filter")
    else:
        basecmd = ["java", "-jar", os.path.join(SOLVER_DIR, "blip.jar"),
                   f"solver.{solver}", "-v", "1"]
        args = ["-j", filename, "-w", str(treewidth), "-r", outfile,
                "-t", str(timeout), "-seed", str(seed)]
    cmd = basecmd + args
    if debug: print("monitoring blip, cmd:", " ".join(cmd))
    if save_as:
        if CWIDTH_MODE:
            bnprovider = lambda: parse_res(filename, 0, outfile, cwidth=cwidth,
                                           datfile=datfile)
        else:
            bnprovider = lambda: parse_res(filename, treewidth, outfile)
        activate_checkpoints(bnprovider, save_as)
    domain_sizes = None if datfile is None else get_domain_sizes(datfile)
    with subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1,
                          universal_newlines=True) as proc:
        for line in proc.stdout:
            if debug: print("got line:", line, end='')
            match = SCORE_PATN.match(line)
            if match:
                score = float(match['score'])
                logdata = {"score": score}
                if domain_sizes is not None:
                    try:
                        bn = bnprovider()
                    except IndexError:  # todo: not reached anymore, retries, rethink
                        print("bn res file invalid (probably got overwritten)")
                        cw = acw = -1
                    else:
                        tw = bn.td.compute_width()
                        cw = compute_complexity_width(bn.td, domain_sizes)
                        logdata["tw"] = tw
                        logdata["cw"] = cw
                logger(logdata)
    print(f"done returncode: {proc.returncode}")

    Run BLIP in monitoring mode, where each new score update is logged

    :param filename: path to jkl file
    :param treewidth: treewidth bound (ignored if in CWIDTH_MODE)
    :param logger: logging function to be used
    :param outfile: path to .res file containing learned network (volatile)
    :param timeout: total time limit on blip computation
    :param seed: random seed passed on to blip
    :param solver: blip sub-algo to use (for tw: [kg, ka, kmax], cwidth: [old, greedy, max])
    :param datfile: path to data file (with header rows, for domain sizes)
    :param cwidth: cwidth bound (if positive, activates CWIDTH_MODE)
    :param onlyfilter: only use pset filtering algo (ignored if not in CWIDTH_MODE)
    :param save_as: filepath prefix to use for saving checkpoint solutions
    :param debug: enable debug mode
    
Run BLIP in monitoring mode, where each new score update is logged
Run BLIP in monitoring mode where each new score update is logged
def monitor_blip(filename, treewidth, logger: Callable, outfile="temp.res",
                 timeout=10, seed=0, solver="kg", datfile=None,
                 cwidth=0, onlyfilter=False, save_as="", debug=False):
    CWIDTH_MODE = cwidth > 0
    if CWIDTH_MODE:
        assert solver in ("old", "greedy", "max"), \
            f"invalid solver({solver}) for monitor_blip in CWIDTH_MODE"
        basecmd = ["java", "-jar", os.path.join(SOLVER_DIR, "blip-cw.jar"),
                   f"solver.kg.adv", "-v", "1", "-src", f"cwidth-{solver}"]
        args = ["-j", filename, "-d", datfile, "-w", "0", "-cw", str(cwidth),
                "-r", outfile, "-t", str(timeout), "-seed", str(seed)]
        if onlyfilter: args.append("-filter")
    else:
        basecmd = ["java", "-jar", os.path.join(SOLVER_DIR, "blip.jar"),
                   f"solver.{solver}", "-v", "1"]
        args = ["-j", filename, "-w", str(treewidth), "-r", outfile,
                "-t", str(timeout), "-seed", str(seed)]
    cmd = basecmd + args
    if debug: print("monitoring blip, cmd:", " ".join(cmd))
    if save_as:
        if CWIDTH_MODE:
            bnprovider = lambda: parse_res(filename, 0, outfile, cwidth=cwidth,
                                           datfile=datfile)
        else:
            bnprovider = lambda: parse_res(filename, treewidth, outfile)
        activate_checkpoints(bnprovider, save_as)
    domain_sizes = None if datfile is None else get_domain_sizes(datfile)
    with subprocess.Popen(cmd, stdout=subprocess.PIPE, bufsize=1,
                          universal_newlines=True) as proc:
        for line in proc.stdout:
            if debug: print("got line:", line, end='')
            match = SCORE_PATN.match(line)
            if match:
                score = float(match['score'])
                logdata = {"score": score}
                if domain_sizes is not None:
                    try:
                        bn = bnprovider()
                    except IndexError:  
                        print("bn res file invalid (probably got overwritten)")
                        cw = acw = -1
                    else:
                        tw = bn.td.compute_width()
                        cw = compute_complexity_width(bn.td, domain_sizes)
                        logdata["tw"] = tw
                        logdata["cw"] = cw
                logger(logdata)
    print(f"done returncode: {proc.returncode}")
def monitor_blip ( filename , treewidth , logger : Callable , outfile = "temp.res" , timeout = 10 , seed = 0 , solver = "kg" , datfile = None , cwidth = 0 , onlyfilter = False , save_as = "" , debug = False ) : CWIDTH_MODE = cwidth > 0 if CWIDTH_MODE : assert solver in ( "old" , "greedy" , "max" ) , f"invalid solver({solver}) for monitor_blip in CWIDTH_MODE" basecmd = [ "java" , "-jar" , os . path . join ( SOLVER_DIR , "blip-cw.jar" ) , f"solver.kg.adv" , "-v" , "1" , "-src" , f"cwidth-{solver}" ] args = [ "-j" , filename , "-d" , datfile , "-w" , "0" , "-cw" , str ( cwidth ) , "-r" , outfile , "-t" , str ( timeout ) , "-seed" , str ( seed ) ] if onlyfilter : args . append ( "-filter" ) else : basecmd = [ "java" , "-jar" , os . path . join ( SOLVER_DIR , "blip.jar" ) , f"solver.{solver}" , "-v" , "1" ] args = [ "-j" , filename , "-w" , str ( treewidth ) , "-r" , outfile , "-t" , str ( timeout ) , "-seed" , str ( seed ) ] cmd = basecmd + args if debug : print ( "monitoring blip, cmd:" , " " . join ( cmd ) ) if save_as : if CWIDTH_MODE : bnprovider = lambda : parse_res ( filename , 0 , outfile , cwidth = cwidth , datfile = datfile ) else : bnprovider = lambda : parse_res ( filename , treewidth , outfile ) activate_checkpoints ( bnprovider , save_as ) domain_sizes = None if datfile is None else get_domain_sizes ( datfile ) with subprocess . Popen ( cmd , stdout = subprocess . PIPE , bufsize = 1 , universal_newlines = True ) as proc : for line in proc . stdout : if debug : print ( "got line:" , line , end = '' ) match = SCORE_PATN . match ( line ) if match : score = float ( match [ 'score' ] ) logdata = { "score" : score } if domain_sizes is not None : try : bn = bnprovider ( ) except IndexError : print ( "bn res file invalid (probably got overwritten)" ) cw = acw = - 1 else : tw = bn . td . compute_width ( ) cw = compute_complexity_width ( bn . td , domain_sizes ) logdata [ "tw" ] = tw logdata [ "cw" ] = cw logger ( logdata ) print ( f"done returncode: {proc.returncode}" )
Run BLIP in monitoring mode, where each new score update is logged
Run BLIP in monitoring mode where each new score update is logged
"""
    Run BLIP in monitoring mode, where each new score update is logged

    :param filename: path to jkl file
    :param treewidth: treewidth bound (ignored if in CWIDTH_MODE)
    :param logger: logging function to be used
    :param outfile: path to .res file containing learned network (volatile)
    :param timeout: total time limit on blip computation
    :param seed: random seed passed on to blip
    :param solver: blip sub-algo to use (for tw: [kg, ka, kmax], cwidth: [old, greedy, max])
    :param datfile: path to data file (with header rows, for domain sizes)
    :param cwidth: cwidth bound (if positive, activates CWIDTH_MODE)
    :param onlyfilter: only use pset filtering algo (ignored if not in CWIDTH_MODE)
    :param save_as: filepath prefix to use for saving checkpoint solutions
    :param debug: enable debug mode
    """ # todo: not reached anymore, retries, rethink
filename
path to jkl file
path to jkl file
treewidth
treewidth bound (ignored if in CWIDTH_MODE)
treewidth bound ( ignored if in CWIDTH_MODE )
logger
Callable
logging function to be used
logging function to be used
outfile
path to .res file containing learned network (volatile)
path to . res file containing learned network ( volatile )
timeout
total time limit on blip computation
total time limit on blip computation
seed
random seed passed on to blip
random seed passed on to blip
solver
blip sub-algo to use (for tw: [kg, ka, kmax], cwidth: [old, greedy, max])
blip sub - algo to use ( for tw : [ kg ka kmax ] cwidth : [ old greedy max ] )
datfile
path to data file (with header rows, for domain sizes)
path to data file ( with header rows for domain sizes )
cwidth
cwidth bound (if positive, activates CWIDTH_MODE)
cwidth bound ( if positive activates CWIDTH_MODE )
onlyfilter
only use pset filtering algo (ignored if not in CWIDTH_MODE)
only use pset filtering algo ( ignored if not in CWIDTH_MODE )
save_as
filepath prefix to use for saving checkpoint solutions
filepath prefix to use for saving checkpoint solutions
debug
enable debug mode
enable debug mode