pyabc: remove python integration from abc, it is moved to a separate extension

This commit is contained in:
Baruch Sterin 2015-11-05 01:24:26 -08:00
parent aa62165a1c
commit c610c03661
27 changed files with 1 additions and 13810 deletions

View File

@ -29,8 +29,7 @@ MODULES := \
src/proof/pdr src/proof/abs src/proof/live src/proof/ssc src/proof/int \
src/proof/cec src/proof/dch src/proof/fraig src/proof/fra src/proof/ssw \
src/aig/aig src/aig/saig src/aig/gia src/aig/ioa src/aig/ivy src/aig/hop \
src/aig/miniaig \
src/python
src/aig/miniaig
all: $(PROG)
default: $(PROG)

View File

@ -1,147 +0,0 @@
# reachx
python new_abc_commands.py
python -c "import reachx_cmd"
# global parameters
set check # checks intermediate networks
#set checkfio # prints warnings when fanins/fanouts are duplicated
#unset checkread # does not check new networks after reading from file
#set backup # saves backup networks retrived by "undo" and "recall"
#set savesteps 1 # sets the maximum number of backup networks to save
#set progressbar # display the progress bar
# program names for internal calls
set dotwin dot.exe
set dotunix dot
set gsviewwin gsview32.exe
set gsviewunix gv
set siswin sis.exe
set sisunix sis
set mvsiswin mvsis.exe
set mvsisunix mvsis
set capowin MetaPl-Capo10.1-Win32.exe
set capounix MetaPl-Capo10.1
set gnuplotwin wgnuplot.exe
set gnuplotunix gnuplot
# Niklas Een's commands
#load_plugin C:\_projects\abc\lib\bip_win.exe "BIP"
#load_plugin /hd/common/pyabc/bip "BIP"
# standard aliases
alias hi history
alias b balance
alias cg clockgate
alias cl cleanup
alias clp collapse
alias cs care_set
alias esd ext_seq_dcs
alias f fraig
alias fs fraig_sweep
alias fsto fraig_store
alias fres fraig_restore
alias fr fretime
alias ft fraig_trust
alias ic indcut
alias lp lutpack
alias pcon print_cone
alias pd print_dsd
alias pex print_exdc -d
alias pf print_factor
alias pfan print_fanio
alias pg print_gates
alias pl print_level
alias plat print_latch
alias pio print_io
alias pk print_kmap
alias pm print_miter
alias ps print_stats
alias psb print_stats -b
alias psu print_supp
alias psy print_symm
alias pun print_unate
alias q quit
alias r read
alias ra read_aiger
alias r3 retime -M 3
alias r3f retime -M 3 -f
alias r3b retime -M 3 -b
alias ren renode
alias rh read_hie
alias ri read_init
alias rl read_blif
alias rb read_bench
alias ret retime
alias dret dretime
alias rp read_pla
alias rt read_truth
alias rv read_verilog
alias rvl read_verlib
alias rsup read_super mcnc5_old.super
alias rlib read_library
alias rlibc read_library cadence.genlib
alias rty read_liberty
alias rlut read_lut
alias rw rewrite
alias rwz rewrite -z
alias rf refactor
alias rfz refactor -z
alias re restructure
alias rez restructure -z
alias rs resub
alias rsz resub -z
alias sa set autoexec ps
alias scl scleanup
alias sif if -s
alias so source -x
alias st strash
alias sw sweep
alias ssw ssweep
alias tr0 trace_start
alias tr1 trace_check
alias trt "r c.blif; st; tr0; b; tr1"
alias u undo
alias w write
alias wa write_aiger
alias wb write_bench
alias wc write_cnf
alias wh write_hie
alias wl write_blif
alias wp write_pla
alias wv write_verilog
# standard scripts
alias resyn "b; rw; rwz; b; rwz; b"
alias resyn2 "b; rw; rf; b; rw; rwz; b; rfz; rwz; b"
alias resyn2a "b; rw; b; rw; rwz; b; rwz; b"
alias resyn3 "b; rs; rs -K 6; b; rsz; rsz -K 6; b; rsz -K 5; b"
alias compress "b -l; rw -l; rwz -l; b -l; rwz -l; b -l"
alias compress2 "b -l; rw -l; rf -l; b -l; rw -l; rwz -l; b -l; rfz -l; rwz -l; b -l"
alias choice "fraig_store; resyn; fraig_store; resyn2; fraig_store; fraig_restore"
alias choice2 "fraig_store; balance; fraig_store; resyn; fraig_store; resyn2; fraig_store; resyn2; fraig_store; fraig_restore"
alias rwsat "st; rw -l; b -l; rw -l; rf -l"
alias drwsat2 "st; drw; b -l; drw; drf; ifraig -C 20; drw; b -l; drw; drf"
alias share "st; multi -m; fx; resyn2"
alias addinit "read_init; undc; strash; zero"
alias blif2aig "undc; strash; zero"
alias v2p "&vta_gla; &ps; &gla_derive; &put; w 1.aig; pdr -v"
alias g2p "&ps; &gla_derive; &put; w 2.aig; pdr -v"
# resubstitution scripts for the IWLS paper
alias src_rw "st; rw -l; rwz -l; rwz -l"
alias src_rs "st; rs -K 6 -N 2 -l; rs -K 9 -N 2 -l; rs -K 12 -N 2 -l"
alias src_rws "st; rw -l; rs -K 6 -N 2 -l; rwz -l; rs -K 9 -N 2 -l; rwz -l; rs -K 12 -N 2 -l"
alias resyn2rs "b; rs -K 6; rw; rs -K 6 -N 2; rf; rs -K 8; b; rs -K 8 -N 2; rw; rs -K 10; rwz; rs -K 10 -N 2; b; rs -K 12; rfz; rs -K 12 -N 2; rwz; b"
alias compress2rs "b -l; rs -K 6 -l; rw -l; rs -K 6 -N 2 -l; rf -l; rs -K 8 -l; b -l; rs -K 8 -N 2 -l; rw -l; rs -K 10 -l; rwz -l; rs -K 10 -N 2 -l; b -l; rs -K 12 -l; rfz -l; rs -K 12 -N 2 -l; rwz -l; b -l"
# use this script to convert 1-valued and DC-valued flops for an AIG
alias fix_aig "logic; undc; strash; zero"
# use this script to convert 1-valued and DC-valued flops for a logic network coming from BLIF
alias fix_blif "undc; strash; zero"
# lazy man's synthesis
alias recadd3 "st; rec_add3; b; rec_add3; dc2; rec_add3; if -K 8; bidec; st; rec_add3; dc2; rec_add3; if -g -K 6; st; rec_add3"

File diff suppressed because it is too large Load Diff

View File

