Ejemplo n.º 1
0
def run_reachx_cmd(effort, timeout):
    with nested(temp_file_name(suffix=".aig"), temp_file_name()) as (tmpaig_name, tmplog_name):
        pyabc.run_command("write %s"%tmpaig_name)
        
        cmdline = [ 
            'read %s'%cygpath(tmpaig_name),
            'qua_ffix -effort %d -L %s'%(effort, cygpath(tmplog_name)),
            'quit'
            ]
            
        cmd = ["jabc", "-c", " ; ".join(cmdline)]
        
        p = subprocess.Popen(cmd, shell=False, stdout=sys.stdout, stderr=sys.stderr)
        
        rc = wait_with_timeout(p,timeout)
        
        if rc != 0:
            # jabc failed or stopped. Write a status file to update the status to unknown
            with open(tmplog_name, "w") as f:
                f.write('snl_UNK -1 unknown\n')
                f.write('NULL\n')
                f.write('NULL\n')
            
        pyabc.run_command("read_status %s"%tmplog_name)
        
        return rc
Ejemplo n.º 2
0
    def abc_f(truth):
        import os

        print "pid=%d, abc_f(%s)" % (os.getpid(), truth)
        pyabc.run_command("read_truth %s" % truth)
        pyabc.run_command("strash")
        return 100
Ejemplo n.º 3
0
def run_reachx_cmd(effort, timeout):
    with nested(temp_file_name(suffix=".aig"),
                temp_file_name()) as (tmpaig_name, tmplog_name):
        pyabc.run_command("write %s" % tmpaig_name)

        cmdline = [
            'read %s' % cygpath(tmpaig_name),
            'qua_ffix -effort %d -L %s' % (effort, cygpath(tmplog_name)),
            'quit'
        ]

        cmd = ["jabc", "-c", " ; ".join(cmdline)]

        rc = popen_and_wait_with_timeout(timeout,
                                         cmd,
                                         shell=False,
                                         stdout=sys.stdout,
                                         stderr=sys.stderr)

        if rc != 0:
            # jabc failed or stopped. Write a status file to update the status to unknown
            with open(tmplog_name, "w") as f:
                f.write('snl_UNK -1 unknown\n')
                f.write('NULL\n')
                f.write('NULL\n')

        pyabc.run_command("read_status %s" % tmplog_name)

        return rc
Ejemplo n.º 4
0
 def __init__(self):
     with tempfile.NamedTemporaryFile(delete=False, suffix='.aig') as file:
         self.aig = file.name
     with tempfile.NamedTemporaryFile(delete=False, suffix='.log') as file:
         self.log = file.name
     pyabc.run_command(r'write_status %s'%self.log)
     pyabc.run_command(r'write_aiger %s'%self.aig)
 def __init__(self):
     with tempfile.NamedTemporaryFile(delete=False, suffix='.aig') as file:
         self.aig = file.name
     with tempfile.NamedTemporaryFile(delete=False, suffix='.log') as file:
         self.log = file.name
     pyabc.run_command(r'write_status %s' % self.log)
     pyabc.run_command(r'write_aiger %s' % self.aig)
Ejemplo n.º 6
0
        def simplify():

            with redirect.redirect(src=sys.stdout):
                with redirect.redirect(src=sys.stderr):
                    par.read_file_quiet(aig_filename)
                    par.pre_simp()
                    pyabc.run_command('write_aiger %s' % simplified_aig)

            return simplified_aig
Ejemplo n.º 7
0
    def wrapper(argv):
        
        usage = "usage: %prog [options] <aig_file>"
    
        parser = optparse.OptionParser(usage, prog=command_name)
    
        parser.add_option("-n", "--no_redirect", dest="noisy", action="store_true", default=False, help="don't redirect output")
        parser.add_option("-d", "--current_dir", dest="current_dir", action="store_true", default=False, help="stay in current directory")

        options, args = parser.parse_args(argv)
        
        if len(args) != 2:
            print args
            parser.print_usage()
            return 0
            
        aig_filename = os.path.abspath(args[1])

        if not options.noisy:
            pyabc.run_command('/pushredirect')
            
        if not options.current_dir:
            pyabc.run_command('/pushdtemp')
            
        try:
            for d in os.environ['PATH'].split(':'):
                bip = os.path.join(d, 'bip')
                if os.path.exists(bip):
                    pyabc.run_command("load_plugin %s Bip"%bip)
                    break

            basename = os.path.basename( aig_filename )
            shutil.copyfile(aig_filename, basename)
            aig_filename = basename

            par.read_file_quiet(aig_filename)
            result = prooffunc()
            
            par.cex_list = []
        except:
            result = None

        if not options.current_dir:
            pyabc.run_command('/popdtemp')

        if not options.noisy:
            pyabc.run_command('/popredirect')
                
        if result=="SAT":
            print 1
        elif result=="UNSAT":
            print 0
        else:
            print 2

        return 0
