예제 #1
0
def run_niklas_single(aiger, simplify, report_result, timeout=None):

    orig_args = [
        [',live', '-k=l2s', '-eng=treb-abs'],
        [',live', '-k=inc'],
        [',live', '-k=l2s', '-eng=bmc'],
    ]

    simplified_args = [
        [',live', '-k=inc'],
        [',live', '-k=l2s', '-eng=bmc'],
        [',live', '-k=l2s', '-eng=treb'],
    ]

    with temp_file_names(1, suffix='.aig') as simple_aiger:

        orig_funcs = [pyabc_split.defer(run_bip)(a, aiger) for a in orig_args]
        simplified_funcs = [
            pyabc_split.defer(run_bip)(a, simple_aiger[0])
            for a in simplified_args
        ]

        with pyabc_split.make_splitter() as splitter:

            sleep_id = splitter.fork_one(
                lambda: time.sleep(timeout)) if timeout else None

            ids = splitter.fork_all(orig_funcs)
            kill_if_simplified = ids[1:]

            simplifier_id = splitter.fork_one(
                pyabc_split.defer(simplify)(aiger, simple_aiger[0]))

            for id, res in splitter:

                print 'NIKLAS: process %d finished with' % id, res

                if id == sleep_id:
                    print 'NIKLAS: timeout'
                    return False

                elif id == simplifier_id:
                    print 'NIKLAS: simplify ended'
                    if not res:
                        continue
                    print 'NIKLAS: killing'
                    splitter.kill(kill_if_simplified)
                    splitter.fork_all(simplified_funcs)
                    continue

                elif report_result(res):
                    print 'NIKLAS: RESULT'
                    return True

    return False
예제 #2
0
def run_niklas_multi(aiger, simplify, report_result):

    with open(aiger, "r") as fin:
        aig = read_aiger(fin)

    n_j_pos = aig.n_justice()
    assert n_j_pos > 0

    if n_j_pos == 1:
        return run_niklas_single(aiger, simplify, report_result=lambda res: report_result(0, res))

    with temp_file_names(n_j_pos, suffix=".aig") as single_aiger:

        def extract(j_po):
            with open(single_aiger[j_po], "w") as fout:
                write_aiger(utils.extract_justice_po(aig, j_po), fout)

        for _ in pyabc_split.split_all_full([pyabc_split.defer(extract)(i) for i in xrange(n_j_pos)]):
            pass

        unsolved = set(xrange(n_j_pos))

        timeout = 1

        while unsolved:
            for j_po in sorted(unsolved):
                if run_niklas_single(
                    single_aiger[j_po], simplify, report_result=lambda res: report_result(j_po, res), timeout=timeout
                ):
                    unsolved.remove(j_po)
            timeout *= 2

    return not unsolved
예제 #3
0
def run_niklas_multi(aiger, simplify, report_result, super_prove=None):
    
    with open(aiger, 'r') as fin:
        aig = read_aiger( fin )
        
    n_j_pos = aig.n_justice()
    assert n_j_pos > 0
    
    if n_j_pos==1:
        return run_niklas_single( aiger, simplify, report_result=lambda res: report_result(0, res), super_prove=super_prove )
    
    with temp_file_names(n_j_pos, suffix='.aig') as single_aiger:
        
        def extract(j_po):
            with open(single_aiger[j_po], 'w') as fout:
                write_aiger(utils.extract_justice_po(aig, j_po), fout)
                
        for _ in pyabc_split.split_all_full( [pyabc_split.defer(extract)(i) for i in xrange(n_j_pos) ] ):
            pass
            
        unsolved = set( xrange(n_j_pos) )
        
        timeout = 1
        
        while unsolved:
            for j_po in sorted(unsolved):
                if run_niklas_single( single_aiger[j_po], simplify, report_result=lambda res: report_result(j_po, res), timeout=timeout, super_prove=super_prove ):
                    unsolved.remove(j_po)
            timeout *= 2
        
    return not unsolved
예제 #4
0
파일: niklas.py 프로젝트: cloudcalvin/abc
def run_niklas_single(aiger, simplify, report_result, timeout=None):
    
    orig_args = [
        [ ',live', '-k=l2s', '-eng=treb-abs' ],
        [ ',live', '-k=inc' ],
        [ ',live', '-k=l2s', '-eng=bmc' ],
    ]
    
    simplified_args = [
        [ ',live', '-k=inc' ],
        [ ',live', '-k=l2s', '-eng=bmc' ],
        [ ',live', '-k=l2s', '-eng=treb' ],
    ]
    
    with temp_file_names(1, suffix='.aig') as simple_aiger:

        orig_funcs = [ pyabc_split.defer(run_bip)(a, aiger) for a in orig_args ]
        simplified_funcs = [ pyabc_split.defer(run_bip)(a, simple_aiger[0]) for a in simplified_args ]

        with pyabc_split.make_splitter() as splitter:

            sleep_id = splitter.fork_one( lambda : time.sleep(timeout ) ) if timeout else None
            
            ids = splitter.fork_all( orig_funcs )
            kill_if_simplified = ids[1:]
            
            simplifier_id = splitter.fork_one( pyabc_split.defer(simplify)(aiger, simple_aiger[0]) )
            
            for id, res in splitter:
                
                if id == sleep_id:
                    return False
                
                if id == simplifier_id:
                    if not res:
                        continue
                    splitter.kill(kill_if_simplified)
                    splitter.fork_all( simplified_funcs )
                    continue
                    
                if report_result(res):
                    return True

    return False