@ -1,431 +0,0 @@
import os
import time
from datetime import *
##import par
##from abc_common import *
import abc_common
#this makes par the dominant module insteat of abc_common
from par import *
import sys
import math
import time
from pyabc_split import *
##import pdb
##from IPython.Debugger import Tracer; debug_here = Tracer()
#x('source ../../abc.rc')
#abc_common.x('source ../../abc.rc')
def scorriter():
""" apply scorr with increasing conflicts up to 100"""
x('time')
run_command('r p_0.aig')
n = 20
while n < 1000:
print_circuit_stats()
run_command('scorr -C %d'%n)
x('ind -C %d'%1000)
if is_unsat():
print 'n = %d'%n
break
n = 2*n
x('time')
def simplifyq():
# set_globals()
n=n_ands()
if n > 30000:
if n<45000:
abc("&get;&scl;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&scorr;&fraig;&dc2;&put;dr;&get;&scorr -F 2;&dc2;&put;w temp.aig")
else:
abc("&get;&scl;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&scorr;&fraig;&dc2;&put;dr;&get;&dc2;&put;w temp.aig")
n = n_ands()
if n < 30000:
if n > 15000:
abc("scl;rw;dr;lcorr;rw;dr;scorr;fraig;dc2;dr;dc2rs;w temp.aig")
else:
abc("scl;rw;dr;lcorr;rw;dr;scorr;fraig;dc2;dr;scorr -F 2;dc2rs;w temp.aig")
if n < 10000:
m = min( 30000/n, 8 )
if m > 2:
abc( "scorr -F %d"%m)
run_command("ps")
def constraints():
"""Determine if a set of files in a set of
directories has constraints and print out the results."""
for s in directories:
print("\ndirectory is "+s)
jj=eval(s)
print(jj)
for j in range(len(jj)):
x("\nr ../DIR/%s/p_%smp.aig"%(s,jj[j]))
print("structural:")
x('constr -s')
print("inductive constraints:")
x('constr ')
def help(s):
run_command('%s -h'%s)
def strip():
"""Strip out each output of a multi-output example and write it
into a separate file"""
os.chdir('../DIR')
abc('r p_all_smp.aig')
po = n_pos()
print_circuit_stats()
for j in range(po):
abc('r p_all_smp.aig')
abc('cone -s -O %d'%j)
abc('scl;rw;trm')
abc('w p_%d.aig'%j)
print_circuit_stats()
def fn_def(f,n):
filename = f.__code__.co_filename
firstline = f.__code__.co_firstlineno
lines = open(filename, "r").readlines()
print "".join(lines[firstline : n+firstline])
def lst(list,match):
result = []
for j in range(len(list)):
if list[j][-len(match):] == match:
result.append(list[j])
return result
def lste(list,match,excp):
result = []
for j in range(len(list)):
if list[j][-len(match):] == match:
if excp in list[j]:
continue
result.append(list[j])
return result
def blif2aig():
""" converts blif files into aig files"""
#os.chdir('../ibm-web')
list_all = os.listdir('.')
l_blif = lst(list_all,'.blif')
for j in range(len(l_blif)):
name = l_blif[j][:-5]
print '%s '%name,
abc('r %s.blif'%name)
abc('st')
abc('fold')
abc('w %s.aig'%name)
ps()
def la():
return list_aig('')
def list_aig(s=''):
""" prnts out the sizes of aig files"""
#os.chdir('../ibm-web')
list_all = os.listdir('.')
dir = lst(list_all,'.aig')
dir.sort()
result = []
for j in range(len(dir)):
name = dir[j][:-4]
if not s_in_s(s,name):
continue
print '%s '%name,
abc('r %s.aig'%name)
ps()
result = result + [name]
return result
def list_original():
list_dir = os.listdir('.')
list_dir.sort()
out = []
for i in range(len(list_dir)):
name = '%s/original.aig'%list_dir[i]
if os.access('%s'%name,os.R_OK):
abc('r %s;&ps'%name)
if n_latches() > 0 and n_pos() > 1:
size = str(sizeof())
print list_dir[i],
ps()
out = out + ['%s: %s'%(list_dir[i],size)]
return out
def list_size(s=''):
""" prnts out the sizes of aig files. Leaves .aig as part of name"""
#os.chdir('../ibm-web')
list_all = os.listdir('.')
dir = lst(list_all,'.aig')
dir.sort()
result = []
for j in range(len(dir)):
## name = dir[j][:-4]
name = dir[j] #leaves .aig as part of name
if not s_in_s(s,name):
continue
print '%s '%name,
## abc('r %s.aig'%name)
abc('r %s'%name)
ps()
result = result + [name[:-4]] #takes .aig off of name
return result
def rename(l=[]):
for j in range(len(l)):
name = l[j]
name1 = name +'.aig'
name2 = name[:-4]+'simp.aig' #take off _smp and put on simp
os.rename(name1,name2)
def list_blif(s=''):
""" prnts out the sizes of aig files"""
#os.chdir('../ibm-web')
list_all = os.listdir('.')
dir = lst(list_all,'.blif')
dir.sort()
result = []
for j in range(len(dir)):
name = dir[j][:-5]
if not s_in_s(s,name):
continue
print '%s: '%name,
abc('read_blif %s.blif'%name)
run_command('ps')
abc('st;zero;w %s.aig'%name)
result = result + [name]
return result
def s_in_s(s1,s2):
ls1 = len(s1)
l = 1+len(s2)- ls1
if l< 0:
return False
else:
for j in range(l):
if s1 == s2[j:j+ls1]:
return True
else:
continue
return False
def convert_ibm():
""" converts blif files (with constraints?) into aig files"""
os.chdir('../ibm-web')
list_ibm = os.listdir('.')
l_blif = lst(list_ibm,'.blif')
for j in range(len(l_blif)):
name = l_blif[j][:-5]
run_command('read_blif %s.blif'%name)
abc('undc')
abc('st -i')
abc('zero')
run_command('w %s.aig'%name)
"""if a<100000000:
f = min(8,max(1,40000/a))
#run_command('scorr -c -F %d'%f)
#print 'Result of scorr -F %d: '%f,
print_circuit_stats()
run_command('w p_%d.aig'%j)"""
def cl():
cleanup()
def cleanup():
list = os.listdir('.')
for j in range(len(list)):
name = list[j]
if ((s_in_s('_smp',name)) or (s_in_s('_save', name)) or (s_in_s('_backup', name)) or (s_in_s('_osave', name))
or (s_in_s('_best', name)) or (s_in_s('_gsrm', name)) or (s_in_s('gore', name)) or
(s_in_s('_bip', name)) or (s_in_s('sm0', name)) or (s_in_s('gabs', name))
or (s_in_s('temp', name)) or (s_in_s('__', name)) or (s_in_s('greg', name)) or (s_in_s('tf2', name))
or (s_in_s('gsrm', name)) or (s_in_s('_rpm', name )) or (s_in_s('gsyn', name)) or (s_in_s('beforerpm', name))
or (s_in_s('afterrpm', name)) or (s_in_s('initabs', name)) or (s_in_s('_init', name))
or (s_in_s('_osave', name)) or (s_in_s('tt_', name)) or (s_in_s('_before', name)) or (s_in_s('_after', name))
or (s_in_s('_and', name)) or (s_in_s('_spec', name)) or (s_in_s('temp.a', name))
or (s_in_s('_sync', name)) or (s_in_s('_old', name)) or (s_in_s('_cone_', name)) or (s_in_s('_abs', name))
or (s_in_s('_vabs', name)) or (s_in_s('_gla', name)) or (s_in_s('vabs', name)) or (s_in_s('_mp2', name))
or (s_in_s('_sc1', name)) or (s_in_s('_sc2', name)) or (s_in_s('_after', name))
or (s_in_s('_before', name)) or (s_in_s('_aigs_', name)) or (s_in_s('_cex.', name))
or (s_in_s('_bmc1', name)) or (s_in_s('_p0_', name)) or (s_in_s('_p1_', name))
or (s_in_s('_unsolv', name)) or (s_in_s('_iso1', name))
):
os.remove(name)
def simp_mbi():
os.chdir('../mbi')
list_ibm = os.listdir('.')
l_aig = lst(list_ibm,'.aig')
for j in range(len(l_aig)):
name = l_aig[j][:-4]
run_command('r %s.aig'%name)
run_command('st')
print '\n%s: '%name
print_circuit_stats()
quick_simp()
scorr_comp()
simplify()
run_command('w %s_smp.aig'%name)
def strip_names():
os.chdir('../mbi')
list_ibm = os.listdir('.')
l_aig = lst(list_ibm,'.aig')
for j in range(len(l_aig)):
name = l_aig[j][:-4]
run_command('r %s.aig'%name)
run_command('st')
print '\n%s: '%name
print_circuit_stats()
quick_simp()
scorr_comp()
simplify()
run_command('w %s_smp.aig'%name)
def map_ibm():
os.chdir('../ibmmike2')
list_ibm = os.listdir('.')
l_blif = lst(list_ibm,'.blif')
result = []
print len(l_blif)
for j in range(len(l_blif)):
name = l_blif[j][:-5]
result.append('%s = %d'%(name,j))
return result
def absn(a,c,s):
""" testing Niklas abstraction with various conflict limits
a= method (0 - regular cba,
1 - pure pba,
2 - cba with pba at the end,
3 cba and pba interleaved at each step
c = conflict limit
s = No. of stable steps without cex"""
global G_C, G_T, latches_before_abs, x_factor, f_name
set_globals()
latches_before_abs = n_latches()
print 'Start: ',
print_circuit_stats()
print 'Een abstraction params: Method #%d, %d conflicts, %d stable'%(a,c,s)
run_command('&get; &abs_newstart -v -A %d -C %d -S %d'%(a,c,s))
bmcdepth = n_bmc_frames()
print 'BMC depth = %d'%n_bmc_frames()
abc('&w absn_greg.aig; &abs_derive; &put; w absn_gabs.aig')
print 'Final abstraction: ',
print_circuit_stats()
write_file('absn')
return "Done"
def time_stamp():
d=datetime.today()
s = d.strftime('%m.%d.%y-%X')
return s
def apply_sp(list):
global m_trace
s = time_stamp()
out_name = "%s-traces.txt"%s
print out_name
if os.access(out_name,os.R_OK):
os.remove(out_name)
f = open(out_name,'w')
print f
for j in range(len(list)):
name = list[j]
print '\n\n**** %s ****\n'%name
f.write('\n\n****%s ****'%name)
read_file_quiet(name)
result = super_prove()
trace = result[1]
s = str(trace)
f.write('\n\n')
f.write(s)
f.flush()
f.close()
def xfiles():
global f_name
#output = sys.stdout
#iterate over all ESS files
#saveout = sys.stdout
#output = open("ibm_log.txt",'w')
# sys.stdout = output
os.chdir('../ess/f58m')
print 'Directories are %s'%directories
for s in directories:
sss= '../%s'%s
os.chdir(sss)
print "\nDirectory is %s\n"%s
jj=eval(s)
print (jj)
run_command('time')
for j in range(len(jj)):
print ' '
set_fname('p_%dsmp23'%jj[j])#file f_name.aig is read in
print 'p_%dsmp23'%jj[j]
run_command('time')
result = dprove3(1)
print result
run_command('time')
run_command('time')
os.chdir('../../python')
#sys.stdout = saveout
#output.close()
def sublist(L,I):
z = []
for i in range(len(I)):
s = L[I[i]],
s = list(s)
z = z + s
return z
def s2l(s):
""" takes the string s divided by '\n' and makess a list of items"""
result = []
while len(s)>2:
j = s.find('\n')
result.append(s[:j])
s = s[j+1:]
return result
def select(lst, s):
result = []
print lst
for j in range(len(lst)):
if s in lst[j]:
s1 = lst[j]
k = s1.find(':')
s1 = s1[:k]
result.append(s1)
return result
def process_result(name):
f = open(name,'r')
s = f.read()
f.close()
lst = s2l(s)
result = select(lst,'Timeout')
return result
def main():
stackno = 0
if len(sys.argv) != 2:
print "usage: %s <aig filename>"%sys.argv[0]
sys.exit(1)
aig_filename = sys.argv[1]
x("source ../../abc.rc")
read(aig_filename)
dprove3(1)
# a test to whether the script is being called from the command line
if __name__=="__main__":
main()