Ejemplo n.º 8
0
    def simplify(aiger_in, aiger_out):
        
        saved = utils.save_po_info(aiger_in, tmp[0])
        
        par.read_file_quiet(tmp[0])
        par.pre_simp()
        pyabc.run_command( 'write_aiger %s'%tmp[1] )

        #~ pyabc.run_command( 'read_aiger %s'%tmp[0] )
        #~ pyabc.run_command( 'dc2 ; dc2 ; dc2 ; dc2' )
        #~ pyabc.run_command( 'write_aiger %s'%tmp[1] )

        utils.restore_po_info( saved, tmp[1], aiger_out )
Ejemplo n.º 9
0
    def bmcs_engine(aig_filename, old_stdout):
        def callback(frame, po, result):

            if result == 0:
                par_client.send_progress(po, 1, frame, fout=old_stdout)
                old_stdout.flush()

        pyabc.run_command('read_aiger "%s"' % aig_filename)
        pyabc.run_command('&get')

        with frame_done_callback(callback):
            pyabc.run_command('&bmcs -g')

        status = pyabc.prob_status()

        if status == pyabc.UNSAT:
            par_client.send_json(dict(prop_no=0, status='UNSAT'),
                                 fout=old_stdout)

        if status == pyabc.SAT:
            with temp_filename() as fname:
                pyabc.run_command('write_cex -a %s' % fname)
                with open(fname, 'r') as fin:
                    cex = fin.read().split('\n')[:-1]

            par_client.send_json(dict(prop_no=0, status='SAT', cex=cex),
                                 fout=old_stdout)
Ejemplo n.º 10
0
def super_prove_aiger_cmd(args):

    noisy = len(args)==2 and args[1]=='-n'

    if not noisy:
        pyabc.run_command('/pushredirect')
        pyabc.run_command('/pushdtemp')
    
    try:
        result = abc_common.super_prove()
    except:
        result = None
    
    if not noisy:
        pyabc.run_command('/popdtemp')
        pyabc.run_command('/popredirect')
            
    if result=="SAT":
        print 1
    elif result=="UNSAT":
        print 0
    else:
        print 2

    return 0
Ejemplo n.º 11
0
    def report_result(po, result):

        print "REPORT RESULT: ", po, result

        print >> stdout, "%d" % result
        print >> stdout, "b%d" % po

        if write_cex:
            with temp_filename() as name:
                pyabc.run_command('write_cex -a %s' % name)
                with open(name, 'r') as f:
                    stdout.write(f.read())

        print >> stdout, "."
Ejemplo n.º 12
0
    def simplify(aiger_in, aiger_out):

        with niklas.temp_file_names(2, suffix=".aig") as tmp:

            saved = utils.save_po_info(aiger_in, tmp[0])

            par.read_file_quiet(tmp[0])

            par.pre_simp()

            pyabc.run_command("write_aiger %s" % tmp[1])

            utils.restore_po_info(saved, tmp[1], aiger_out)

            return True
Ejemplo n.º 13
0
    def simplify(aiger_in, aiger_out):

        with niklas.temp_file_names(2, suffix='.aig') as tmp:

            saved = utils.save_po_info(aiger_in, tmp[0])

            par.read_file_quiet(tmp[0])

            par.pre_simp()

            pyabc.run_command('write_aiger %s' % tmp[1])

            utils.restore_po_info(saved, tmp[1], aiger_out)

            return True
Ejemplo n.º 14
0
    def simplify(aiger_in, aiger_out):
        print 'SIMPLIFY: start simplify', aiger_in, aiger_out

        with liveness.temp_file_names(2, suffix='.aig') as tmp:

            saved = utils.save_po_info(aiger_in, tmp[0])

            par.read_file_quiet(tmp[0])

            par.pre_simp()

            pyabc.run_command('write_aiger %s' % tmp[1])

            utils.restore_po_info(saved, tmp[1], aiger_out)

            print 'SIMPLIFY: ended simplify'

            return True