예제 #5
0
def run_niklas_single(aiger, simplify, report_result, timeout=None):

    orig_args = [[",live", "-k=l2s", "-eng=treb-abs"], [",live", "-k=inc"], [",live", "-k=l2s", "-eng=bmc"]]

    simplified_args = [[",live", "-k=inc"], [",live", "-k=l2s", "-eng=bmc"], [",live", "-k=l2s", "-eng=treb"]]

    with temp_file_names(1, suffix=".aig") as simple_aiger:

        orig_funcs = [pyabc_split.defer(run_bip)(a, aiger) for a in orig_args]
        simplified_funcs = [pyabc_split.defer(run_bip)(a, simple_aiger[0]) for a in simplified_args]

        with pyabc_split.make_splitter() as splitter:

            sleep_id = splitter.fork_one(lambda: time.sleep(timeout)) if timeout else None

            ids = splitter.fork_all(orig_funcs)
            kill_if_simplified = ids[1:]

            simplifier_id = splitter.fork_one(pyabc_split.defer(simplify)(aiger, simple_aiger[0]))

            for id, res in splitter:

                print "NIKLAS: process %d finished with" % id, res

                if id == sleep_id:
                    print "NIKLAS: timeout"
                    return False

                elif id == simplifier_id:
                    print "NIKLAS: simplify ended"
                    if not res:
                        continue
                    print "NIKLAS: killing"
                    splitter.kill(kill_if_simplified)
                    splitter.fork_all(simplified_funcs)
                    continue

                elif report_result(res):
                    print "NIKLAS: RESULT"
                    return True

    return False
예제 #6
0
def run_niklas_single(aiger, simplify, report_result, super_prove=None, timeout=None):

    log('run_niklas_single')
    
    orig_args = [
        [ ',live', '-k=l2s', '-eng=treb-abs' ],
        [ ',live', '-k=inc' ],
        [ ',live', '-k=l2s', '-eng=bmc' ],
    ]
    
    simplified_args = [
        [ ',live', '-k=l2s', '-eng=treb-abs' ],
        [ ',live', '-k=inc' ],
        [ ',live', '-k=l2s', '-eng=bmc' ],
        [ ',live', '-k=l2s', '-eng=treb' ],
    ]
    
    with temp_file_names(3, suffix='.aig') as temporary_files:

        simple_aiger, sc_aiger, l2s_aiger = temporary_files

        orig_funcs = [ pyabc_split.defer(run_bip)(a, aiger) for a in orig_args ]
        simplified_funcs = [ pyabc_split.defer(run_bip)(a, simple_aiger) for a in simplified_args ]

        with pyabc_split.make_splitter() as splitter:

            timeout_id = splitter.add_timer(timeout) if timeout else None
            
            ids = splitter.fork_all( orig_funcs )
            log('running engines:', ids)
            kill_if_simplified = ids[1:]
            
            simplifier_id = splitter.fork_one( pyabc_split.defer(simplify)(aiger, simple_aiger) )
            log('running simplifier:', simplifier_id)

            sc_id = None
            
            for id, res in splitter:

                log('process %d finished with'%id, res)

                if id in kill_if_simplified:
                    kill_if_simplified.remove(id)
                
                if id == timeout_id:
                    log('timeout')
                    return False
                
                elif id == simplifier_id:
                    log('simplify ended')
                    if not res:
                        continue
                    log('killing', kill_if_simplified)
                    for kill_id in kill_if_simplified:
                        splitter.kill(kill_id)
                    tmp_ids = splitter.fork_all( simplified_funcs )
                    log('running engines:', tmp_ids)

                    sc_id = splitter.fork_one( pyabc_split.defer(compute_sc)(simple_aiger, sc_aiger, l2s_aiger))
                    log('running sc:', sc_id)
                    continue

                elif id == sc_id:

                    log('sc ended')

                    if res:
                        tmp_id = splitter.fork_one( pyabc_split.defer(run_bip)([',live', '-k=inc'], sc_aiger) )
                        log('running engine:', tmp_id)
                        if super_prove:
                            tmp_id = splitter.fork_one( pyabc_split.defer(run_super_prove)(l2s_aiger, 3, super_prove) )
                            log('running super_prove:', tmp_id)

                elif report_result(res):
                    log('RESULT', res)
                    return True

    return False