View File

@ -1,14 +0,0 @@
#!/bin/sh
abc_root()
{
cwd="$(pwd)"
cd $(dirname "$1")
echo $(dirname "$(pwd)")
cd "${cwd}"
}
abc_dir=$(abc_root "$0")
bin_dir="${abc_dir}"/bin
exec ${bin_dir}/abc -q "/multi_prove_aiger $*"

View File

@ -1,257 +0,0 @@
import sys
import os
import pyabc
import par
import tempfile
import shutil
import redirect
import optparse
from contextlib import contextmanager
def read_cmd(args):
if len(args)==2:
par.read_file_quiet(args[1])
else:
par.read_file()
return 0
pyabc.add_abc_command(read_cmd, "ZPython", "/rf", 0)
def chdir_cmd(args):
os.chdir( args[1] )
return 0
pyabc.add_abc_command(chdir_cmd, "ZPython", "/cd", 0)
def pwd_cmd(args):
print os.getcwd()
return 0
pyabc.add_abc_command(pwd_cmd, "ZPython", "/pwd", 0)
def ls_cmd(args):
os.system("ls " + " ".join(args[1:]))
return 0
pyabc.add_abc_command(ls_cmd, "ZPython", "/ls", 0)
pushd_temp_stack = []
def pushdtemp_cmd(args):
tmpdir = tempfile.mkdtemp()
pushd_temp_stack.append( (os.getcwd(), tmpdir) )
os.chdir(tmpdir)
return 0
pyabc.add_abc_command(pushdtemp_cmd, "ZPython", "/pushdtemp", 0)
def popdtemp_cmd(args):
prev, temp = pushd_temp_stack.pop()
os.chdir(prev)
shutil.rmtree(temp, ignore_errors=True)
return 0
pyabc.add_abc_command(popdtemp_cmd, "ZPython", "/popdtemp", 0)
pushredirect_stack = []
def push_redirect_cmd(args):
fdout = redirect.start_redirect( redirect.null_file, sys.stdout)
pushredirect_stack.append( (sys.stdout, fdout) )
fderr = redirect.start_redirect( redirect.null_file, sys.stderr)
pushredirect_stack.append( (sys.stderr, fderr) )
return 0
pyabc.add_abc_command(push_redirect_cmd, "ZPython", "/pushredirect", 0)
def pop_redirect_cmd(args):
err, fderr = pushredirect_stack.pop()
redirect.end_redirect(err, fderr)
out, fdout = pushredirect_stack.pop()
redirect.end_redirect(out, fdout)
return 0
pyabc.add_abc_command(pop_redirect_cmd, "ZPython", "/popredirect", 0)
def print_aiger_result(args):
status = pyabc.prob_status()
if status==1:
print 0
elif status==0:
print 1
else:
print 2
return 0
pyabc.add_abc_command(print_aiger_result, "ZPython", "/print_aiger_result", 0)
@contextmanager
def replace_report_result(multi):
def report_result(po, result):
print "REPORT RESULT: ", po, result
print >> stdout, "%d"%result
print >> stdout, "b%d"%po
print >> stdout, "."
def report_liveness_result(po, result):
print "REPORT RESULT: ", po, result
print >> stdout, "%d"%result
print >> stdout, "j%d"%po
print >> stdout, "."
def report_bmc_depth(depth):
if not multi:
print "REPORT BMC DEPTH:", depth
print >> stdout, "u%d"%depth
with redirect.save_stdout() as stdout:
old_report_result = par.report_result
par.report_result = report_result
#old_report_liveness_result = par.report_liveness_result
par.report_liveness_result = report_liveness_result
old_report_bmc_depth = par.report_bmc_depth
par.report_bmc_depth = report_bmc_depth
try:
yield
finally:
par.report_result = old_report_result
#~ par.report_liveness_result = report_liveness_result
par.report_bmc_depth = old_report_bmc_depth
def proof_command_wrapper_internal(prooffunc, category_name, command_name, change, multi=False):
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
pyabc.add_abc_command(wrapper, category_name, command_name, change)
def proof_command_wrapper(prooffunc, category_name, command_name, change, multi=False):
def pf(aig_filename):
par.read_file_quiet(aig_filename)
return prooffunc()
return proof_command_wrapper_internal(pf, category_name, command_name, change, multi)
proof_command_wrapper(par.sp, 'HWMCC13', '/super_prove_aiger', 0)
proof_command_wrapper(par.simple, 'HWMCC13', '/simple_aiger', 0)
proof_command_wrapper(par.simple_bip, 'HWMCC13', '/simple_bip_aiger', 0)
proof_command_wrapper(par.simple_sat, 'HWMCC13', '/simple_sat_aiger', 0)
proof_command_wrapper(par.mp, 'HWMCC13', '/multi_prove_aiger', 0, multi=True)
def simple_liveness_prooffunc(aig_filename):
import niklas
from pyaig import utils
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
def report_result(id, res):
if res and 'result' in res:
result = res['result']
if result=='proved':
par.report_liveness_result(id, 0)
return True
elif result=='failed':
par.report_liveness_result(id, 1)
return True
return False
try:
niklas.run_niklas_multi(aig_filename, simplify=simplify, report_result=report_result)
except:
import traceback
traceback.print_exc()
proof_command_wrapper_internal( simple_liveness_prooffunc, "HWMCC13", "/simple_liveness_aiger", 0, multi=True)