Ejemplo n.º 15
0
def pytest3_cmd(args):
    usage = "usage: %prog [options]"
    
    parser = optparse.OptionParser(usage, prog="pytest3")
    
    parser.add_option("-c", "--cmd", dest="cmd", help="command to ask help for")
    parser.add_option("-v", "--version", action="store_true", dest="version", help="display Python Version")

    options, args = parser.parse_args(args)
    
    if options.version:
        print sys.version
        return 0
    
    if options.cmd:
        pyabc.run_command("%s -h"%options.cmd)
        return 0
    
    return 0
Ejemplo n.º 16
0
def pytest3_cmd(args):
    usage = "usage: %prog [options]"
    
    parser = optparse.OptionParser(usage)
    
    parser.add_option("-c", "--cmd", dest="cmd", help="command to ask help for")
    parser.add_option("-v", "--version", action="store_true", dest="version", help="display Python Version")

    options, args = parser.parse_args(args)
    
    if options.version:
        print sys.version
        return 0
    
    if options.cmd:
        pyabc.run_command("%s -h"%options.cmd)
        return 0
    
    return 0
Ejemplo n.º 17
0
def super_prove_aiger_cmd(args):
    pyabc.run_command('/pushredirect')
    pyabc.run_command('/pushdtemp')
    
    try:
        result = abc_common.super_prove()
    except:
        result = None
    
    pyabc.run_command('/popdtemp')
    pyabc.run_command('/popredirect')
            
    if result=="SAT":
        print 1
    elif result=="UNSAT":
        print 0
    else:
        print 2

    return 0
Ejemplo n.º 18
0
    def simplify(aiger_in, aiger_out):

        with temp_file_names(2, suffix='.aig') as tmp:

            saved = utils.save_po_info(aiger_in, tmp[0])

            pyabc.run_command( 'read_aiger %s'%tmp[0] )
            pyabc.run_command( 'dc2 ; dc2 ; dc2 ; dc2' )
            pyabc.run_command( 'write_aiger %s'%tmp[1] )

            utils.restore_po_info( saved, tmp[1], aiger_out )
            
        return True
Ejemplo n.º 19
0
    def simplify(aiger_in, aiger_out):

        with temp_file_names(2, suffix=".aig") as tmp:

            saved = utils.save_po_info(aiger_in, tmp[0])

            pyabc.run_command("read_aiger %s" % tmp[0])
            pyabc.run_command("dc2 ; dc2 ; dc2 ; dc2")
            pyabc.run_command("write_aiger %s" % tmp[1])

            utils.restore_po_info(saved, tmp[1], aiger_out)

        return True
Ejemplo n.º 20
0
def bmcs_prooffunc(aig_filename, old_stdout):
    def callback(frame, po, result):

        if result == 0:
            par.report_bmc_depth(frame)

        print 'callback: ', frame, po, result

    pyabc.run_command('read "%s"' % aig_filename)
    pyabc.run_command('&get')

    with frame_done_callback(callback):
        pyabc.run_command('&bmcs -g')

    status = pyabc.prob_status()

    if status == pyabc.SAT:
        return 'SAT'
    elif status == pyabc.UNSAT:
        return 'UNSAT'
    else:
        return 'UNKNOWN'
Ejemplo n.º 21
0
    def wrapper(argv):

        usage = "usage: %prog [options] <aig_file>"

        parser = optparse.OptionParser(usage, prog=command_name)

        parser.add_option("-n",
                          "--no_redirect",
                          dest="noisy",
                          action="store_true",
                          default=False,
                          help="don't redirect output")
        parser.add_option("-d",
                          "--current_dir",
                          dest="current_dir",
                          action="store_true",
                          default=False,
                          help="stay in current directory")

        options, args = parser.parse_args(argv)

        if len(args) != 2:
            parser.print_usage()
            return 0

        aig_filename = os.path.abspath(args[1])

        with replace_report_result(multi):

            if not options.noisy:
                pyabc.run_command('/pushredirect')

            if not options.current_dir:
                pyabc.run_command('/pushdtemp')

            try:
                for d in os.environ['PATH'].split(':'):
                    bip = os.path.join(d, 'bip')
                    if os.path.exists(bip):
                        pyabc.run_command("load_plugin %s Bip" % bip)
                        break

                basename = os.path.basename(aig_filename)
                shutil.copyfile(aig_filename, basename)
                aig_filename = basename

                result = prooffunc(aig_filename)

                par.cex_list = []
            except:
                result = None

            if not multi:

                if result == "SAT":
                    par.report_result(0, 1)
                elif result == "UNSAT":
                    par.report_result(0, 0)
                elif type(result
                          ) == list and len(result) > 0 and result[0] == "SAT":
                    par.report_result(0, 1)
                elif type(result) == list and len(
                        result) > 0 and result[0] == "UNSAT":
                    par.report_result(0, 0)
                else:
                    par.report_result(0, 2)

            if not options.current_dir:
                pyabc.run_command('/popdtemp')

            if not options.noisy:
                pyabc.run_command('/popredirect')

        return 0
 def restore(self):
     pyabc.run_command(r'read_aiger %s' % self.aig)
     pyabc.run_command(r'read_status %s' % self.log)