View File

@ -1,191 +0,0 @@
import os
import sys
import time
import tempfile
import subprocess
from contextlib import contextmanager
import pyabc
import pyabc_split
@contextmanager
def temp_file_names(N, suffix=""):
files = []
try:
for i in xrange(N):
files.append( tempfile.NamedTemporaryFile(suffix=suffix) )
yield [ f.name for f in files ]
finally:
for f in files:
f.close()
def parse_bip_status(status):
res = {}
for line in open(status, 'r'):
line = line.strip()
colon = line.find(':')
if colon < 0:
continue
field = line[:colon]
data = line[colon+2:]
res[field] = data
return res
def run_bip(args, aiger):
import redirect
with redirect.redirect():
with temp_file_names(1) as tmpnames:
args = [
'bip',
'-abc',
'-input=%s'%aiger,
'-output=%s'%tmpnames[0],
] + args;
rc = subprocess.call(args, preexec_fn=pyabc._set_death_signal)
if rc!=0:
return None
return parse_bip_status(tmpnames[0])
from pyaig import AIG, read_aiger, write_aiger, utils
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
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
if __name__ == "__main__":
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
def report_result(id, res):
if res and 'result' in res:
result = res['result']
if result=='proved':
print "PROVED: ", id
return True
elif result=='failed':
print "FAILED:", id
return True
return False
aiger = "test.aig"
while True:
try:
run_niklas_multi(aiger, simplify=simplify, report_result=report_result)
except:
import traceback
traceback.print_exc()

File diff suppressed because it is too large Load Diff

View File

@ -1,14 +0,0 @@
#!/bin/sh
abc_root()
{
cwd="$(pwd)"
cd $(dirname "$1")
echo $(dirname "$(pwd)")
cd "${cwd}"
}
abc_dir=$(abc_root "$0")
bin_dir="${abc_dir}"/bin
exec ${bin_dir}/abc -q "/simple_aiger $*"

View File

@ -1,14 +0,0 @@
#!/bin/sh
abc_root()
{
cwd="$(pwd)"
cd $(dirname "$1")
echo $(dirname "$(pwd)")
cd "${cwd}"
}
abc_dir=$(abc_root "$0")
bin_dir="${abc_dir}"/bin
exec ${bin_dir}/abc -q "/simple_bip_aiger $*"

View File

@ -1,14 +0,0 @@
#!/bin/sh
abc_root()
{
cwd="$(pwd)"
cd $(dirname "$1")
echo $(dirname "$(pwd)")
cd "${cwd}"
}
abc_dir=$(abc_root "$0")
bin_dir="${abc_dir}"/bin
exec ${bin_dir}/abc -q "/simple_liveness_aiger $*"

View File

@ -1,14 +0,0 @@
#!/bin/sh
abc_root()
{
cwd="$(pwd)"
cd $(dirname "$1")
echo $(dirname "$(pwd)")
cd "${cwd}"
}
abc_dir=$(abc_root "$0")
bin_dir="${abc_dir}"/bin
exec ${bin_dir}/abc -q "/simple_sat_aiger $*"

View File

@ -1,14 +0,0 @@
#!/bin/sh
abc_root()
{
cwd="$(pwd)"
cd $(dirname "$1")
echo $(dirname "$(pwd)")
cd "${cwd}"
}
abc_dir=$(abc_root "$0")
bin_dir="${abc_dir}"/bin
exec ${bin_dir}/abc -q "/super_prove_aiger $*"

View File

@ -45,10 +45,6 @@ SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
***********************************************************************/
#ifdef ABC_PYTHON_EMBED
#include <Python.h>
#endif /* ABC_PYTHON_EMBED */
#include "base/abc/abc.h"
#include "mainInt.h"
#include "base/wlc/wlc.h"
@ -108,29 +104,6 @@ int Abc_RealMain( int argc, char * argv[] )
pAbc = Abc_FrameGetGlobalFrame();
pAbc->sBinary = argv[0];
#ifdef ABC_PYTHON_EMBED
{
PyObject* pModule;
void init_pyabc(void);
Py_SetProgramName(argv[0]);
Py_NoSiteFlag = 1;
Py_Initialize();
init_pyabc();
pModule = PyImport_ImportModule("pyabc");
if (pModule)
{
Py_DECREF(pModule);
}
else
{
fprintf( pAbc->Err, "error: pyabc.py not found. PYTHONPATH may not be set properly.\n");
}
}
#endif /* ABC_PYTHON_EMBED */
// default options
fBatch = INTERACTIVE;
fInitSource = 1;
@ -354,12 +327,6 @@ int Abc_RealMain( int argc, char * argv[] )
}
}
#ifdef ABC_PYTHON_EMBED
{
Py_Finalize();
}
#endif /* ABC_PYTHON_EMBED */
// if the memory should be freed, quit packages
// if ( fStatus < 0 )
{

View File

@ -190,23 +190,6 @@ void Abc_UtilsSource( Abc_Frame_t * pAbc )
}
#endif
#ifdef ABC_PYTHON_EMBED
if ( getenv("ABC_PYTHON_ABC_RC") )
{
/* read script file from $ABC_PYTHON_ABC_RC */
char * sPath = getenv("ABC_PYTHON_ABC_RC");
if (sPath){
char * sCmd = ABC_ALLOC(char, strlen(sPath) + 50);
(void) sprintf(sCmd, "source -s %s", sPath);
(void) Cmd_CommandExecute(pAbc, sCmd);
ABC_FREE(sCmd);
}
}
else
#endif /* #ifdef ABC_PYTHON_EMBED */
{
char * sPath1, * sPath2;
char * home;

View File

@ -41,8 +41,6 @@ ABC_NAMESPACE_IMPL_START
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
#ifndef ABC_PYTHON_EMBED
int Util_SignalSystem(const char* cmd)
{
return system(cmd);
@ -63,8 +61,6 @@ void Util_SignalTmpFileRemove(const char* fname, int fLeave)
}
}
#endif /* ABC_PYTHON_EMBED */
ABC_NAMESPACE_IMPL_END
////////////////////////////////////////////////////////////////////////