Ejemplo n.º 23
0
 def parent(res, aig, log):
     pyabc.run_command(r'read_aiger %s'%aig)
     pyabc.run_command(r'read_status %s'%log)
     return res
Ejemplo n.º 24
0
 def child(f, aig, log):
     res = f()
     pyabc.run_command(r'write_status %s'%log)
     pyabc.run_command(r'write_aiger %s'%aig)
     return res
Ejemplo n.º 25
0
def pytest2_cmd(args):
    print args
    pyabc.run_command('scorr -h')
    return 0
Ejemplo n.º 26
0
        
    # For operations with ABC that save and restore status
    
    import pyabc
    
    def abc_f(truth):
        import os
        print "pid=%d, abc_f(%s)"%(os.getpid(), truth)
        pyabc.run_command('read_truth %s'%truth)
        pyabc.run_command('strash')
        return 100
        
    funcs = [
        defer(abc_f)("1000"),
        defer(abc_f)("0001")
    ]
    
    best = None
    
    for i, res in abc_split_all(funcs):
        print i, res
        if best is None:\
            # save state
            best = abc_state()
        pyabc.run_command('write_verilog /dev/stdout')
    
    # if there is a saved state, restore it
    if best is not None:
        best.restore()
        pyabc.run_command('write_verilog /dev/stdout')
Ejemplo n.º 27
0
 def abc_f(truth):
     import os
     print "pid=%d, abc_f(%s)" % (os.getpid(), truth)
     pyabc.run_command('read_truth %s' % truth)
     pyabc.run_command('strash')
     return 100
Ejemplo n.º 28
0
 def parent(res, aig, log):
     pyabc.run_command(r'read_aiger %s' % aig)
     pyabc.run_command(r'read_status %s' % log)
     return res
Ejemplo n.º 29
0
 def child(f, aig, log):
     res = f()
     pyabc.run_command(r'write_status %s' % log)
     pyabc.run_command(r'write_aiger %s' % aig)
     return res
Ejemplo n.º 30
0
        print res
        break

    # For operations with ABC that save and restore status

    import pyabc

    def abc_f(truth):
        import os
        print "pid=%d, abc_f(%s)" % (os.getpid(), truth)
        pyabc.run_command('read_truth %s' % truth)
        pyabc.run_command('strash')
        return 100

    funcs = [defer(abc_f)("1000"), defer(abc_f)("0001")]

    best = None

    for i, res in abc_split_all(funcs):
        print i, res
        if best is None:            \
            # save state

            best = abc_state()
        pyabc.run_command('write_verilog /dev/stdout')

    # if there is a saved state, restore it
    if best is not None:
        best.restore()
        pyabc.run_command('write_verilog /dev/stdout')
Ejemplo n.º 31
0
    def wrapper(argv):

        usage = "usage: %prog [options] <aig_file>"

        parser = optparse.OptionParser(usage, prog=command_name)

        parser.add_option(
            "-n", "--no_redirect", dest="noisy", action="store_true", default=False, help="don't redirect output"
        )
        parser.add_option(
            "-d",
            "--current_dir",
            dest="current_dir",
            action="store_true",
            default=False,
            help="stay in current directory",
        )

        options, args = parser.parse_args(argv)

        if len(args) != 2:
            parser.print_usage()
            return 0

        aig_filename = os.path.abspath(args[1])

        with replace_report_result(multi):

            if not options.noisy:
                pyabc.run_command("/pushredirect")

            if not options.current_dir:
                pyabc.run_command("/pushdtemp")

            try:
                for d in os.environ["PATH"].split(":"):
                    bip = os.path.join(d, "bip")
                    if os.path.exists(bip):
                        pyabc.run_command("load_plugin %s Bip" % bip)
                        break

                basename = os.path.basename(aig_filename)
                shutil.copyfile(aig_filename, basename)
                aig_filename = basename

                result = prooffunc(aig_filename)

                par.cex_list = []
            except:
                result = None

            if not multi:

                if result == "SAT":
                    par.report_result(0, 1)
                elif result == "UNSAT":
                    par.report_result(0, 0)
                elif type(result) == list and len(result) > 0 and result[0] == "SAT":
                    par.report_result(0, 1)
                elif type(result) == list and len(result) > 0 and result[0] == "UNSAT":
                    par.report_result(0, 0)
                else:
                    par.report_result(0, 2)

            if not options.current_dir:
                pyabc.run_command("/popdtemp")

            if not options.noisy:
                pyabc.run_command("/popredirect")

        return 0