View File

@ -1,78 +0,0 @@
#!/bin/sh
#
# Setup the ABC/Py environment and run the ABC/Py executable
# (ABC/Py stands for ABC with embedded Python)
#
# ABC/Py expects the following directory structure
#
# abc_root/
# bin/
# abc - this script
# abc_exe - the ABC executable
# ... - Other scripts
# lib/
# pyabc.py - support file for pyabc extension
# python_library.zip - The Python standard library. Only if not using the system Python interpreter.
# *.so - Python extensions, Only if not using the system Python interpreter.
# scripts/
# *.py - default directory for python scripts
#
# usage: abspath <dir>
# get the absolute path of <dir>
abspath()
{
cwd="$(pwd)"
cd "$1"
echo "$(pwd)"
cd "${cwd}"
}
self=$0
self_dir=$(dirname "${self}")
self_dir=$(abspath "${self_dir}")
abc_root=$(dirname "${self_dir}")
abc_exe="${abc_root}/bin/abc_exe"
PYTHONPATH="${abc_root}/lib":"${PYTHONPATH}"
export PYTHONPATH
if [ -d "${abc_root}/scripts" ] ; then
ABC_PYTHON_SCRIPTS="${abc_root}/scripts"
export ABC_PYTHON_SCRIPTS
PYTHONPATH="${ABC_PYTHON_SCRIPTS}":"${PYTHONPATH}"
export PYTHONPATH
fi
if [ -f "${abc_root}/scripts/abc.rc" ] ; then
ABC_PYTHON_ABC_RC="${abc_root}/scripts/abc.rc"
export ABC_PYTHON_ABC_RC
fi
if [ -f "${abc_root}/lib/python_library.zip" ] ; then
PYTHONHOME="${abc_root}"
export PYTHONHOME
PYTHONPATH="${abc_root}/lib/python_library.zip":"${PYTHONPATH}"
export PYTHONPATH
fi
PATH="${abc_root}/bin:$PATH"
export PATH
if [ "$1" = "--debug" ]; then
shift
abc_debugger="$1"
shift
echo export PYTHONHOME=$PYTHONHOME
echo export PYTHONPATH=$PYTHONPATH
echo export ABC_PYTHON_SCRIPTS=$ABC_PYTHON_SCRIPTS
echo export ABC_PYTHON_ABC_RC=$ABC_PYTHON_ABC_RC
fi
exec ${abc_debugger} "${abc_exe}" "$@"

View File

@ -1,54 +0,0 @@
# You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere
import pyabc
# A new command is just a function that accepts a list of string arguments
# The first argument is always the name of the command
# It MUST return an integer. -1: user quits, -2: error. Return 0 for success.
# a simple command that just prints its arguments and returns success
def pytest1_cmd(args):
print args
return 0
# registers the command:
# The first argument is the function
# The second argument is the category (mainly for the ABC help command)
# The third argument is the new command name
# Keet the fourth argument 0, or consult with Alan
pyabc.add_abc_command(pytest1_cmd, "Python-Test", "pytest1", 0)
# a simple command that just prints its arguments and runs the command 'scorr -h'
def pytest2_cmd(args):
print args
pyabc.run_command('scorr -h')
return 0
pyabc.add_abc_command(pytest2_cmd, "Python-Test", "pytest2", 0)
# Now a more complicated command with argument parsing
# This command gets two command line arguments -c and -v. -c cmd runs the command 'cmd -h' and -v prints the python version
# for more details see the optparse module: http://docs.python.org/library/optparse.html
import optparse
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
pyabc.add_abc_command(pytest3_cmd, "Python-Test", "pytest3", 0)

View File

@ -1,32 +0,0 @@
On Windows:
python setup.py build
python setup.py bdist_wininst
On Linux (from the main abc directory)
To build the extensions (make sure -fPIC is added to OPTFLAG in the main ABC Makefile first)
make ABC_PYTHON=/usr/bin/python pyabc_extension_install
To build the ABC with embedded python
make pyabc.tgz
Updating the latest version on mima:
alanmi@mima:~/abc_60$ cp ./src/python/build/lib.linux-x86_64-2.6/_pyabc.so /hd/common/pyabc/builds/101030/_pyabc.so
alanmi@mima:~/abc_60$ cp ./src/python/build/lib.linux-x86_64-2.6/pyabc.py /hd/common/pyabc/builds/101030/pyabc.py
alanmi@mima:/hd/common/pyabc$ rm current
alanmi@mima:/hd/common/pyabc$ ln -s builds/101030 current
alanmi@mima:/hd/common/pyabc$ ls -l
total 4
lrwxrwxrwx 1 alanmi common 13 2010-10-30 14:55 current -> builds/101030
Latest documentation:
http://goo.gl/jNV2

View File

@ -1,37 +0,0 @@
class _Getch:
"""Gets a single character from standard input. Does not echo to the screen."""
def __init__(self):
try:
self.impl = _GetchWindows()
except ImportError:
self.impl = _GetchUnix()
def __call__(self): return self.impl()
class _GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class _GetchWindows:
def __init__(self):
import msvcrt
def __call__(self):
import msvcrt
return msvcrt.getch()
getch = _Getch()

View File

@ -1,92 +0,0 @@
# To compile with the embedded python interpreter set
# the variable ABC_PYTHON to point to the python executable
#
# Examples:
# make ABC_PYTHON=/usr/bin/python
# make ABC_PYTHON=/usr/bin/python2.5
#
# To build the Python extension build the target pyabc
# To create a package of ABC with embedded Python use the target pyabc.tgz
ifdef ABC_PYTHON
# get the directory containing this file
ABC_PYTHON_FILES_PREFIX := $(CURDIR)/src/python
ABC_SWIG := swig
ABC_PYTHON_CONFIG := $(ABC_PYTHON)-config
ABC_PYTHON_CFLAGS := $(shell $(ABC_PYTHON_CONFIG) --includes) -DABC_PYTHON_EMBED=1
ABC_PYTHON_LDFLAGS := $(shell $(ABC_PYTHON_CONFIG) --ldflags)
CFLAGS += $(ABC_PYTHON_CFLAGS)
CXXFLAGS += $(ABC_PYTHON_CFLAGS)
LIBS += $(ABC_PYTHON_LDFLAGS)
ABC_PYTHON_SRC := $(ABC_PYTHON_FILES_PREFIX)/pyabc_wrap.c
SRC += $(ABC_PYTHON_SRC)
GARBAGE += \
$(ABC_PYTHON_SRC) \
$(ABC_PYTHON_SRC:_wrap.c=.py) \
$(ABC_PYTHON_SRC:_wrap.c=.pyc) \
$(ABC_PYTHON_FILES_PREFIX)/build \
$(ABC_PYTHON_FILES_PREFIX)/dist \
pyabc.tgz
ABC_PYABC_DIR ?= pyabc
ABC_PYABC_TGZ ?= pyabc.tgz
ABC_PYABC_EXTRA_BIN ?=
ABC_PYABC_EXTRA_LIB ?=
%_wrap.c %.py : %.i
$(ABC_SWIG) -python -outdir $(<D) $<
.PHONY: pyabc_extension_build
pyabc_extension_build : lib$(PROG).a $(ABC_PYTHON_SRC) $(ABC_PYTHON_SRC:_wrap.c=.py)
( cd $(ABC_PYTHON_FILES_PREFIX) && rm -rf build/ )
( cd $(ABC_PYTHON_FILES_PREFIX) && $(ABC_PYTHON) setup.py build )
.PHONY: pyabc_extension_install
pyabc_extension_install : pyabc_extension_build
( cd $(ABC_PYTHON_FILES_PREFIX) && $(ABC_PYTHON) setup.py install --user )
.PHONY: pyabc_extension_bdist
pyabc_extension_bdist : pyabc_extension_build
( cd $(ABC_PYTHON_FILES_PREFIX) && python setup.py bdist )
.PHONY: pyabc_tgz
pyabc_tgz : $(ABC_PYABC_TGZ)
$(ABC_PYABC_TGZ) : $(PROG) $(ABC_PYTHON_SRC:_wrap.c=.py) $(ABC_PYTHON_FILES_PREFIX)/abc.sh $(ABC_PYTHON_FILES_PREFIX)/package.py
$(ABC_PYTHON) $(ABC_PYTHON_FILES_PREFIX)/package.py \
--pyabc_dir=$(ABC_PYABC_DIR) \
--abc=$(PROG) \
--abc_sh=$(ABC_PYTHON_FILES_PREFIX)/abc.sh \
--pyabc=$(ABC_PYTHON_FILES_PREFIX) \
--extra_bin="$(ABC_PYABC_EXTRA_BIN)" \
--extra_lib="$(ABC_PYABC_EXTRA_LIB)" \
--out=$@ \
$(ABC_PYTHON_OPTIONS)
PYABC_INSTALL_TARGET ?= $(shell date +%Y-%m-%d_%H-%M.%N_${USER})
PYABC_INSTALL_TARGET := $(PYABC_INSTALL_TARGET)
PYABC_INSTALL_DIR ?= /hd/common/pyabc/builds/pyabc_builds/
pyabc_install_target: pyabc_extension_bdist
mkdir -p "$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)"
tar \
--directory="$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)" \
--show-transformed-names \
--transform='s#^.*/##g' \
-xvzf "$(ABC_PYTHON_FILES_PREFIX)/dist/pyabc-1.0.linux-x86_64.tar.gz"
find "$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)/"* -type d | xargs rmdir
echo "Installed at $(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)"
endif

View File

@ -1,176 +0,0 @@
import os
import sys
import optparse
import zipfile
import tarfile
import tempfile
import time
import py_compile
def zip_library(f, extra_files = []):
lib = "%s/lib/python%s/"%(sys.prefix,sys.version[:3])
zf = zipfile.ZipFile(f, "w", zipfile.ZIP_DEFLATED)
for root, _, files in os.walk(lib):
arcroot = os.path.relpath(root, lib)
for f in files:
_, ext = os.path.splitext(f)
if ext in ['.py']:
zf.write(os.path.join(root,f), os.path.join(arcroot, f))
for s, r in extra_files:
zf.write( s, r )
zf.close()
def add_python_lib(tf, lib_dir, lib, mtime):
_, prefix = os.path.split(lib)
for root, _, files in os.walk(lib):
relpath = os.path.relpath(root, lib)
if '.hg' in relpath.split('/'):
continue
if relpath=='.':
arcroot = lib_dir
else:
arcroot = os.path.join( lib_dir, os.path.relpath(root, lib) )
arcroot = os.path.join(arcroot, prefix)
add_dir(tf, arcroot, mtime)
for f in files:
_, ext = os.path.splitext(f)
if ext in ['.py', '.so']:
add_file( tf, os.path.join(root,f), os.path.join(arcroot, f), 0666, mtime)
def add_dir(tf, dir, mtime):
ti = tarfile.TarInfo(dir)
ti.mode = 0777
ti.mtime = mtime
ti.type = tarfile.DIRTYPE
tf.addfile(ti)
def add_fileobj(tf, f, arcname, mode, mtime):
ti = tarfile.TarInfo(arcname)
ti.mode = mode
ti.mtime = mtime
f.seek(0, os.SEEK_END)
ti.size = f.tell()
f.seek(0, os.SEEK_SET)
tf.addfile(ti, f)
def add_file(tf, fname, arcname, mode, mtime):
print "\t adding %s as %s"%(fname, arcname)
with open(fname, "rb") as f:
add_fileobj(tf, f, arcname, mode, mtime)
def package(pyabc_dir, extra_bin, extra_lib, extra_files, abc_exe, abc_sh, pyabc, ofname, scripts_dir, use_sys):
mtime = time.time()
tf = tarfile.open(ofname, "w:gz")
add_dir(tf, "%s"%pyabc_dir, mtime)
add_dir(tf, "%s/bin"%pyabc_dir, mtime)
add_file(tf, abc_exe, "%s/bin/abc_exe"%pyabc_dir, 0777, mtime)
add_file(tf, abc_sh, "%s/bin/abc"%pyabc_dir, 0777, mtime)
if scripts_dir:
for fn in os.listdir(scripts_dir):
if fn.startswith('.'):
continue
fullname = os.path.join(scripts_dir, fn)
if os.path.isfile(fullname):
fnroot, fnext = os.path.splitext(fn)
if fnext==".sh":
add_file( tf, fullname, os.path.join("%s/bin"%pyabc_dir, fnroot), 0777, mtime)
elif fnext not in ( '.pyc', '.pyo'):
add_file( tf, fullname, os.path.join("%s/scripts"%pyabc_dir, fn), 0666, mtime)
for bin in extra_bin:
add_file( tf, bin, os.path.join("%s/bin"%pyabc_dir, os.path.basename(bin)), 0777, mtime)
lib_dir = "%s/lib"%pyabc_dir
add_dir(tf, lib_dir, mtime)
for lib in extra_lib:
add_python_lib( tf, lib_dir, lib, mtime)
for file, dest in extra_files:
add_file(tf, file, '%s/%s'%(pyabc_dir, dest), 0666, mtime)
for entry in os.listdir(pyabc):
if entry.endswith('.py'):
add_file( tf, os.path.join(pyabc, entry), os.path.join("%s/lib"%pyabc_dir, entry), 0666, mtime)
if not use_sys:
# ZIP standard library
zf = tempfile.NamedTemporaryFile("w+b")
#zip_library(zf, [(pyabc, "pyabc.py")])
zip_library(zf, [])
zf.flush()
add_fileobj(tf, zf, "%s/lib/python_library.zip"%pyabc_dir, 0666, mtime)
zf.close()
# add all extensions
lib_dynload = os.path.join(sys.exec_prefix,"lib", "python%s"%sys.version[:3], "lib-dynload")
for fn in os.listdir(lib_dynload):
fullname = os.path.join(lib_dynload, fn)
if os.path.isfile(fullname):
add_file( tf, fullname, os.path.join("%s/lib"%pyabc_dir, fn), 0666, mtime)
tf.close()
def main(args):
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage)
parser.add_option("-d", "--pyabc_dir", dest="pyabc_dir", help="name of generated directory" )
parser.add_option("-b", "--extra_bin", dest="extra_bin", help="extra binaries to pack" )
parser.add_option("-l", "--extra_lib", dest="extra_lib", help="extra directories in lib to pack" )
parser.add_option("-f", "--extra_files", dest="extra_files", help="additional files (comma separated pairs of file:dest" )
parser.add_option("-a", "--abc", dest="abc", help="location of the ABC exeutable")
parser.add_option("-s", "--abc_sh", dest="abc_sh", help="location of the ABC setup script")
parser.add_option("-p", "--pyabc", dest="pyabc", help="location of pyabc.py")
parser.add_option("-o", "--out", dest="out", help="location of output tar gzipped file")
parser.add_option("-x", "--scripts", dest="scripts", default="scripts", help="location of scripts")
parser.add_option("-S", "--system", action="store_false", dest="sys", default=True, help="use default python installation")
options, args = parser.parse_args(args)
if len(args) > 1:
parser.print_help()
return 1
if not options.pyabc_dir or not options.abc or not options.abc_sh or not options.pyabc or not options.out:
parser.print_help()
return 1
extra_bin = options.extra_bin.split(',') if options.extra_bin else []
extra_lib = options.extra_lib.split(',') if options.extra_lib else []
extra_files = [ s.split(':') for s in options.extra_files.split(',')] if options.extra_files else []
return package(options.pyabc_dir, extra_bin, extra_lib, extra_files, options.abc, options.abc_sh, options.pyabc, options.out, options.scripts, options.sys)
if __name__=="__main__":
main(sys.argv)