Ejemplo n.º 32
0
    def wrapper(argv):

        usage = "usage: %prog [options] <aig_file>"

        parser = optparse.OptionParser(usage, prog=command_name)

        parser.add_option("-n",
                          "--no_redirect",
                          dest="noisy",
                          action="store_true",
                          default=False,
                          help="don't redirect output")
        parser.add_option("-r",
                          "--redirect",
                          dest="redirect",
                          default=None,
                          help="redirect output to file")
        parser.add_option("-d",
                          "--current_dir",
                          dest="current_dir",
                          action="store_true",
                          default=False,
                          help="stay in current directory")

        options, args = parser.parse_args(argv)

        if len(args) != 2:
            parser.print_usage()
            return 0

        if options.noisy and options.redirect:
            print 'error: options -n/--no_redirect and -r/--redirect are mutually exclusive'
            return 0

        aig_filename = os.path.abspath(args[1])

        with replace_report_result(write_cex=write_cex,
                                   bmc_depth=bmc_depth) as old_stdout:

            if options.redirect:
                pyabc.run_command('/pushredirect %s' % options.redirect)
            elif not options.noisy:
                pyabc.run_command('/pushredirect')

            if not options.current_dir:
                pyabc.run_command('/pushdtemp')

            try:
                basename = os.path.basename(aig_filename)
                shutil.copyfile(aig_filename, basename)
                aig_filename = basename

                result = prooffunc(aig_filename, old_stdout)

                par.cex_list = []
            except:
                import traceback
                traceback.print_exc()
                result = None

            if do_reporting and not multi:

                if result == "SAT":
                    par.report_result(0, 1)
                elif result == "UNSAT":
                    par.report_result(0, 0)
                elif type(result
                          ) == list and len(result) > 0 and result[0] == "SAT":
                    par.report_result(0, 1)
                elif type(result) == list and len(
                        result) > 0 and result[0] == "UNSAT":
                    par.report_result(0, 0)
                else:
                    par.report_result(0, 2)

            if not options.current_dir:
                pyabc.run_command('/popdtemp')

            if not options.noisy:
                pyabc.run_command('/popredirect')

        return 0
Ejemplo n.º 33
0
def pytest2_cmd(args):
    print args
    pyabc.run_command('scorr -h')
    return 0
Ejemplo n.º 34
0
 def restore(self):
     pyabc.run_command(r'read_aiger %s'%self.aig)
     pyabc.run_command(r'read_status %s'%self.log)
Ejemplo n.º 35
0
def prove_one_by_one_cmd(args):
    
    noisy = len(args)==2 and args[1]=='-n'

    # switch to a temporary directory
    pyabc.run_command('/pushdtemp')
    
    # write a copy of the original file in the temporary directory
    pyabc.run_command('w original_aig_file.aig')
    
    # iterate through the ouptus
    for po in range(0, pyabc.n_pos()):
        
        if not noisy:
            pyabc.run_command('/pushredirect')

        # replace the nework with the cone of the current PO
        pyabc.run_command( 'cone -O %d -s'%po )

        # run super_prove
        try:
            result = abc_common.super_prove()
        except:
            result = 'UNKNOWN'

        if not noisy:
            pyabc.run_command('/popredirect')

        print 'PO %d is %s'%(po, result)
        
        # stop if the result is not UNSAT
        if result != "UNSAT":
            break

        # read the original file for the next iteration
        pyabc.run_command('r original_aig_file.aig')
        
    # go back to the original directory
    pyabc.run_command('/popdtemp')

    return 0
Ejemplo n.º 36
0
        print res
        break

    # For operations with ABC that save and restore status

    import pyabc

    def abc_f(truth):
        import os

        print "pid=%d, abc_f(%s)" % (os.getpid(), truth)
        pyabc.run_command("read_truth %s" % truth)
        pyabc.run_command("strash")
        return 100

    funcs = [defer(abc_f)("1000"), defer(abc_f)("0001")]

    best = None

    for i, res in abc_split_all(funcs):
        print i, res
        if best is None:
        # save state
            best = abc_state()
        pyabc.run_command("write_verilog /dev/stdout")

    # if there is a saved state, restore it
    if best is not None:
        best.restore()
        pyabc.run_command("write_verilog /dev/stdout")