File diff suppressed because it is too large Load Diff

View File

@ -1,412 +0,0 @@
"""
module pyabc_split
Executes python functions and their arguements as separate processes and returns their return values through pickling. This modules offers a single function:
Function: split_all(funcs)
The function returns a generator objects that allowes iteration over the results,
Arguments:
funcs: a list of tuples (f, args) where f is a python function and args is a collection of arguments for f.
Caveats:
1. Global variables in the parent process are not affected by the child processes.
2. The functions can only return simple types, see the pickle module for details
Usage:
Assume you would like to run the function f_1(1), f_2(1,2), f_3(1,2,3) in different processes.
def f_1(i):
return i+1
def f_2(i,j):
return i*10+j+1
def f_3(i,j,k):
return i*100+j*10+k+1
Construct a tuple of the function and arguments for each function
t_1 = (f_1, [1])
t_2 = (f_2, [1,2])
t_3 = (f_3, [1,2,3])
Create a list containing these tuples:
funcs = [t_1, t_2, t_3]
Use the function split_all() to run these functions in separate processes:
for res in split_all(funcs):
print res
The output will be:
2
13
124
(The order may be different, except that in this case the processes are so fast that they terminate before the next one is created)
Alternatively, you may quite in the middle, say after the first process returns:
for res in split_all(funcs):
print res
break
This will kill all processes not yet finished.
To run ABC operations, that required saving the child process state and restoring it at the parent, use abc_split_all().
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')
funcs = [
defer(abc_f)("1000"),
defer(abc_f)("0001")
]
for _ in abc_split_all(funcs):
pyabc.run_command('write_verilog /dev/stdout')
Author: Baruch Sterin <sterin@berkeley.edu>
"""
import os
import select
import fcntl
import errno
import sys
import cPickle as pickle
import signal
import cStringIO
import traceback
from contextlib import contextmanager
import pyabc
def _retry_select(rlist):
while True:
try:
rrdy,_,_ = select.select(rlist,[],[])
if rrdy:
return rrdy
except select.error as e:
if e[0] == errno.EINTR:
continue
raise
class _splitter(object):
def __init__(self):
self.pids = []
self.fds = {}
self.buffers = {}
self.results = {}
def is_done(self):
return len(self.fds) == 0
def _kill(self, pids):
# close pipes and kill child processes
for pid in pids:
if pid == -1:
continue
i, fd = self.fds[pid]
del self.buffers[fd]
del self.fds[pid]
self.pids[i] = -1
self.results[pid] = None
os.close(fd)
try:
os.kill( pid, signal.SIGINT)
except Exception as e:
print >>sys.stderr, 'exception while trying to kill pid=%d: '%pid, e
raise
# wait for termination and update result
for pid in pids:
os.waitpid( pid, 0 )
def kill(self, ids):
self._kill( [ self.pids[i] for i in ids ] )
def cleanup(self):
self._kill( self.fds.keys() )
def child( self, fdw, f):
# call function
try:
res = f()
except:
traceback.print_exc()
raise
# write return value into pipe
with os.fdopen( fdw, "w" ) as fout:
pickle.dump(res, fout)
return 0
def _fork_one(self, f):
# create a pipe to communicate with the child process
pr,pw = os.pipe()
# set pr to be non-blocking
fcntl.fcntl(pr, fcntl.F_SETFL, os.O_NONBLOCK)
parentpid = os.getpid()
rc = 1
try:
# create child process
pid = os.fork()
if pid == 0:
# child process:
os.close(pr)
pyabc.close_on_fork(pw)
rc = self.child( pw, f)
os._exit(rc)
else:
# parent process:
os.close(pw)
return (pid, pr)
finally:
if os.getpid() != parentpid:
os._exit(rc)
def fork_one(self, func):
pid, fd = self._fork_one(func)
i = len(self.pids)
self.pids.append(pid)
self.fds[pid] = (i, fd)
self.buffers[fd] = cStringIO.StringIO()
return i
def fork_all(self, funcs):
return [ self.fork_one(f) for f in funcs ]
def communicate(self):
rlist = [ fd for _, (_,fd) in self.fds.iteritems() ]
rlist.append(pyabc.wait_fd)
stop = False
while not stop:
rrdy = _retry_select( rlist )
for fd in rrdy:
if fd == pyabc.wait_fd:
stop = True
continue
self.buffers[fd].write( os.read(fd, 16384) )
def get_next_result(self):
# read from the pipes as needed, while waiting for the next child process to terminate
self.communicate()
# wait for the next child process to terminate
pid, rc = os.wait()
assert pid in self.fds
# retrieve the pipe file descriptor
i, fd = self.fds[pid]
del self.fds[pid]
# remove the pid
self.pids[i] = -1
# retrieve the buffer
buffer = self.buffers[fd]
del self.buffers[fd]
# fill the buffer
while True:
s = os.read(fd, 16384)
if not s:
break
buffer.write(s)
os.close(fd)
try:
return (i, pickle.loads(buffer.getvalue()))
except EOFError, pickle.UnpicklingError:
return (i, None)
def __iter__(self):
def iterator():
while not self.is_done():
yield self.get_next_result()
return iterator()
@contextmanager
def make_splitter():
# ensure cleanup of child processes
s = _splitter()
try:
yield s
finally:
s.cleanup()
def split_all_full(funcs):
# provide an iterator for child process result
with make_splitter() as s:
s.fork_all(funcs)
for res in s:
yield res
def defer(f):
return lambda *args, **kwargs: lambda : f(*args,**kwargs)
def split_all(funcs):
for _, res in split_all_full( ( defer(f)(*args) for f,args in funcs ) ):
yield res
import tempfile
@contextmanager
def temp_file_names(suffixes):
names = []
try:
for suffix in suffixes:
with tempfile.NamedTemporaryFile(delete=False, suffix=suffix) as file:
names.append( file.name )
yield names
finally:
for name in names:
os.unlink(name)
class abc_state(object):
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 __del__(self):
os.unlink( self.aig )
os.unlink( self.log )
def restore(self):
pyabc.run_command(r'read_aiger %s'%self.aig)
pyabc.run_command(r'read_status %s'%self.log)
def abc_split_all(funcs):
import pyabc
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
def parent(res, aig, log):
pyabc.run_command(r'read_aiger %s'%aig)
pyabc.run_command(r'read_status %s'%log)
return res
with temp_file_names( ['.aig','.log']*len(funcs) ) as tmp:
funcs = [ defer(child)(f, tmp[2*i],tmp[2*i+1]) for i,f in enumerate(funcs) ]
for i, res in split_all_full(funcs):
yield i, parent(res, tmp[2*i],tmp[2*i+1])
if __name__ == "__main__":
# define some functions to run
def f_1(i):
return i+1
def f_2(i,j):
return i*10+j+1
def f_3(i,j,k):
return i*100+j*10+k+1
# Construct a tuple of the function and arguments for each function
t_1 = (f_1, [1])
t_2 = (f_2, [1,2])
t_3 = (f_3, [1,2,3])
# Create a list containing these tuples:
funcs = [t_1, t_2, t_3]
# Use the function split_all() to run these functions in separate processes:
for res in split_all(funcs):
print res
# Alternatively, quit after the first process returns:
for res in split_all(funcs):
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')

View File

@ -1,108 +0,0 @@
# You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere
import sys
import optparse
import subprocess
import tempfile
import threading
import os
import os.path
from contextlib import contextmanager, nested
import pyabc
def popen_and_wait_with_timeout(timeout,cmd, *args, **kwargs):
""" Wait for a subprocess.Popen object to terminate, or until timeout (in seconds) expires. """
p = None
t = None
try:
p = subprocess.Popen(cmd, *args, **kwargs)
if timeout <= 0:
timeout = None
t = threading.Thread(target=lambda: p.communicate())
t.start()
t.join(timeout)
finally:
if p is not None and p.poll() is None:
p.kill()
if t is not None and t.is_alive():
t.join()
if p is not None:
return p.returncode
return -1
@contextmanager
def temp_file_name(suffix=""):
file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
name = file.name
file.close()
try:
yield name
finally:
os.unlink(name)
def cygpath(path):
if sys.platform == "win32":
if os.path.isabs(path):
drive, tail = os.path.splitdrive(path)
drive = drive.lower()
tail = tail.split(os.path.sep)
return '/cygdrive/%s'%drive[0] + '/'.join(tail)
else:
path = path.split(os.path.sep)
return "/".join(path)
return path
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
def reachx_cmd(argv):
usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage, prog="reachx")
parser.add_option("-e", "--effort", dest="effort", type=int, default=0, help="effort level. [default=0, means unlimited]")
parser.add_option("-t", "--timeout", dest="timeout", type=int, default=0, help="timeout in seconds [default=0, unlimited]")
options, args = parser.parse_args(argv)
rc = run_reachx_cmd(options.effort, options.timeout)
print "%s command: jabc returned: %d"%(argv[0], rc)
return 0
pyabc.add_abc_command(reachx_cmd, "Verification", "reachx", 0)

View File

@ -1,111 +0,0 @@
"""
A simple context manager for redirecting streams in Python.
The streams are redirected at the the C runtime level so that the output of C extensions
that use stdio will also be redirected.
null_file : a stream representing the null device (e.g. /dev/null on Unix)
redirect: a context manager for redirecting streams
Author: Baruch Sterin (sterin@berkeley.edu)
"""
import os
import sys
from contextlib import contextmanager
null_file = open( os.devnull, "w" )
@contextmanager
def _dup( f ):
fd = os.dup( f.fileno() )
yield fd
os.close(fd)
@contextmanager
def save_stdout( src = sys.stdout ):
"""
Redirect
"""
fd = os.dup( src.fileno() )
own = True
try:
with os.fdopen( fd, "w", 0) as f:
own = False
yield f
except:
if own:
os.close(fd)
raise
@contextmanager
def redirect(dst = null_file, src = sys.stdout):
"""
Redirect the src stream into dst.
Example:
with redirect( open("somefile.txt", sys.stdout ) ):
do some stuff ...
"""
if src.fileno() == dst.fileno():
yield
return
with _dup( src ) as fd_dup_src:
dst.flush()
src.flush()
os.close( src.fileno() )
os.dup2( dst.fileno(), src.fileno() )
yield
src.flush()
os.close( src.fileno() )
os.dup2( fd_dup_src, src.fileno() )
def start_redirect(dst = null_file, src = sys.stdout):
"""
Start redirection of src stream into dst. Return the duplicated file handle of the source.
Example:
fd = start_redirect( open("somefile.txt"), sys.stdout )
... do some stuff ...
end_redirect(sys.stdout, fd)
"""
if src.fileno() == dst.fileno():
return None
fd_dup_src = os.dup( src.fileno() )
dst.flush()
src.flush()
os.close( src.fileno() )
os.dup2( dst.fileno(), src.fileno() )
return fd_dup_src
def end_redirect(src, fd_dup_src):
"""
End redirection of stream src.Redirect the src stream into dst. src is the source stream and fd_dup_src is the value returned by
start_redirect()
"""
if fd_dup_src is None:
return
src.flush()
os.close( src.fileno() )
os.dup2( fd_dup_src, src.fileno() )
os.close(fd_dup_src)

View File

@ -1,67 +0,0 @@
import sys
from distutils.core import setup, Extension
from distutils.sysconfig import get_config_vars
from distutils import util
from distutils.command.build_ext import build_ext
from distutils import sysconfig
define_macros = []
libraries = []
library_dirs = []
if sys.platform == "win32":
src_file = [ 'pyabc.i' ]
define_macros.append( ('WIN32', 1) )
define_macros.append( ('ABC_DLL', 'ABC_DLLEXPORT') )
libraries.append('abcr')
library_dirs.append('./../../lib')
else:
src_file = [ 'pyabc_wrap.c' ]
if get_config_vars()['SIZEOF_VOID_P'] > 4:
define_macros.append( ('LIN64', 1) )
else:
define_macros.append( ('LIN', 1) )
libraries.append( 'abc' )
libraries.append( 'rt' )
libraries.append( 'readline' )
library_dirs.append('./../../')
# ugly hack to silence strict-prototype warnings
class build_ext_subclass( build_ext ):
def build_extensions(self):
CC = sysconfig.get_config_var("CC")
if self.compiler.compiler_type == 'unix' and ( 'gcc' in CC or 'g++' in CC):
for e in self.extensions:
e.extra_compile_args.append( '-Wno-strict-prototypes' )
build_ext.build_extensions(self)
ext = Extension(
'_pyabc',
src_file,
define_macros=define_macros,
include_dirs = ["../../src"],
library_dirs=library_dirs,
libraries=libraries
)
setup(
name='pyabc',
version='1.0',
ext_modules=[ext],
py_modules=['pyabc','getch','pyabc_split','redirect', 'reachx_cmd'],
cmdclass = {'build_ext': build_ext_subclass }
)