Commit a8e1ba40 by Alan Mishchenko

The result of merging with recent PyABC changes.

parents f96f3fa5 b51ab369
...@@ -43,7 +43,7 @@ CFLAGS += -Wall -Wno-unused-function $(OPTFLAGS) $(patsubst %, -I%, $(MODULES) ...@@ -43,7 +43,7 @@ CFLAGS += -Wall -Wno-unused-function $(OPTFLAGS) $(patsubst %, -I%, $(MODULES)
CXXFLAGS += $(CFLAGS) CXXFLAGS += $(CFLAGS)
#LIBS := -m32 -ldl -rdynamic -lreadline -ltermcap #LIBS := -m32 -ldl -rdynamic -lreadline -ltermcap
LIBS := -ldl /usr/lib64/libreadline.a /usr/lib64/libncurses.a -rdynamic LIBS := -lreadline
SRC := SRC :=
GARBAGE := core core.* *.stackdump ./tags $(PROG) GARBAGE := core core.* *.stackdump ./tags $(PROG)
......
python new_abc_commands.py python new_abc_commands.py
python reachx_cmd.py python -c "import reachx_cmd"
#python C:\Research\ABC\AIG\Python\reachx_cmd.py
# global parameters # global parameters
set check # checks intermediate networks set check # checks intermediate networks
#set checkfio # prints warnings when fanins/fanouts are duplicated #set checkfio # prints warnings when fanins/fanouts are duplicated
set checkread # checks new networks after reading from file #set checkread # checks new networks after reading from file
set backup # saves backup networks retrived by "undo" and "recall" #set backup # saves backup networks retrived by "undo" and "recall"
set savesteps 1 # sets the maximum number of backup networks to save #set savesteps 1 # sets the maximum number of backup networks to save
set progressbar # display the progress bar #set progressbar # display the progress bar
# program names for internal calls # program names for internal calls
set dotwin dot.exe set dotwin dot.exe
...@@ -25,6 +24,10 @@ set gnuplotwin wgnuplot.exe ...@@ -25,6 +24,10 @@ set gnuplotwin wgnuplot.exe
set gnuplotunix gnuplot set gnuplotunix gnuplot
# standard aliases # standard aliases
alias srw "b; rw; b"
alias fix "ps; st; ps; srw; ps; plat; cycle -x -F 1; plat; logic; undc; st; zero; ps; scorr; ps"
alias fixp "st; srw; cycle -x -F 1; logic; undc; st; zero "
alias b balance alias b balance
alias cl cleanup alias cl cleanup
alias clp collapse alias clp collapse
...@@ -67,8 +70,8 @@ alias rvl read_verlib ...@@ -67,8 +70,8 @@ alias rvl read_verlib
alias rsup read_super mcnc5_old.super alias rsup read_super mcnc5_old.super
alias rlib read_library alias rlib read_library
alias rlibc read_library cadence.genlib alias rlibc read_library cadence.genlib
alias rw rewrite alias rw drw
alias rwz rewrite -z alias rwz drw -z
alias rf refactor alias rf refactor
alias rfz refactor -z alias rfz refactor -z
alias re restructure alias re restructure
...@@ -98,18 +101,18 @@ alias wv write_verilog ...@@ -98,18 +101,18 @@ alias wv write_verilog
# standard scripts # standard scripts
alias share "b; multi; fx; b" alias share "b; multi; fx; b"
alias resyn "b; rw; rwz; b; rwz; b" alias resyn "b; drw; rwz; b; rwz; b"
alias resyn2 "b; rw; rf; b; rw; rwz; b; rfz; rwz; b" alias resyn2 "b; drw; rf; b; drw; rwz; b; rfz; rwz; b"
alias resyn2a "b; rw; b; rw; rwz; b; rwz; b" alias resyn2a "b; drw; b; drw; rwz; b; rwz; b"
alias resyn3 "b; rs; rs -K 6; b; rsz; rsz -K 6; b; rsz -K 5; 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 compress "b -l; drw -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 compress2 "b -l; drw -l; rf -l; b -l; drw -l; rwz -l; b -l; rfz -l; rwz -l; b -l"
alias choice "fraig_store; resyn; fraig_store; resyn2; fraig_store; fraig_restore" 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 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 rwsat "st; drw -l; b -l; drw -l; rf -l"
alias rwsat2 "st; rw -l; b -l; rw -l; rf -l; fraig; rw -l; b -l; rw -l; rf -l" alias rwsat2 "st; drw -l; b -l; drw -l; rf -l; fraig; drw -l; b -l; drw -l; rf -l"
alias shake "st; ps; sat -C 5000; rw -l; ps; sat -C 5000; b -l; rf -l; ps; sat -C 5000; rfz -l; ps; sat -C 5000; rwz -l; ps; sat -C 5000; rfz -l; ps; sat -C 5000" alias shake "st; ps; sat -C 5000; drw -l; ps; sat -C 5000; b -l; rf -l; ps; sat -C 5000; rfz -l; ps; sat -C 5000; rwz -l; ps; sat -C 5000; rfz -l; ps; sat -C 5000"
alias snap fraig_store alias snap fraig_store
alias unsnap fraig_restore alias unsnap fraig_restore
...@@ -126,24 +129,24 @@ alias icb "ic -M 2 -B 10 -s" ...@@ -126,24 +129,24 @@ alias icb "ic -M 2 -B 10 -s"
alias cs "care_set " alias cs "care_set "
# resubstitution scripts for the IWLS paper # resubstitution scripts for the IWLS paper
alias src_rw "st; rw -l; rwz -l; rwz -l" alias src_rw "st; drw -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_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 src_rws "st; drw -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 resyn2rs "b; rs -K 6; drw; rs -K 6 -N 2; rf; rs -K 8; b; rs -K 8 -N 2; drw; 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" alias compress2rs "b -l; rs -K 6 -l; drw -l; rs -K 6 -N 2 -l; rf -l; rs -K 8 -l; b -l; rs -K 8 -N 2 -l; drw -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"
alias c2 "ua; compress2rs; sa" alias c2 "ua; compress2rs; sa"
alias ic "indcut -v" alias ic "indcut -v"
alias lp "lutpack" alias lp "lutpack"
alias c "ua; compress; sa" alias c "ua; compress; sa"
alias c1 "ua; compress;b -l; rs -K 6 -l; rw -l; rs -K 6 -N 2 -l; rf -l; rs -K 8 -l; b -l; sa" alias c1 "ua; compress;b -l; rs -K 6 -l; drw -l; rs -K 6 -N 2 -l; rf -l; rs -K 8 -l; b -l; sa"
alias dr dretime alias dr dretime
alias ds dsec -v alias ds dsec -v
alias dp dprove -v alias dp dprove -v
# experimental implementation of don't-cares # experimental implementation of don't-cares
alias resyn2rsdc "b; rs -K 6 -F 2; rw; rs -K 6 -N 2 -F 2; rf; rs -K 8 -F 2; b; rs -K 8 -N 2 -F 2; rw; rs -K 10 -F 2; rwz; rs -K 10 -N 2 -F 2; b; rs -K 12 -F 2; rfz; rs -K 12 -N 2 -F 2; rwz; b" alias resyn2rsdc "b; rs -K 6 -F 2; drw; rs -K 6 -N 2 -F 2; rf; rs -K 8 -F 2; b; rs -K 8 -N 2 -F 2; drw; rs -K 10 -F 2; rwz; rs -K 10 -N 2 -F 2; b; rs -K 12 -F 2; rfz; rs -K 12 -N 2 -F 2; rwz; b"
alias compress2rsdc "b -l; rs -K 6 -F 2 -l; rw -l; rs -K 6 -N 2 -F 2 -l; rf -l; rs -K 8 -F 2 -l; b -l; rs -K 8 -N 2 -F 2 -l; rw -l; rs -K 10 -F 2 -l; rwz -l; rs -K 10 -N 2 -F 2 -l; b -l; rs -K 12 -F 2 -l; rfz -l; rs -K 12 -N 2 -F 2 -l; rwz -l; b -l" alias compress2rsdc "b -l; rs -K 6 -F 2 -l; drw -l; rs -K 6 -N 2 -F 2 -l; rf -l; rs -K 8 -F 2 -l; b -l; rs -K 8 -N 2 -F 2 -l; drw -l; rs -K 10 -F 2 -l; rwz -l; rs -K 10 -N 2 -F 2 -l; b -l; rs -K 12 -F 2 -l; rfz -l; rs -K 12 -N 2 -F 2 -l; rwz -l; b -l"
# minimizing for FF literals # minimizing for FF literals
alias fflitmin "compress2rs; ren; sop; ps -f" alias fflitmin "compress2rs; ren; sop; ps -f"
...@@ -222,9 +225,10 @@ alias lcr "&get; &lcorr; &put" ...@@ -222,9 +225,10 @@ alias lcr "&get; &lcorr; &put"
alias trm "logic;trim;st;ps" alias trm "logic;trim;st;ps"
alias smp "ua;ps;scl;ps;rw;dr;lcorr;rw;dr;ps;scorr;ps;fraig;ps;dc2;dr;scorr -F 2;ps;dc2rs;w temp.aig" alias smp "ua;ps;scl;ps;drw;dr;lcorr;drw;dr;ps;scorr;ps;fraig;ps;dc2;dr;scorr -F 2;ps;dc2rs;w temp.aig"
alias smp1 "ua;ps;scl;ps;rw;dr;lcorr;rw;dr;ps;scorr;ps;fraig;ps;dc2;dr;ps;dc2rs;w temp.aig" alias smp1 "scl;drw;dr;lcorr;drw;dr;scorr;fraig;dc2rs"
alias smpf "ua;ps;scl;lcr;ps;rw;dr;ps;scr;ps;dc2;&get;&scorr -F 2;&put;dr;ps;dc2;ps;w temp.aig" alias smp2 "ua;ps;scl;ps;drw;dr;lcorr;drw;dr;ps;scorr;ps;fraig;ps;dc2;dr;ps;dc2rs;w temp.aig"
alias smpf "ua;ps;scl;lcr;ps;drw;dr;ps;scr;ps;dc2;&get;&scorr -F 2;&put;dr;ps;dc2;ps;w temp.aig"
alias &smp "ua;&get;&ps;&scl;&ps;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&ps;&scorr;&ps;&fraig;&ps;&dc2;&put;dr;&get;&scorr -F 2;&ps;&dc2;&put;w temp.aig" alias &smp "ua;&get;&ps;&scl;&ps;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&ps;&scorr;&ps;&fraig;&ps;&dc2;&put;dr;&get;&scorr -F 2;&ps;&dc2;&put;w temp.aig"
...@@ -233,7 +237,7 @@ alias smplite '&get;&scl;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&scorr;&dc2; ...@@ -233,7 +237,7 @@ alias smplite '&get;&scl;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&scorr;&dc2;
alias &smp1 "ua;&get;&ps;&scl;&ps;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&ps;&scorr;&ps;&fraig;&ps;&dc2;&put;dr;&get;&ps;&dc2;&put;w temp.aig" alias &smp1 "ua;&get;&ps;&scl;&ps;&dc2;&put;dr;&get;&lcorr;&dc2;&put;dr;&get;&ps;&scorr;&ps;&fraig;&ps;&dc2;&put;dr;&get;&ps;&dc2;&put;w temp.aig"
alias &smpf "ua;ps;rw;&get;&ps;&scl;&ps;&put;dr;&get;&ps;&lcorr;&ps;&dc2;&ps;&scorr;&ps;&put;rw;ps;w temp.aig" alias &smpf "ua;ps;drw;&get;&ps;&scl;&ps;&put;dr;&get;&ps;&lcorr;&ps;&dc2;&ps;&scorr;&ps;&put;drw;ps;w temp.aig"
#for each output separately #for each output separately
alias simpk "dprove -vrcbkmiu -B 10 -D 1000" alias simpk "dprove -vrcbkmiu -B 10 -D 1000"
...@@ -323,7 +327,12 @@ alias %scr "%get;%st;%scorr;%put;st" ...@@ -323,7 +327,12 @@ alias %scr "%get;%st;%scorr;%put;st"
alias sc "fold;w tempc.aig;unfold -s" alias sc "fold;w tempc.aig;unfold -s"
alias uc "r tempc.aig;unfold -s" alias uc "r tempc.aig;unfold -s"
alias smpc "scl;rw;ps;scorr -c;ps;fraig;ps;compress2rs;ps" alias smpc "scl;drw;ps;scorr -c;ps;fraig;ps;compress2rs;ps"
alias abseen "&get;,abs -vt=60 -timeout=60 -bob=10 -aig=temp.aig;r temp.aig"
alias pdreen "&get;,pdr -vt=60"
alias inteen "&get;,imc -vt=60"
alias bmceen "&get;,bmc -vt=60"
......
from pyabc import * from pyabc import *
import pyabc_split
import par
import redirect import redirect
import sys import sys
import os import os
import time import time
import math import math
global G_C,G_T,latches_before_abs,latches_before_pba,n_pos_before,x_factor global G_C,G_T,latches_before_abs,latches_before_pba,n_pos_before,x_factor
""" """
...@@ -40,7 +44,7 @@ stackno_gabs = stackno_gore = stackno_greg= 0 ...@@ -40,7 +44,7 @@ stackno_gabs = stackno_gore = stackno_greg= 0
STATUS_UNKNOWN = -1 STATUS_UNKNOWN = -1
STATUS_SAT = 0 STATUS_SAT = 0
STATUS_UNSAT = 1 STATUS_UNSAT = 1
RESULT = ('SAT' , 'SAT', 'UNSAT', 'UNDECIDED but reduced', 'UNDECIDED, no reduction', 'UNDCIDED but reduced' ) RESULT = ('SAT' , 'SAT', 'UNSAT', 'UNDECIDED', 'UNDECIDED,', 'UNDCIDED' )
Sat_reg = 0 Sat_reg = 0
Sat_true = 1 Sat_true = 1
Unsat = 2 Unsat = 2
...@@ -190,29 +194,6 @@ def read_file(): ...@@ -190,29 +194,6 @@ def read_file():
def rf(): def rf():
read_file() read_file()
##def read_file():
## """This is the main program used for reading in a new circuit. The global file name is stored (f_name)
## Sometimes we want to know the initial starting name. The file name can have the .aig extension left off
## and it will assume that the .aig extension is implied. This should not be used for .blif files.
## Any time we want to process a new circuit, we should use this since otherwise we would not have the
## correct f_name."""
## global max_bmc, f_name, d_name, initial_f_name, x_factor
## x_factor = 1
## max_bmc = -1
## print 'Type in the name of the aig file to be read in'
## s = raw_input()
## if s[-4:] == '.aig':
## f_name = s[:-4]
## else:
## f_name = s
## s = s+'.aig'
## run_command(s)
## initial_f_name = f_name
## print_circuit_stats()
##
##def rf():
## """just an alias for read_file"""
## read_file()
def write_file(s): def write_file(s):
"""this is the main method for writing the current circuit to an AIG file on disk. """this is the main method for writing the current circuit to an AIG file on disk.
...@@ -236,7 +217,7 @@ def wf(): ...@@ -236,7 +217,7 @@ def wf():
def bmc_depth(): def bmc_depth():
""" Finds the number of BMC frames that the latest operation has used. The operation could be BMC, reachability """ Finds the number of BMC frames that the latest operation has used. The operation could be BMC, reachability
interpolation, abstract, speculate. max_bmc is continually increased. It reflects the maximum depth of any version of the circuit interpolation, abstract, speculate. max_bmc is continually increased. It reflects the maximum depth of any version of the circuit
including abstract ones, for which it is known that there is not cex out to that depth.""" including g ones, for which it is known that there is not cex out to that depth."""
global max_bmc global max_bmc
b = n_bmc_frames() b = n_bmc_frames()
max_bmc = max(b,max_bmc) max_bmc = max(b,max_bmc)
...@@ -301,43 +282,7 @@ def rc(file): ...@@ -301,43 +282,7 @@ def rc(file):
"""reads <file> so that if constraints are explicit, it will preserve them""" """reads <file> so that if constraints are explicit, it will preserve them"""
abc('&r %s;&put'%file) abc('&r %s;&put'%file)
##def push(file):
## """ saves <file>.aig in stack_x"""
## global stackno_gabs, stackno_gsrm, stackno_greg
## if 'gabs' in file:
## snm = 'gabs'
## elif 'gsrm' in file:
## snm = 'gsrm'
## elif 'x' in file:
## snm = 'greg'
## else:
## print 'wrong file name'
## return
## print snm
## sn = 'stackno_%s'%snm
## print sn
## exec 'sn += sn'
## print sn, eval(sn)
## run_command("r %s.aig"%file)
## run_command("w %s_%d.aig"%(file,eval(sn)))
##
##def pop(file):
## """ reads top <file>.aig in stack_1 and saves it in <file>.aig"""
## global stackno_gabs, stackno_gsrm, stackno_greg
## if 'gabs' in file:
## sn = 'gabs'
## if 'gsrm' in file:
## sn = 'gsrm'
## if 'x' in file:
## sn = 'greg'
## else:
## print 'wrong file name'
## return
## run_command("r %s_%d.aig"%(file,eval(sn)))
## run_command("w %s.aig"%file)
## os.remove("%s_%d.aig"%(file,eval(sn)))
## exec 'sn = sn-1'
## # need to protect against wrong stack count
def fast_int(n): def fast_int(n):
"""This is used to eliminate easy-to-prove outputs. Arg n is conflict limit to be used """This is used to eliminate easy-to-prove outputs. Arg n is conflict limit to be used
...@@ -382,10 +327,10 @@ def simplify(): ...@@ -382,10 +327,10 @@ def simplify():
# set_globals() # set_globals()
## print 'simplify initial ', ## print 'simplify initial ',
## ps() ## ps()
abc('w t.aig') #abc('w t.aig')
n=n_ands() n=n_ands()
abc('scl') abc('scl')
if n > 30000: if n > 40000:
abc('&get;&scl;&put') abc('&get;&scl;&put')
n = n_ands() n = n_ands()
if n < 100000: if n < 100000:
...@@ -393,7 +338,7 @@ def simplify(): ...@@ -393,7 +338,7 @@ def simplify():
run_command('ps') run_command('ps')
print '.', print '.',
n = n_ands() n = n_ands()
if n<45000: if n<60000:
abc("&get;&scorr -F 2;&put;dc2rs") abc("&get;&scorr -F 2;&put;dc2rs")
print '.', print '.',
#ps() #ps()
...@@ -403,28 +348,34 @@ def simplify(): ...@@ -403,28 +348,34 @@ def simplify():
#ps() #ps()
n = n_ands() n = n_ands()
n = n_ands() n = n_ands()
if n <= 30000: if n <= 40000:
print '.', print '.',
#ps() #ps()
if n > 15000: if n > 30000:
abc("dc2rs") abc("dc2rs")
print '.', print '.',
else: ## else:
abc("scorr -F 2;dc2rs") ## abc("scorr -F 2;dc2rs")
print '.', ## print '.',
#ps() ## ps()
n = max(1,n_ands()) n = max(1,n_ands())
ps() #ps()
if n < 20000: if n < 30000:
abc('scl;rw;dr;lcorr;rw;dr')
m = int(min( 60000/n, 16)) m = int(min( 60000/n, 16))
#print 'm = %d'%m #print 'm = %d'%m
if m >= 4: if m >= 1:
j = 4 j = 1
while j <= m: while j <= m:
set_size() set_size()
#print 'j - %d'%j #print 'j - %d'%j
abc('scl;dr;dc2;scorr -C 5000 -F %d'%j) #abc('scl;dr;dc2;scorr -C 5000 -F %d'%j)
if check_size() == 1: if j<8:
abc('dc2')
else:
abc('dc2rs')
abc('scorr -C 5000 -F %d'%j)
if check_size():
break break
j = 2*j j = 2*j
#ps() #ps()
...@@ -464,6 +415,25 @@ def iterate_simulation(latches_before): ...@@ -464,6 +415,25 @@ def iterate_simulation(latches_before):
if not is_sat(): if not is_sat():
break break
def simulate():
"""Simulation is controlled by the amount
of memory it might use. At first wide but shallow simulation is done, bollowed by
successively more narrow but deeper simulation"""
global x_factor, f_name
## print 'RUNNING simulation iteratively'
f = 5
w = 255
for k in range(9):
f = min(f *2, 3500)
w = max(((w+1)/2)-1,1)
print '.',
abc('sim -m -F %d -W %d'%(f,w))
if is_sat():
print 'cex found in frame %d'%cex_frame()
return 'SAT'
return 'UNDECIDED'
def iterate_abstraction_refinement(latches_before,NBF): def iterate_abstraction_refinement(latches_before,NBF):
"""Subroutine of 'abstract' which does the refinement of the abstracted model, """Subroutine of 'abstract' which does the refinement of the abstracted model,
using counterexamples found by BMC or BDD reachability""" using counterexamples found by BMC or BDD reachability"""
...@@ -472,8 +442,7 @@ def iterate_abstraction_refinement(latches_before,NBF): ...@@ -472,8 +442,7 @@ def iterate_abstraction_refinement(latches_before,NBF):
F = 2000 F = 2000
else: else:
F = 2*NBF F = 2*NBF
print '\nIterating BMC or BDD reachability' print '\nIterating BMC/PDR'
reach_sw = 0
always_reach = 0 always_reach = 0
cexf = 0 cexf = 0
reach_failed = 0 reach_failed = 0
...@@ -490,36 +459,47 @@ def iterate_abstraction_refinement(latches_before,NBF): ...@@ -490,36 +459,47 @@ def iterate_abstraction_refinement(latches_before,NBF):
nlri = n_latches()+ri nlri = n_latches()+ri
#reach_allowed = ((nlri<150) or (((cexf>250))&(nlri<300))) #reach_allowed = ((nlri<150) or (((cexf>250))&(nlri<300)))
reach_allowed = ((nlri<75) or (((cexf>250))&(nlri<300))) reach_allowed = ((nlri<75) or (((cexf>250))&(nlri<300)))
pdr_allowed = True
bmc = False
t = max(1,G_T) t = max(1,G_T)
if not F == -1: if not F == -1:
F = int(1.5*max_bmc) F = int(1.5*max_bmc)
if (((reach_allowed or (reach_sw ==1)) and not reach_failed)): if (((reach_allowed or pdr_allowed ) and not reach_failed)):
#cmd = 'reach -B 200000 -F 3500 -T %f'%t #cmd = 'reach -B 200000 -F 3500 -T %f'%t
#cmd = 'reachx -e %d -t %d'%(int(long(t)),max(10,int(t))) #cmd = 'reachx -e %d -t %d'%(int(long(t)),max(10,int(t)))
cmd = 'reachx -t %d'%max(10,int(t)) #cmd = 'reachx -t %d'%max(10,int(t))
reach_sw = 1 cmd = '&get;,pdr -vt=%f'%t
else: else:
reach_sw = 0 #cmd = 'bmc3 -C %d -T %f -F %d'%(G_C,t,F)
cmd = 'bmc3 -C %d -T %f -F %d'%(G_C,t,F) bmc = True
print 'RUNNING %s'%cmd cmd = '&get;,bmc -vt=%f'%(t)
#cmd = '&get;,pdr -vt=%f'%(t)
print '\n***RUNNING %s'%cmd
#run_command(cmd)
last_bmc = max_bmc
abc(cmd) abc(cmd)
if prob_status() == 1: if prob_status() == 1:
print 'Reachability went to %d frames, '%n_bmc_frames() #print 'Depth reached %d frames, '%n_bmc_frames()
print 'UNSAT' print 'UNSAT'
return Unsat return Unsat
cexf = cex_frame() cexf = cex_frame()
set_max_bmc(cexf -1) #print 'cex depth = %d'%cexf
if ((not is_sat()) and (reach_sw == 1)): #set_max_bmc(cexf -1)
if ((not is_sat()) ):
reach_failed = 1 # if ever reach failed, then we should not try it again on more refined models reach_failed = 1 # if ever reach failed, then we should not try it again on more refined models
if is_sat(): if is_sat():
set_max_bmc(cex_frame()-1) #print 'CEX in frame %d for output %d'%(cex_frame(),cex_po())
#set_max_bmc(cexf-1)
refine_with_cex() # if cex can't refine, status is set to Sat_true refine_with_cex() # if cex can't refine, status is set to Sat_true
if is_sat(): if is_sat():
print 'cex did not refine. Implies true_sat' print 'cex did not refine. Implies true_sat'
return Sat_true return Sat_true
else: else:
print "No CEX found in %d frames"%n_bmc_frames() print "No CEX found in %d frames"%n_bmc_frames()
if reach_sw == 0: set_max_bmc(n_bmc_frames())
if bmc:
break
elif max_bmc> 1.2*last_bmc: # if pdr increased significantly over abs, the assume OK
break break
else: else:
continue continue
...@@ -543,29 +523,18 @@ def abstract(): ...@@ -543,29 +523,18 @@ def abstract():
print 'Start: ', print 'Start: ',
print_circuit_stats() print_circuit_stats()
c = 1.5*G_C c = 1.5*G_C
#c = 20000 #t = max(1,1.25*G_T)
t = max(1,1.25*G_T) t = 2*max(1,1.25*G_T)
method = 3
if n_ands() > 100000:
method = 0
s = min(max(3,c/30000),10) # stability between 3 and 10 s = min(max(3,c/30000),10) # stability between 3 and 10
if max_bmc == -1: time = max(1,.01*G_T)
time = max(1,.01*G_T) abc('&get;,bmc -vt=%f'%time)
abc('bmc3 -C %d -T %f -F 165'%(.01*G_C, time)) print 'BMC went %d frames'%n_bmc_frames()
set_max_bmc(bmc_depth()) set_max_bmc(bmc_depth())
f = min(250,1.5*max_bmc) f = max(2*max_bmc,20)
f = max(20, f) b = min(max(10,max_bmc),200)
f = 10*f cmd = '&get;,abs -bob=%d -stable=%d -timeout=%f -vt=%f -depth=%d'%(b,s,t,t,f)
if not method == 0: print ' Running %s'%cmd
b = 10 run_command(cmd)
b = max(b,max_bmc+2)
b = b*2**(x_factor-1)
b = 2*b
print 'Neen abstraction params: Bob = %d, Method #%d, %d conflicts, %d stable, %d sec., %d frames'%(b,method,c/3,s,t,f)
abc('&get; &abs_newstart -v -B %f -A %d -C %d -S %d -V %f -F %d'%(b,method,c/3,s,t,f))
else:
abc('&get;&abs_start -v -C 500000 -R 1')
#abc('w abstemp.aig')
if is_sat(): if is_sat():
print 'Found true counterexample in frame %d'%cex_frame() print 'Found true counterexample in frame %d'%cex_frame()
return Sat_true return Sat_true
...@@ -573,8 +542,8 @@ def abstract(): ...@@ -573,8 +542,8 @@ def abstract():
print 'Abstraction good to %d frames'%n_bmc_frames() print 'Abstraction good to %d frames'%n_bmc_frames()
set_max_bmc(NBF) set_max_bmc(NBF)
abc('&w %s_greg.aig; &abs_derive; &put; w %s_gabs.aig'%(f_name,f_name)) abc('&w %s_greg.aig; &abs_derive; &put; w %s_gabs.aig'%(f_name,f_name))
print 'First abstraction: ', ## print 'First abstraction: ',
print_circuit_stats() ## print_circuit_stats()
latches_after = n_latches() latches_after = n_latches()
#if latches_before_abs == latches_after: #if latches_before_abs == latches_after:
if latches_after >= .98*latches_before_abs: if latches_after >= .98*latches_before_abs:
...@@ -583,7 +552,7 @@ def abstract(): ...@@ -583,7 +552,7 @@ def abstract():
return Undecided_no_reduction return Undecided_no_reduction
# refinement loop # refinement loop
if (n_ands() + n_latches() + n_pis()) < 15000: if (n_ands() + n_latches() + n_pis()) < 15000:
print 'Running simulation iteratively' print '\n***Running simulation iteratively'
for i in range(5): for i in range(5):
result = iterate_simulation(latches_before_abs) result = iterate_simulation(latches_before_abs)
if result == Restart: if result == Restart:
...@@ -610,7 +579,8 @@ def absv(n,v): ...@@ -610,7 +579,8 @@ def absv(n,v):
s = min(max(3,c/30000),10) # stability between 3 and 10 s = min(max(3,c/30000),10) # stability between 3 and 10
if max_bmc == -1: if max_bmc == -1:
time = max(1,.01*G_T) time = max(1,.01*G_T)
abc('bmc3 -C %d -T %f -F 165'%(.01*G_C, time)) #abc('bmc3 -C %d -T %f -F 165'%(.01*G_C, time))
abc('&get;,bmc -vt=%f'%time)
set_max_bmc(bmc_depth()) set_max_bmc(bmc_depth())
f = min(250,1.5*max_bmc) f = min(250,1.5*max_bmc)
f = max(20, f) f = max(20, f)
...@@ -648,7 +618,7 @@ def spec(): ...@@ -648,7 +618,7 @@ def spec():
set_globals() set_globals()
t = max(1,.5*G_T) t = max(1,.5*G_T)
r = max(1,int(t)) r = max(1,int(t))
print 'Running &equiv2 with C = %d, T = %f sec., F = %d -S 1 -R %d'%(G_C,t,200,r) print '\n***Running &equiv2 with C = %d, T = %f sec., F = %d -S 1 -R %d'%(G_C,t,200,r)
abc("&get; &equiv2 -C %d -F 200 -T %f -S 1 -R %d; &semi -F 50; &speci -F 20 -C 1000;&srm; r gsrm.aig; w %s_gsrm.aig; &w %s_gore.aig"%((G_C),t,r,f_name,f_name)) abc("&get; &equiv2 -C %d -F 200 -T %f -S 1 -R %d; &semi -F 50; &speci -F 20 -C 1000;&srm; r gsrm.aig; w %s_gsrm.aig; &w %s_gore.aig"%((G_C),t,r,f_name,f_name))
print 'Initial speculation: ', print 'Initial speculation: ',
print_circuit_stats() print_circuit_stats()
...@@ -723,11 +693,13 @@ def speculate(): ...@@ -723,11 +693,13 @@ def speculate():
set_globals() set_globals()
t = max(1,.5*G_T) t = max(1,.5*G_T)
r = max(1,int(t)) r = max(1,int(t))
print 'Running &equiv2 with C = %d, T = %f sec., F = %d -S 1 -R %d'%(G_C,t,200,r) abc('write spec_temp.aig')
abc("&get; &equiv2 -C %d -F 200 -T %f -S 1 -R %d; &semi -F 50; &speci -F 20 -C 1000;&srm; r gsrm.aig; w %s_gsrm.aig; &w %s_gore.aig"%((G_C),t,r,f_name,f_name)) print '\n***Running &equiv2 with C = %d, T = %f sec., F = %d -S 1 -R %d'%(G_C,t,200,r)
## abc("&get; &equiv2 -C %d -F 200 -T %f -S 1 -R %d; &semi -F 50; &speci -F 20 -C 1000;&srm; r gsrm.aig; w %s_gsrm.aig; &w %s_gore.aig"%((G_C),t,r,f_name,f_name))
abc("&get; &equiv2 -C %d -F 200 -T %f -S 1 -R %d; &semi -W 63 -S 5 -C 500 -F 500; &speci -F 200 -C 5000;&srm; r gsrm.aig; w %s_gsrm.aig; &w %s_gore.aig"%((G_C),t,r,f_name,f_name))
print 'Initial speculation: ', print 'Initial speculation: ',
print_circuit_stats() print_circuit_stats()
print 'Speculation good to %d frames'%n_bmc_frames() #print 'Speculation good to %d frames'%n_bmc_frames()
#simplify() #simplify()
if n_pos_before == n_pos(): if n_pos_before == n_pos():
print 'No new outputs. Quitting speculate' print 'No new outputs. Quitting speculate'
...@@ -735,6 +707,12 @@ def speculate(): ...@@ -735,6 +707,12 @@ def speculate():
if is_sat(): if is_sat():
#print '\nWARNING: if an abstraction was done, need to refine it further\n' #print '\nWARNING: if an abstraction was done, need to refine it further\n'
return Sat_true return Sat_true
if n_latches() > .98*n_latches_before:
pre_simp()
if n_latches() > .98*n_latches_before:
print 'Quitting speculation - not enough gain'
abc('r spec_temp.aig')
return Undecided_no_reduction # not worth it
k = n_ands() + n_latches() + n_pis() k = n_ands() + n_latches() + n_pis()
n = 0 n = 0
if k < 15000: if k < 15000:
...@@ -746,7 +724,7 @@ def speculate(): ...@@ -746,7 +724,7 @@ def speculate():
elif k < 120000: elif k < 120000:
n = 8 n = 8
if n > 0: # simulation can run out of memory for too large designs, so be careful if n > 0: # simulation can run out of memory for too large designs, so be careful
print 'RUNNING simulation iteratively' print '\n***RUNNING simulation iteratively'
for i in range(5): for i in range(5):
result = run_simulation(n) result = run_simulation(n)
if result == Sat_true: if result == Sat_true:
...@@ -757,6 +735,7 @@ def speculate(): ...@@ -757,6 +735,7 @@ def speculate():
cexf = 0 cexf = 0
reach_failed = 0 reach_failed = 0
init = 1 init = 1
run_command('write temptemp.aig')
print '\nIterating BMC or BDD reachability' print '\nIterating BMC or BDD reachability'
while True: # now try real hard to get the last cex. while True: # now try real hard to get the last cex.
set_globals() set_globals()
...@@ -788,7 +767,8 @@ def speculate(): ...@@ -788,7 +767,8 @@ def speculate():
print 'Int found true cex: Output = %d, Frame = %d'%(cex_po(),cex_frame()) print 'Int found true cex: Output = %d, Frame = %d'%(cex_po(),cex_frame())
return Sat_true return Sat_true
refine_with_cex() refine_with_cex()
if n_pos_before == n_pos(): if ((n_pos_before == n_pos()) or (n_latches_before == n_latches())):
abc('r temp_spec.aig')
return Undecided_no_reduction return Undecided_no_reduction
if is_sat(): if is_sat():
print '1. cex failed to refine abstraction' print '1. cex failed to refine abstraction'
...@@ -800,11 +780,13 @@ def speculate(): ...@@ -800,11 +780,13 @@ def speculate():
ri = n_real_inputs() #seeing how many inputs would trm get rid of ri = n_real_inputs() #seeing how many inputs would trm get rid of
nlri = n_latches() + ri nlri = n_latches() + ri
reach_allowed = ((nlri<75) or (((cexf>250)) and (nlri<300))) reach_allowed = ((nlri<75) or (((cexf>250)) and (nlri<300)))
if (((reach_allowed or (reach_sw == 1)) and not reach_failed)): pdr_allowed = True
bmc = False
if (((reach_allowed or pdr_allowed ) and not reach_failed)):
t = max(1,1.2*G_T) t = max(1,1.2*G_T)
f = max(3500, 2*max_bmc) f = max(3500, 2*max_bmc)
cmd = 'reachx -t %d'%max(10,int(t)) #cmd = 'reachx -t %d'%max(10,int(t))
reach_sw = 1 cmd ='&get;,pdr -vt=%f'%t
else: else:
t = max(1,1.5*G_T) t = max(1,1.5*G_T)
if max_bmc == -1: if max_bmc == -1:
...@@ -812,16 +794,19 @@ def speculate(): ...@@ -812,16 +794,19 @@ def speculate():
else: else:
f = max_bmc f = max_bmc
f = int(1.5*f) f = int(1.5*f)
cmd = 'bmc3 -C %d -T %f -F %f'%(1.5*G_C,1.2*t,f) #cmd = 'bmc3 -C %d -T %f -F %f'%(1.5*G_C,1.2*t,f)
reach_sw = 0 bmc = True
print 'Running %s'%cmd cmd = '&get;,bmc -vt=%f'%(1.2*t)
print '\n***Running %s'%cmd
last_bmc = max_bmc
abc(cmd) abc(cmd)
#run_command(cmd)
if is_sat(): if is_sat():
cexf = cex_frame() cexf = cex_frame()
set_max_bmc(cexf - 1) #set_max_bmc(cexf - 1)
#This is a temporary fix since reachx always reports cex_ps = 0 #This is a temporary fix since reachx always reports cex_ps = 0
if ((cex_po() < n_pos_before) and (cmd[:3] == 'bmc')): if ((cex_po() < n_pos_before) and (cmd[:4] == '&get')):
print 'BMC found true cex: Output = %d, Frame = %d'%(cex_po(),cex_frame()) print 'BMC/PDR found true cex: Output = %d, Frame = %d'%(cex_po(),cex_frame())
return Sat_true return Sat_true
#End of temporary fix #End of temporary fix
refine_with_cex()#change the number of equivalences refine_with_cex()#change the number of equivalences
...@@ -829,14 +814,16 @@ def speculate(): ...@@ -829,14 +814,16 @@ def speculate():
return Undecided_no_reduction return Undecided_no_reduction
continue continue
else: else:
set_max_bmc(bmc_depth()) set_max_bmc(n_bmc_frames())
if prob_status() == 1:
#print 'Convergence reached in %d frames'%n_bmc_frames()
return Unsat
print 'No cex found in %d frames'%n_bmc_frames() print 'No cex found in %d frames'%n_bmc_frames()
if reach_sw == 0: if bmc:
break
elif max_bmc > 1.2*last_bmc:
break break
else: else:
if prob_status() == 1:
print 'Reachability converged in %d frames'%n_bmc_frames()
return Unsat
reach_failed = 1 reach_failed = 1
init = 1 init = 1
continue continue
...@@ -880,28 +867,39 @@ def quick_verify(n): ...@@ -880,28 +867,39 @@ def quick_verify(n):
if n_latches == 0: if n_latches == 0:
return check_sat() return check_sat()
abc('trm') abc('trm')
if is_sat():
return Sat_true
print 'After trimming: ', print 'After trimming: ',
print_circuit_stats() print_circuit_stats()
#try_rpm() #try_rpm()
set_globals() set_globals()
if is_sat(): t = max(1,.4*G_T)
return Sat_true print ' Running PDR for %d sec '%(t)
abc('&get;,pdr -vt=%f'%(t*.8))
status = get_status()
if not status == Unsat:
print 'PDR went to %d frames, '%n_bmc_frames(),
print RESULT[status]
return status #temporary
if status <= Unsat:
return status
N = bmc_depth()
c = max(G_C/10, 1000) c = max(G_C/10, 1000)
t = max(1,.4*G_T) t = max(1,.4*G_T)
print 'RUNNING interpolation with %d conflicts, max %d sec and 100 frames'%(c,t) print ' RUNNING interpolation with %d conflicts, max %d sec and 100 frames'%(c,t)
abc('int -v -F 100 -C %d -T %f'%(c,t)) #abc('int -v -F 100 -C %d -T %f'%(c,t))
abc(',imc -vt=%f '%t)
status = get_status() status = get_status()
if status <= Unsat: if status <= Unsat:
print 'Interpolation went to %d frames, '%n_bmc_frames(), print 'Interpolation went to %d frames, '%n_bmc_frames(),
print RESULT[status] print RESULT[status]
return status return status
N = bmc_depth()
L = n_latches() L = n_latches()
I = n_real_inputs() I = n_real_inputs()
if ( ((I+L<200)&(N>100)) or (I+L<125) or L < 51 ): #heuristic that if bmc went deep, then reachability might also if ( ((I+L<200)&(N>100)) or (I+L<125) or L < 51 ): #heuristic that if bmc went deep, then reachability might also
t = max(1,.4*G_T) t = max(1,.4*G_T)
cmd = 'reachx -t %d'%max(10,int(t)) cmd = 'reachx -t %d'%max(10,int(t))
print 'Running %s'%cmd print ' Running %s'%cmd
abc(cmd) abc(cmd)
status = get_status() status = get_status()
if status <= Unsat: if status <= Unsat:
...@@ -944,7 +942,8 @@ def try_rpm(): ...@@ -944,7 +942,8 @@ def try_rpm():
bmc_before = bmc_depth() bmc_before = bmc_depth()
#print 'running quick bmc to see if rpm is OK' #print 'running quick bmc to see if rpm is OK'
t = max(1,.1*G_T) t = max(1,.1*G_T)
abc('bmc3 -C %d, -T %f'%(.1*G_C, t)) #abc('bmc3 -C %d, -T %f'%(.1*G_C, t))
abc('&get;,bmc -vt=%f'%t)
if is_sat(): #rpm made it sat by bmc test, so undo rpm if is_sat(): #rpm made it sat by bmc test, so undo rpm
abc('r %s_savetemp.aig'%f_name) abc('r %s_savetemp.aig'%f_name)
else: else:
...@@ -970,13 +969,22 @@ def final_verify(): ...@@ -970,13 +969,22 @@ def final_verify():
L = n_latches() L = n_latches()
I = n_real_inputs() I = n_real_inputs()
#try_induction(G_C) #try_induction(G_C)
c = max(G_C/5, 1000)
t = max(1,G_T)
print '\n***Running PDR for %d sec'%(t)
abc('&get;,pdr -vt=%f'%(t*.8))
status = get_status()
if status <= Unsat:
print 'PDR went to %d frames, '%n_bmc_frames(),
print RESULT[status]
return status
if ( ((I+L<250)&(N>100)) or (I+L<200) or (L<51) ): #heuristic that if bmc went deep, then reachability might also if ( ((I+L<250)&(N>100)) or (I+L<200) or (L<51) ): #heuristic that if bmc went deep, then reachability might also
t = max(1,1.5*G_T) t = max(1,1.5*G_T)
#cmd = 'reach -v -B 1000000 -F 10000 -T %f'%t #cmd = 'reach -v -B 1000000 -F 10000 -T %f'%t
#cmd = 'reachx -e %d'%int(long(t)) #cmd = 'reachx -e %d'%int(long(t))
#cmd = 'reachx -e %d -t %d'%(int(long(t)),max(10,int(t))) #cmd = 'reachx -e %d -t %d'%(int(long(t)),max(10,int(t)))
cmd = 'reachx -t %d'%max(10,int(t)) cmd = 'reachx -t %d'%max(10,int(t))
print 'Running %s'%cmd print '\n***Running %s'%cmd
abc(cmd) abc(cmd)
status = get_status() status = get_status()
if status <= Unsat: if status <= Unsat:
...@@ -984,16 +992,17 @@ def final_verify(): ...@@ -984,16 +992,17 @@ def final_verify():
print RESULT[status] print RESULT[status]
return status return status
print 'BDD reachability aborted' print 'BDD reachability aborted'
#f = max(100,bmc_depth()) return status #temporary
c = max(G_C/5, 1000) #f = max(100, bmc_depth())
t = max(1,G_T) print '\n***RUNNING interpolation with %d conflicts, %d sec, max 100 frames'%(c,t)
print '\nRUNNING interpolation with %d conflicts, %d sec, max 100 frames'%(c,t) #abc('int -v -F 100 -C %d -T %f'%(c,t))
abc('int -v -F 100 -C %d -T %f'%(c,t)) abc(',imc -vt=%f '%t)
status = get_status() status = get_status()
if status <= Unsat: if status <= Unsat:
print 'Interpolation went to %d frames, '%n_bmc_frames(), print 'Interpolation went to %d frames, '%n_bmc_frames(),
print RESULT[status] print RESULT[status]
return status return status
t = max(1,G_T)
simplify() simplify()
if n_latches() == 0: if n_latches() == 0:
return check_sat() return check_sat()
...@@ -1005,7 +1014,7 @@ def check_sat(): ...@@ -1005,7 +1014,7 @@ def check_sat():
the remaining logic may be UNSAT, which is usually the case, but this has to be proved. The ABC command 'dsat' is used fro combinational problems""" the remaining logic may be UNSAT, which is usually the case, but this has to be proved. The ABC command 'dsat' is used fro combinational problems"""
## if n_ands() == 0: ## if n_ands() == 0:
## return Unsat ## return Unsat
abc('dsat -C %d'%G_C) abc('orpos;dsat -C %d'%G_C)
if is_sat(): if is_sat():
return Sat_true return Sat_true
elif is_unsat(): elif is_unsat():
...@@ -1026,7 +1035,7 @@ def try_induction(C): ...@@ -1026,7 +1035,7 @@ def try_induction(C):
"""Sometimes proving the property directly using induction works but not very often. """Sometimes proving the property directly using induction works but not very often.
For 'ind' to work, it must have only 1 output, so all outputs are or'ed together temporarily""" For 'ind' to work, it must have only 1 output, so all outputs are or'ed together temporarily"""
return Undecided_reduction return Undecided_reduction
print '\nTrying induction' print '\n***Running induction'
abc('w %s_temp.aig'%f_name) abc('w %s_temp.aig'%f_name)
abc('orpos; ind -uv -C %d -F 10'%C) abc('orpos; ind -uv -C %d -F 10'%C)
abc('r %s_savetemp.aig'%f_name) abc('r %s_savetemp.aig'%f_name)
...@@ -1055,11 +1064,11 @@ def final_verify_recur(K): ...@@ -1055,11 +1064,11 @@ def final_verify_recur(K):
if status >= Unsat: if status >= Unsat:
return status return status
if i > 0: if i > 0:
print 'SAT returned, trying less abstract backup' print 'SAT returned, Running less abstract backup'
continue continue
break break
if ((i == 0) and (status > Unsat) and (n_ands() > 0)): if ((i == 0) and (status > Unsat) and (n_ands() > 0)):
print '\nTrying speculate on initial backup number %d:'%i, print '\n***Running speculate on initial backup number %d:'%i,
abc('r %s_backup_%d.aig'%(initial_f_name,i)) abc('r %s_backup_%d.aig'%(initial_f_name,i))
ps() ps()
if n_ands() < 20000: if n_ands() < 20000:
...@@ -1073,29 +1082,42 @@ def final_verify_recur(K): ...@@ -1073,29 +1082,42 @@ def final_verify_recur(K):
return Undecided_reduction return Undecided_reduction
def smp():
pre_simp()
write_file('smp')
def pre_simp(): def pre_simp():
"""This uses a set of simplification algorithms which preprocesses a design. """This uses a set of simplification algorithms which preprocesses a design.
Includes forward retiming, quick simp, signal correspondence with constraints, trimming away Includes forward retiming, quick simp, signal correspondence with constraints, trimming away
PIs, and strong simplify""" PIs, and strong simplify"""
## print "Trying BMC for 2 sec."
## abc("&get; ,bmc -vt=2")
## if is_sat():
## return Sat_true
set_globals() set_globals()
#print 'trying forward' if n_latches == 0:
return check_sat()
#print '\n*** Running forward'
try_forward() try_forward()
#print 'trying quick simp' #print \n*** Running quick simp'
quick_simp() quick_simp()
#print 'trying_scorr_constr' #print 'Running_scorr_constr'
status = try_scorr_constr() status = try_scorr_constr()
#status = 3 #status = 3
#print 'trying trm' #print 'Running trm'
if ((n_ands() > 0) or (n_latches()>0)): if ((n_ands() > 0) or (n_latches()>0)):
abc('trm') abc('trm')
print 'Forward, quick_simp, scorr_constr,: ', print 'Forward, quick_simp, scorr_constr,: ',
print_circuit_stats() print_circuit_stats()
if n_latches() == 0:
return check_sat()
status = process_status(status) status = process_status(status)
if status <= Unsat: if status <= Unsat:
return status return status
simplify() simplify()
print 'Simplify: ', print 'Simplify: ',
print_circuit_stats() print_circuit_stats()
#abc('w temp_simp.aig')
if n_latches() == 0: if n_latches() == 0:
return check_sat() return check_sat()
try_phase() try_phase()
...@@ -1132,7 +1154,7 @@ def try_phase(): ...@@ -1132,7 +1154,7 @@ def try_phase():
simplified (with retiming to see if there is a significant reduction. simplified (with retiming to see if there is a significant reduction.
If not, then revert back to original""" If not, then revert back to original"""
n = n_phases() n = n_phases()
if ((n == 1) or (n_ands() > 30000)): if ((n == 1) or (n_ands() > 40000)):
return return
print 'Number of possible phases = %d'%n print 'Number of possible phases = %d'%n
abc('w %s_savetemp.aig'%f_name) abc('w %s_savetemp.aig'%f_name)
...@@ -1140,7 +1162,7 @@ def try_phase(): ...@@ -1140,7 +1162,7 @@ def try_phase():
nl = n_latches() nl = n_latches()
ni = n_pis() ni = n_pis()
no = n_pos() no = n_pos()
cost_init = (1*n_pis())+(2*n_latches())+.05*n_ands() cost_init = (1*n_pis())+(2*n_latches())+1*n_ands()
cost_min = cost_init cost_min = cost_init
cost = cost_init cost = cost_init
abc('w %s_best.aig'%f_name) abc('w %s_best.aig'%f_name)
...@@ -1158,7 +1180,7 @@ def try_phase(): ...@@ -1158,7 +1180,7 @@ def try_phase():
#print_circuit_stats() #print_circuit_stats()
abc('rw;lcorr;trm') abc('rw;lcorr;trm')
#print_circuit_stats() #print_circuit_stats()
cost = (1*n_pis())+(2*n_latches())+.05*n_ands() cost = (1*n_pis())+(2*n_latches())+1*n_ands()
if cost < cost_min: if cost < cost_min:
cost_min = cost cost_min = cost
abc('w %s_best.aig'%f_name) abc('w %s_best.aig'%f_name)
...@@ -1207,7 +1229,6 @@ def quick_simp(): ...@@ -1207,7 +1229,6 @@ def quick_simp():
abc('&get;&scl;&put;rw') abc('&get;&scl;&put;rw')
def scorr_constr(): def scorr_constr():
#return Undecided_no_reduction #temporarily disable the for the moment
"""Extracts implicit constraints and uses them in signal correspondence """Extracts implicit constraints and uses them in signal correspondence
Constraints that are found are folded back when done""" Constraints that are found are folded back when done"""
na = max(1,n_ands()) na = max(1,n_ands())
...@@ -1223,18 +1244,13 @@ def scorr_constr(): ...@@ -1223,18 +1244,13 @@ def scorr_constr():
else: else:
cmd = 'unfold' cmd = 'unfold'
abc(cmd) abc(cmd)
if ((n_ands() > na) or (n_pos() == 1)): if ((n_ands() > na) or (n_pos() == n_pos_before)):
abc('r %s_savetemp.aig'%f_name) abc('r %s_savetemp.aig'%f_name)
return Undecided_no_reduction return Undecided_no_reduction
print_circuit_stats() print_circuit_stats()
print 'Number of constraints = %d'%(n_pos() - n_pos_before) print 'Number of constraints = %d'%(n_pos() - n_pos_before)
abc('scorr -c -F %dd'%f) abc('scorr -c -F %d'%f)
if n_pos_before == 1: abc('fold')
#abc('cone -s -O 0') #don't fold constraints back in
abc('fold')
else:
abc('fold')
## abc('fold')
return Undecided_no_reduction return Undecided_no_reduction
def process_status(status): def process_status(status):
...@@ -1253,7 +1269,7 @@ def input_x_factor(): ...@@ -1253,7 +1269,7 @@ def input_x_factor():
def prove(a): def prove(a):
"""Proves all the outputs together. If ever an abstraction was done then if SAT is returned, """Proves all the outputs together. If ever an abstraction was done then if SAT is returned,
we make RESULT return "undecided". we make RESULT return "undecided".
if a = 0 we skip the first quick_verify""" If a == 1 do not run speculate"""
global x_factor,xfi,f_name global x_factor,xfi,f_name
x = time.clock() x = time.clock()
max_bmc = -1 max_bmc = -1
...@@ -1262,14 +1278,18 @@ def prove(a): ...@@ -1262,14 +1278,18 @@ def prove(a):
print_circuit_stats() print_circuit_stats()
x_factor = xfi x_factor = xfi
print 'x_factor = %f'%x_factor print 'x_factor = %f'%x_factor
print '\nRunning pre_simp' print '\n***Running pre_simp'
set_globals() set_globals()
status = pre_simp() if n_latches() > 0:
if status <= Unsat: status = pre_simp()
else:
status = check_sat()
if ((status <= Unsat) or (n_latches() == 0)):
print 'Time for proof = %f sec.'%(time.clock() - x) print 'Time for proof = %f sec.'%(time.clock() - x)
return RESULT[status] return RESULT[status]
if n_ands() == 0: if n_ands() == 0:
abc('bmc3 -T 2') #abc('bmc3 -T 2')
abc('&get;,bmc -vt=2')
if is_sat(): if is_sat():
return 'SAT' return 'SAT'
abc('trm') abc('trm')
...@@ -1277,8 +1297,9 @@ def prove(a): ...@@ -1277,8 +1297,9 @@ def prove(a):
abc('w %s_backup_%d.aig'%(initial_f_name,K)) abc('w %s_backup_%d.aig'%(initial_f_name,K))
K = K +1 K = K +1
set_globals() set_globals()
if ((n_ands() < 30000) and (a == 1) and (n_latches() < 300)): ## if ((n_ands() < 30000) and (a == 1) and (n_latches() < 300)):
print '\nRunning quick_verify' if ((n_ands() < 30000) and (n_latches() < 300)):
print '\n***Running quick_verify'
status = quick_verify(0) status = quick_verify(0)
if status <= Unsat: if status <= Unsat:
if not status == Unsat: if not status == Unsat:
...@@ -1286,10 +1307,11 @@ def prove(a): ...@@ -1286,10 +1307,11 @@ def prove(a):
print 'Time for proof = %f sec.'%(time.clock() - x) print 'Time for proof = %f sec.'%(time.clock() - x)
return RESULT[status] return RESULT[status]
if n_ands() == 0: if n_ands() == 0:
abc('bmc3 -T 2') #abc('bmc3 -T 2')
abc('&get;,bmc -vt=2')
if is_sat(): if is_sat():
return 'SAT' return 'SAT'
print'\nRunning abstract' print'\n***Running abstract'
nl_b = n_latches() nl_b = n_latches()
status = abstract() status = abstract()
abc('trm') abc('trm')
...@@ -1306,27 +1328,14 @@ def prove(a): ...@@ -1306,27 +1328,14 @@ def prove(a):
return RESULT[status] return RESULT[status]
abc('w %s_backup_%d.aig'%(initial_f_name,K)) abc('w %s_backup_%d.aig'%(initial_f_name,K))
K = K +1 K = K +1
if status == Undecided_reduction: if ((n_ands() > 20000) or (a == 1)):
print '\nRunning quick_verify' print 'Speculation skipped because either too large or already done'
status = quick_verify(1)
status = process_status(status)
if status <= Unsat:
if status < Unsat:
print 'CEX in frame %d'%cex_frame()
#print 'Time for proof = %f sec.'%(time.clock() - x)
status = final_verify_recur(K-1)
abc('trm')
write_file('final')
print 'Time for proof = %f sec.'%(time.clock() - x)
return RESULT[status]
if n_ands() > 20000:
print 'Speculation skipped because too large'
K = 2 K = 2
elif n_ands() == 0: elif n_ands() == 0:
print 'Speculation skipped because no and nodes' print 'Speculation skipped because no AND nodes'
K = 2 K = 2
else: else:
print '\nRunning speculate' print '\n***Running speculate'
status = speculate() status = speculate()
abc('trm') abc('trm')
write_file('spec') write_file('spec')
...@@ -1359,11 +1368,11 @@ def prove_g_pos(a): ...@@ -1359,11 +1368,11 @@ def prove_g_pos(a):
init_f_name = f_name init_f_name = f_name
#fast_int(1) #fast_int(1)
print 'Beginning prove_g_pos' print 'Beginning prove_g_pos'
result = prove_all_ind() prove_all_ind()
print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos() print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos()
print '\n************Trying second level prove****************\n' print '\n************Running second level prove****************\n'
try_rpm() try_rpm()
result = prove(0) result = prove(1) # 1 here means do not try speculate.
#result = prove_0_ind() #result = prove_0_ind()
if result == 'UNSAT': if result == 'UNSAT':
print 'Second prove returned UNSAT' print 'Second prove returned UNSAT'
...@@ -1372,7 +1381,7 @@ def prove_g_pos(a): ...@@ -1372,7 +1381,7 @@ def prove_g_pos(a):
print 'CEX found' print 'CEX found'
return result return result
print '\n********** Proving each output separately ************' print '\n********** Proving each output separately ************'
result = prove_all_ind() prove_all_ind()
print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos() print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos()
f_name = init_f_name f_name = init_f_name
abc('w %s_osavetemp.aig'%f_name) abc('w %s_osavetemp.aig'%f_name)
...@@ -1428,20 +1437,16 @@ def prove_g_pos(a): ...@@ -1428,20 +1437,16 @@ def prove_g_pos(a):
return result return result
def prove_pos(): def prove_pos():
"""Proves the outputs clustered by a parameter a. """
a is the disallowed increase in latch support Clusters must be contiguous
If a = 0 then outputs are proved individually. Clustering is done from last to first
Output 0 is attempted to be proved inductively using other outputs as constraints.
Proved outputs are removed if all the outputs have not been proved. Proved outputs are removed if all the outputs have not been proved.
If ever one of the proofs returns SAT, we stop and do not try any other outputs.""" If ever one of the proofs returns SAT, we stop and do not try any other outputs."""
global f_name, max_bmc,x_factor global f_name, max_bmc,x_factor
a=0
x = time.clock() x = time.clock()
#input_x_factor() #input_x_factor()
init_f_name = f_name init_f_name = f_name
#fast_int(1) #fast_int(1)
print 'Beginning prove_g_pos' print 'Beginning prove_pos'
result = prove_all_ind() prove_all_ind()
print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos() print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos()
print '\n********** Proving each output separately ************' print '\n********** Proving each output separately ************'
f_name = init_f_name f_name = init_f_name
...@@ -1450,6 +1455,7 @@ def prove_pos(): ...@@ -1450,6 +1455,7 @@ def prove_pos():
print 'Number of outputs = %d'%n print 'Number of outputs = %d'%n
#count = 0 #count = 0
pos_proved = [] pos_proved = []
pos_disproved = []
J = 0 J = 0
jnext = n-1 jnext = n-1
while jnext >= 0: while jnext >= 0:
...@@ -1458,43 +1464,36 @@ def prove_pos(): ...@@ -1458,43 +1464,36 @@ def prove_pos():
abc('r %s_osavetemp.aig'%f_name) abc('r %s_osavetemp.aig'%f_name)
#Do in reverse order #Do in reverse order
jnext_old = jnext jnext_old = jnext
if a == 0: # do not group extract(jnext,jnext)
extract(jnext,jnext) jnext = jnext -1
jnext = jnext -1 print '\nProving output %d'%(jnext_old)
else:
jnext = group(a,jnext)
if jnext_old > jnext+1:
print '\nProving outputs [%d-%d]'%(jnext + 1,jnext_old)
else:
print '\nProving output %d'%(jnext_old)
#ps()
#fast_int(1)
f_name = f_name + '_%d'%jnext_old f_name = f_name + '_%d'%jnext_old
result = prove_1() result = prove_1()
if result == 'UNSAT': if result == 'UNSAT':
if jnext_old > jnext+1: print '\n******** PROVED OUTPUT %d ******** \n\n'%(jnext_old)
print '\n******** PROVED OUTPUTS [%d-%d] ******** \n\n'%(jnext+1,jnext_old)
else:
print '\n******** PROVED OUTPUT %d ******** \n\n'%(jnext_old)
pos_proved = pos_proved + range(jnext +1,jnext_old+1) pos_proved = pos_proved + range(jnext +1,jnext_old+1)
continue continue
if result == 'SAT': if result == 'SAT':
print 'One of output in (%d to %d) is SAT'%(jnext + 1,jnext_old) print '\n******** DISPROVED OUTPUT %d ******** \n\n'%(jnext_old)
return result pos_disproved = pos_disproved + range(jnext +1,jnext_old+1)
continue
else: else:
print '\n******** UNDECIDED on OUTPUTS %d thru %d ******** \n\n'%(jnext+1,jnext_old) print '\n******** UNDECIDED on OUTPUT %d ******** \n\n'%(jnext_old)
f_name = init_f_name f_name = init_f_name
abc('r %s_osavetemp.aig'%f_name) abc('r %s_osavetemp.aig'%f_name)
if not len(pos_proved) == n: list = pos_proved + pos_disproved
print 'Eliminating %d proved outputs'%(len(pos_proved)) print 'Proved the following outputs: %s'%pos_proved
remove(pos_proved) print 'Disproved the following outputs: %s'%pos_disproved
if not len(list) == n:
print 'Eliminating %d resolved outputs'%(len(list))
remove(list)
abc('trm') abc('trm')
write_file('group') write_file('group')
result = 'UNDECIDED' result = 'UNRESOLVED'
else: else:
print 'Proved all outputs. The problem is proved UNSAT' print 'Proved or disproved all outputs. The problem is proved RESOLVED'
result = 'UNSAT' result = 'RESOLVED'
print 'Total time for prove_g_pos = %f sec.'%(time.clock() - x) print 'Total time for prove_pos = %f sec.'%(time.clock() - x)
return result return result
...@@ -1506,7 +1505,7 @@ def prove_g_pos_split(): ...@@ -1506,7 +1505,7 @@ def prove_g_pos_split():
init_f_name = f_name init_f_name = f_name
#fast_int(1) #fast_int(1)
print 'Beginning prove_g_pos_split' print 'Beginning prove_g_pos_split'
result = prove_all_ind() prove_all_ind()
print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos() print 'Number of outputs reduced to %d by induction and fast interpolation'%n_pos()
try_rpm() try_rpm()
print '\n********** Proving each output separately ************' print '\n********** Proving each output separately ************'
...@@ -1575,7 +1574,7 @@ def group(a,n): ...@@ -1575,7 +1574,7 @@ def group(a,n):
for J in range(1,n+1): for J in range(1,n+1):
abc('r %s_osavetemp.aig'%f_name) abc('r %s_osavetemp.aig'%f_name)
j = n-J j = n-J
#print 'trying %d to %d'%(j,n) #print 'Running %d to %d'%(j,n)
extract(j,n) extract(j,n)
#print 'n_latches = %d'%n_latches() #print 'n_latches = %d'%n_latches()
#if n_latches() >= nli + (nlt - nli)/2: #if n_latches() >= nli + (nlt - nli)/2:
...@@ -1613,10 +1612,10 @@ def prove_0_ind(): ...@@ -1613,10 +1612,10 @@ def prove_0_ind():
return status return status
def remove(list): def remove(list):
"""Removes outputs in list as well as easy output proved by fast interpolation""" """Removes outputs in list"""
zero(list) zero(list)
abc('scl') abc('&get;&trim;&put')
fast_int(1) #fast_int(1)
def zero(list): def zero(list):
"""Zeros out POs in list""" """Zeros out POs in list"""
...@@ -1640,7 +1639,14 @@ def super_prove(): ...@@ -1640,7 +1639,14 @@ def super_prove():
input_x_factor() input_x_factor()
max_bmc = -1 max_bmc = -1
x = time.clock() x = time.clock()
print "Trying BMC for 2 sec."
abc("&get; ,bmc -vt=2")
if is_sat():
print 'Total time taken by super_prove = %f sec.'%(time.clock() - x)
return 'SAT'
result = prove(0) result = prove(0)
if ((result[:3] == 'UND') and (n_latches() == 0)):
return result
k = 1 k = 1
print result print result
if not result[:3] == 'UND': if not result[:3] == 'UND':
...@@ -1662,60 +1668,64 @@ def super_prove(): ...@@ -1662,60 +1668,64 @@ def super_prove():
return result return result
def reachm(t): def reachm(t):
x = time.clock()
run_command('&get;&reach -vcs -T %d;&put'%t) run_command('&get;&reach -vcs -T %d;&put'%t)
print 'Time = %f'%(time.clock() - x)
def reachx(t):
x = time.clock()
run_command('reachx -t %d'%t)
print 'Time = %f'%(time.clock() - x)
def BMC_VER_result(n): def BMC_VER_result(n):
global init_initial_f_name global init_initial_f_name
#print init_initial_f_name #print init_initial_f_name
if n == 0: xt = time.clock()
print '\nTrying proof on initial simplified and abstracted circuit\n'
abc('r %s_smp.abs.aig'%init_initial_f_name)
ps()
x = time.clock()
result = 5 result = 5
N = 0
T = 150 T = 150
if (n_pis()+n_latches() < 250): if n == 0:
print ' Trying deep Reachability' abc('r %s_smp.aig'%init_initial_f_name)
run_command('reachx -t 150') print '\n***Running proof on initial simplified circuit\n',
#run_command('&get;&reach -vcs -T %d'%T) ps()
result = get_status() else:
if result == Unsat: print '\n***Running proof on final unproved circuit'
return 'UNSAT' ps()
if ((result < Unsat) and (n == 0)): print ' Running PDR for %d sec'%T
N = 1 abc('&get;,pdr -vt=%d'%(T*.8))
if ((result >= Unsat) and (N == 0)): result = get_status()
print 'Trying deep interpolation' if result == Unsat:
run_command('int -v -F 30000 -C 1000000 -T %d'%T) return 'UNSAT'
result = get_status() if result > Unsat: #still undefined
if result == Unsat: if (n_pis()+n_latches() < 250):
return 'UNSAT' print ' Running Reachability for 150 sec.'
## try_split() abc('reachx -t 150')
## if n_pos() > 1: #run_command('&get;&reach -vcs -T %d'%T)
## result = prove_g_pos_split() result = get_status()
## if result[:5] == 'UNSAT': if result == Unsat:
## return result return 'UNSAT'
#ps() if ((result > Unsat) and n ==1):
abc('r %s_smp.aig'%init_initial_f_name) print ' Running interpolation for %f sec.'%T
abc(',imc -vt=%f'%T)
result = get_status()
if result == Unsat:
return 'UNSAT'
# if n=1 we are trying to prove result on abstracted circuit. If still undefined, then probably does
# not make sense to try pdr, reach, int on original simplified circuit, only BMC here.
if n == 1:
abc('r %s_smp.aig'%init_initial_f_name) #check if the initial circuit was SAT
#print 'Reading %s_smp'%init_initial_f_name,
#run_command('bmc3 -v -T %d -F 200000 -C 1000000'%T)
print '***Running BMC on initial simplified circuit'
ps() ps()
if N == 1: print '\n'
print '\nTrying deep interpolation on initial simplified circuit\n' abc('&get;,bmc -vt=%f'%T)
run_command('int -v -F 30000 -C 1000000 -T %d'%T)
result = get_status()
if result == Unsat:
return 'UNSAT'
if result < Unsat:
return 'SAT'
print '\nTrying deep BMC on initial simplified circuit\n'
run_command('bmc3 -v -T %d -F 200000 -C 1000000'%T)
result = get_status() result = get_status()
if result < Unsat: if result < Unsat:
result = 'SAT' result = 'SAT'
print ' CEX found in frame %d'%cex_frame() print ' CEX found in frame %d'%cex_frame()
else: else:
result = 'UNDECIDED' result = 'UNDECIDED'
print 'Additional time taken by BMC/ability = %f sec.'%(time.clock() - x) print 'Additional time taken by BMC/PDR/Reach = %f sec.'%(time.clock() - xt)
return result return result
def try_split(): def try_split():
...@@ -1733,12 +1743,74 @@ def time_diff(): ...@@ -1733,12 +1743,74 @@ def time_diff():
last_time = new_time last_time = new_time
result = 'Lapsed time = %.2f sec.'%diff result = 'Lapsed time = %.2f sec.'%diff
return result return result
def prove_all_ind(): def prove_all_ind():
"""Tries to prove output k by induction, using other outputs as constraints. If ever an output is proved
it is set to 0 so it can't be used in proving another output to break circularity.
Finally all zero'ed ooutputs are removed. """
N = n_pos()
remove_0_pos()
print '0 valued output removal changed POs from %d to %d'%(N,n_pos())
abc('w %s_osavetemp.aig'%f_name)
list = range(n_pos())
for j in list:
#abc('r %s_osavetemp.aig'%f_name)
abc('swappos -N %d'%j)
remove_0_pos() #may not have to do this if constr works well with 0'ed outputs
abc('constr -N %d'%(n_pos()-1))
abc('fold')
n = max(1,n_ands())
f = max(1,min(40000/n,16))
f = int(f)
abc('ind -u -C 10000 -F %d'%f)
status = get_status()
abc('r %s_osavetemp.aig'%f_name)
if status == Unsat:
print '+',
abc('zeropo -N %d'%j)
abc('w %s_osavetemp.aig'%f_name) #if changed, store it permanently
print '%d'%j,
remove_0_pos()
print '\nThe number of POs reduced from %d to %d'%(N,n_pos())
#return status
def prove_all_pdr(t):
"""Tries to prove output k by PDR. If ever an output is proved
it is set to 0. Finally all zero'ed ooutputs are removed. """
N = n_pos()
remove_0_pos()
print '0 valued output removal changed POs from %d to %d'%(N,n_pos())
abc('w %s_osavetemp.aig'%f_name)
list = range(n_pos())
for j in list:
#abc('r %s_osavetemp.aig'%f_name)
abc('cone -O %d -s'%j)
abc('scl')
abc('&get;,pdr -vt=%d'%t)
status = get_status()
abc('r %s_osavetemp.aig'%f_name)
if status == Unsat:
print '+',
abc('zeropo -N %d'%j)
abc('w %s_osavetemp.aig'%f_name) #if changed, store it permanently
print '%d'%j,
remove_0_pos()
print '\nThe number of POs reduced from %d to %d'%(N,n_pos())
#return status
def remove_0_pos():
abc('&get; &trim; &put')
def prove_all_ind2():
"""Tries to prove output k by induction, using outputs > k as constraints. Removes proved outputs from POs.""" """Tries to prove output k by induction, using outputs > k as constraints. Removes proved outputs from POs."""
abc('w %s_osavetemp.aig'%f_name) abc('w %s_osavetemp.aig'%f_name)
plist = [] plist = []
for j in range(n_pos()): list = range(n_pos())
## if r == 1:
## list.reverse()
for j in list:
abc('r %s_osavetemp.aig'%f_name) abc('r %s_osavetemp.aig'%f_name)
extract(j,n_pos()) extract(j,n_pos())
abc('constr -N %d'%(n_pos()-1)) abc('constr -N %d'%(n_pos()-1))
...@@ -1750,12 +1822,50 @@ def prove_all_ind(): ...@@ -1750,12 +1822,50 @@ def prove_all_ind():
status = get_status() status = get_status()
if status == Unsat: if status == Unsat:
plist = plist + [j] plist = plist + [j]
print '-',
## else:
## status = pdr(1)
## if status == Unsat:
## print '+',
## plist = plist + [j]
print '%d'%j, print '%d'%j,
print '\nOutputs proved inductively = ', print '\nOutputs proved = ',
print plist print plist
abc('r %s_osavetemp.aig'%f_name) abc('r %s_osavetemp.aig'%f_name)
remove(plist) #remove the outputs proved remove(plist) #remove the outputs proved
return status ## #the following did not work because abc command constr, allows only last set of outputs to be constraints
## abc('w %s_osavetemp.aig'%f_name)
## plist = []
## list = range(n_pos())
## list.reverse()
## for j in list:
## abc('r %s_osavetemp.aig'%f_name)
## extract(j,n_pos())
## abc('constr -N %d'%(n_pos()-1))
## abc('fold')
## n = max(1,n_ands())
## f = max(1,min(40000/n,16))
## f = int(f)
## abc('ind -u -C 10000 -F %d'%f)
## status = get_status()
## if status == Unsat:
## plist = plist + [j]
## print '-',
#### else:
#### status = pdr(1)
#### if status == Unsat:
#### print '+',
#### plist = plist + [j]
## print '%d'%j,
## print '\nOutputs proved = ',
## print plist.reverse
## abc('r %s_osavetemp.aig'%f_name)
## remove(plist) #remove the outputs proved
## return status
def pdr(t):
abc('&get; ,pdr -vt=%f'%t)
result = get_status()
def split(n): def split(n):
abc('orpos;&get') abc('orpos;&get')
...@@ -1787,10 +1897,10 @@ def prove_1(): ...@@ -1787,10 +1897,10 @@ def prove_1():
print_circuit_stats() print_circuit_stats()
x_factor = xfi x_factor = xfi
print 'x_factor = %f'%x_factor print 'x_factor = %f'%x_factor
print '\nRunning pre_simp' print '\n***Running pre_simp'
set_globals() set_globals()
status = pre_simp() status = pre_simp()
if status <= Unsat: if ((status <= Unsat) or (n_latches == 0)):
print 'Time for proof = %f sec.'%(time.clock() - x) print 'Time for proof = %f sec.'%(time.clock() - x)
return RESULT[status] return RESULT[status]
abc('trm') abc('trm')
...@@ -1799,14 +1909,14 @@ def prove_1(): ...@@ -1799,14 +1909,14 @@ def prove_1():
K = K +1 K = K +1
set_globals() set_globals()
if ((n_ands() < 30000) and (a == 1) and (n_latches() < 300)): if ((n_ands() < 30000) and (a == 1) and (n_latches() < 300)):
print '\nRunning quick_verify' print '\n***Running quick_verify'
status = quick_verify(0) status = quick_verify(0)
if status <= Unsat: if status <= Unsat:
if not status == Unsat: if not status == Unsat:
print 'CEX in frame %d'%cex_frame() print 'CEX in frame %d'%cex_frame()
print 'Time for proof = %f sec.'%(time.clock() - x) print 'Time for proof = %f sec.'%(time.clock() - x)
return RESULT[status] return RESULT[status]
print'\nRunning abstract' print'\n***Running abstract'
nl_b = n_latches() nl_b = n_latches()
status = abstract() status = abstract()
abc('trm') abc('trm')
...@@ -1851,5 +1961,47 @@ def qprove(): ...@@ -1851,5 +1961,47 @@ def qprove():
print 'Time for proof = %f sec.'%(time.clock() - x) print 'Time for proof = %f sec.'%(time.clock() - x)
return result return result
def pre_reduce():
x = time.clock()
pre_simp()
write_file('smp')
abstract()
write_file('abs')
print 'Time = %f'%(time.clock() - x)
#PARALLEL FUNCTIONS
""" funcs should look like
funcs = [defer(abc)('&get;,bmc -vt=50;&put'),defer(super_prove)()]
After this is executed funcs becomes a special list of lambda functions
which are given to abc_split_all to be executed as in fork below.
It has been set up so that each of the functions works on the current aig and
possibly transforms it. The new aig and status is always read into the master when done
"""
def fork(funcs):
""" runs funcs in parallel"""
for i,res in pyabc_split.abc_split_all(funcs):
status = prob_status()
if not status == -1:
print i,status
ps()
break
else:
print i,status
ps()
continue
return status
def handler_s(res):
""" This serial handler returns True if the problem is solved by the first returning function,
in which case, the problem is replaced by the new aig and status.
"""
if not res == -1:
#replace_prob()
print ('UNSAT','SAT')[res]
return True
else:
return False
import os
##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')
#IBM directories
# directories = ['ibmhard']
ibmhard = (33,34,36,37,28,40,42,44,48,5,49,50,52,53,58,59,6,64,66,67,68,\
69,70,71,72,73,74,75,76,78,79,80,81,82,83,84,86,9,87,89,90,0,10,\
11,12,14,15,16,2,19,20,29,31,32)
#directories = ['IBM_converted']
#ibm_convert = (3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,\
# 27,28,29,30,31,32,33,34,35,36,37,38,39,40,41)
#IBM_converted = range(42)[3:]
#the smaller files in ascending order
#IBM_converted = (26,38,21,15,22,23,20,27,16,19,24,28,18,9,8,7,6,25,17,3,4)
#the larger file in order (skipping 39)
#IBM_converted = (39,5,40,41,13,12,10,14,11,31,33,36,29,34,35,37,30)
IBM_converted = (5,40,41,13,12,10,14,11,31,33,36,29,34,35,37,30)
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 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 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()
for j in range(len(dir)):
name = dir[j][:-4]
if not s in name:
continue
print '%s '%name,
abc('r %s.aig'%name)
ps()
return dir
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 (('_smp' in name) or ('_save' in name) or ('_backup' in name) or ('_osave' in name)
or ('_best' in name) or ('_gsrm' in name) or ('gore' in name) or
('_bip' in name) or ('sm0' in name) or ('gabs' in name)
or ('temp' in name) or ('__' in name) or ('greg' in name) or ('tf2' in name)
or ('gsrm' in name) or ('_rpm' in name ) or ('gsyn' in name) or ('beforerpm' in name)
or ('afterrpm' in name) or ('initabs' in name) or ('.status' in name) or ('_init' in name)
or ('_osave' in name) or ('tt_' in name) or ('_before' in name) or ('_after' in name)
or ('_and' in name) or ('_final' in name) or ('_spec' in name) or ('temp.a' in name) or ('_sync' in 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 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()
import sys
# You can use 'from pyabc import *' and then not need the pyabc. prefix everywhere
import os import os
import pyabc import pyabc
import abc_common import par
import tempfile import tempfile
import shutil import shutil
import redirect import redirect
import optparse
# 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 command that calls prove(1) and returns success
def prove_cmd(args):
result = abc_common.prove(1)
print result
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
# Keep the fourth argument 0, or consult with Alan
pyabc.add_abc_command(prove_cmd, "ZPython", "/prove", 0)
def read_cmd(args): def read_cmd(args):
if len(args)==2: if len(args)==2:
abc_common.read_file_quiet(args[1]) par.read_file_quiet(args[1])
else: else:
abc_common.read_file() par.read_file()
return 0 return 0
pyabc.add_abc_command(read_cmd, "ZPython", "/rf", 0) pyabc.add_abc_command(read_cmd, "ZPython", "/rf", 0)
...@@ -109,75 +90,67 @@ def print_aiger_result(args): ...@@ -109,75 +90,67 @@ def print_aiger_result(args):
pyabc.add_abc_command(print_aiger_result, "ZPython", "/print_aiger_result", 0) pyabc.add_abc_command(print_aiger_result, "ZPython", "/print_aiger_result", 0)
def super_prove_aiger_cmd(args): def proof_command_wrapper(prooffunc, category_name, command_name, change):
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 def wrapper(argv):
usage = "usage: %prog [options] <aig_file>"
pyabc.add_abc_command(super_prove_aiger_cmd, "ZPython", "/super_prove_aiger", 0) parser = optparse.OptionParser(usage, prog=command_name)
def prove_one_by_one_cmd(args):
noisy = len(args)==2 and args[1]=='-n' 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")
# switch to a temporary directory options, args = parser.parse_args(argv)
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: if len(args) != 2:
pyabc.run_command('/pushredirect') print args
parser.print_usage()
# replace the nework with the cone of the current PO return 0
pyabc.run_command( 'cone -O %d -s'%po )
aig_filename = os.path.abspath(args[1])
# run super_prove if not options.noisy:
pyabc.run_command('/pushredirect')
if not options.current_dir:
pyabc.run_command('/pushdtemp')
try: try:
result = abc_common.super_prove() 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: except:
result = 'UNKNOWN' result = None
if not noisy: if not options.current_dir:
pyabc.run_command('/popredirect') pyabc.run_command('/popdtemp')
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 if not options.noisy:
pyabc.run_command('r original_aig_file.aig') pyabc.run_command('/popredirect')
# go back to the original directory if result=="SAT":
pyabc.run_command('/popdtemp') print 1
elif result=="UNSAT":
print 0
else:
print 2
return 0 return 0
pyabc.add_abc_command(prove_one_by_one_cmd, "ZPython", "/prove_one_by_one", 0) pyabc.add_abc_command(wrapper, category_name, command_name, change)
proof_command_wrapper(par.super_prove, 'HWMCC11', '/super_prove_aiger', 0)
proof_command_wrapper(par.simple_prove, 'HWMCC11', '/simple_prove_aiger', 0)
proof_command_wrapper(par.simple_bip, 'HWMCC11', '/simple_bip_aiger', 0)
This source diff could not be displayed because it is too large. You can view the blob instead.
#!/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 -c "/simple_bip_aiger $*"
#!/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 -c "/simple_prove_aiger $*"
...@@ -10,6 +10,5 @@ abc_root() ...@@ -10,6 +10,5 @@ abc_root()
abc_dir=$(abc_root "$0") abc_dir=$(abc_root "$0")
bin_dir="${abc_dir}"/bin bin_dir="${abc_dir}"/bin
aig_file="$1"
exec ${bin_dir}/abc -c "/rf ${aig_file} ; /super_prove_aiger" exec ${bin_dir}/abc -c "/super_prove_aiger $*"
...@@ -454,7 +454,7 @@ FILE * CmdFileOpen( Abc_Frame_t * pAbc, char *sFileName, char *sMode, char **pFi ...@@ -454,7 +454,7 @@ FILE * CmdFileOpen( Abc_Frame_t * pAbc, char *sFileName, char *sMode, char **pFi
else else
{ {
// print the path/name of the resource file 'abc.rc' that is being loaded // print the path/name of the resource file 'abc.rc' that is being loaded
if ( strlen(sRealName) >= 6 && strcmp( sRealName + strlen(sRealName) - 6, "abc.rc" ) == 0 ) if ( !silent && strlen(sRealName) >= 6 && strcmp( sRealName + strlen(sRealName) - 6, "abc.rc" ) == 0 )
printf( "Loading resource file \"%s\".\n", sRealName ); printf( "Loading resource file \"%s\".\n", sRealName );
} }
} }
......
...@@ -34,7 +34,7 @@ import optparse ...@@ -34,7 +34,7 @@ import optparse
def pytest3_cmd(args): def pytest3_cmd(args):
usage = "usage: %prog [options]" usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage) parser = optparse.OptionParser(usage, prog="pytest3")
parser.add_option("-c", "--cmd", dest="cmd", help="command to ask help for") 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") parser.add_option("-v", "--version", action="store_true", dest="version", help="display Python Version")
......
...@@ -57,7 +57,7 @@ pyabc.tgz : $(PROG) $(ABC_PYTHON_SRC:_wrap.c=.py) $(ABC_PYTHON_FILES_PREFIX)/abc ...@@ -57,7 +57,7 @@ pyabc.tgz : $(PROG) $(ABC_PYTHON_SRC:_wrap.c=.py) $(ABC_PYTHON_FILES_PREFIX)/abc
$(ABC_PYTHON) $(ABC_PYTHON_FILES_PREFIX)/package.py \ $(ABC_PYTHON) $(ABC_PYTHON_FILES_PREFIX)/package.py \
--abc=$(PROG) \ --abc=$(PROG) \
--abc_sh=$(ABC_PYTHON_FILES_PREFIX)/abc.sh \ --abc_sh=$(ABC_PYTHON_FILES_PREFIX)/abc.sh \
--pyabc=$(ABC_PYTHON_SRC:_wrap.c=.py) \ --pyabc=$(ABC_PYTHON_FILES_PREFIX) \
--out=$@ \ --out=$@ \
$(ABC_PYTHON_OPTIONS) $(ABC_PYTHON_OPTIONS)
...@@ -66,8 +66,6 @@ PYABC_INSTALL_TARGET := $(PYABC_INSTALL_TARGET) ...@@ -66,8 +66,6 @@ PYABC_INSTALL_TARGET := $(PYABC_INSTALL_TARGET)
PYABC_INSTALL_DIR ?= /hd/common/pyabc/builds/pyabc_builds/ PYABC_INSTALL_DIR ?= /hd/common/pyabc/builds/pyabc_builds/
.PHONY: zzz
pyabc_install_target: pyabc_extension_bdist pyabc_install_target: pyabc_extension_bdist
mkdir -p "$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)" mkdir -p "$(PYABC_INSTALL_DIR)/$(PYABC_INSTALL_TARGET)"
tar \ tar \
......
...@@ -70,7 +70,10 @@ def package(abc_exe, abc_sh, pyabc, ofname, scripts_dir, use_sys): ...@@ -70,7 +70,10 @@ def package(abc_exe, abc_sh, pyabc, ofname, scripts_dir, use_sys):
add_file( tf, fullname, os.path.join("pyabc/scripts", fn), 0666, mtime) add_file( tf, fullname, os.path.join("pyabc/scripts", fn), 0666, mtime)
add_dir(tf, "pyabc/lib", mtime) add_dir(tf, "pyabc/lib", mtime)
add_file( tf, pyabc, "pyabc/lib/pyabc.py", 0666, mtime)
for entry in os.listdir(pyabc):
if entry.endswith('.py'):
add_file( tf, os.path.join(pyabc, entry), os.path.join("pyabc/lib", entry), 0666, mtime)
if not use_sys: if not use_sys:
# ZIP standard library # ZIP standard library
......
...@@ -262,8 +262,6 @@ void pyabc_internal_set_command_callback( PyObject* callback ) ...@@ -262,8 +262,6 @@ void pyabc_internal_set_command_callback( PyObject* callback )
pyabc_internal_python_command_callback = callback; pyabc_internal_python_command_callback = callback;
} }
PyThreadState *_save;
static int pyabc_internal_abc_command_callback(Abc_Frame_t * pAbc, int argc, char ** argv) static int pyabc_internal_abc_command_callback(Abc_Frame_t * pAbc, int argc, char ** argv)
{ {
int i; int i;
...@@ -271,13 +269,15 @@ static int pyabc_internal_abc_command_callback(Abc_Frame_t * pAbc, int argc, cha ...@@ -271,13 +269,15 @@ static int pyabc_internal_abc_command_callback(Abc_Frame_t * pAbc, int argc, cha
PyObject* args; PyObject* args;
PyObject* arglist; PyObject* arglist;
PyObject* res; PyObject* res;
PyGILState_STATE gstate;
long lres; long lres;
if ( !pyabc_internal_python_command_callback ) if ( !pyabc_internal_python_command_callback )
return 0; return 0;
Py_BLOCK_THREADS gstate = PyGILState_Ensure();
args = PyList_New(argc); args = PyList_New(argc);
...@@ -292,14 +292,14 @@ static int pyabc_internal_abc_command_callback(Abc_Frame_t * pAbc, int argc, cha ...@@ -292,14 +292,14 @@ static int pyabc_internal_abc_command_callback(Abc_Frame_t * pAbc, int argc, cha
if ( !res ) if ( !res )
{ {
Py_UNBLOCK_THREADS PyGILState_Release(gstate);
return -1; return -1;
} }
lres = PyInt_AsLong(res); lres = PyInt_AsLong(res);
Py_DECREF(res); Py_DECREF(res);
Py_UNBLOCK_THREADS PyGILState_Release(gstate);
return lres; return lres;
} }
...@@ -309,11 +309,11 @@ int run_command(char* cmd) ...@@ -309,11 +309,11 @@ int run_command(char* cmd)
Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame(); Abc_Frame_t* pAbc = Abc_FrameGetGlobalFrame();
int rc; int rc;
Py_UNBLOCK_THREADS Py_BEGIN_ALLOW_THREADS
rc = Cmd_CommandExecute(pAbc, cmd); rc = Cmd_CommandExecute(pAbc, cmd);
Py_BLOCK_THREADS Py_END_ALLOW_THREADS
return rc; return rc;
} }
...@@ -401,13 +401,15 @@ int Util_SignalSystem(const char* cmd) ...@@ -401,13 +401,15 @@ int Util_SignalSystem(const char* cmd)
{ {
PyObject* arglist; PyObject* arglist;
PyObject* res; PyObject* res;
PyGILState_STATE gstate;
long lres; long lres;
if ( !pyabc_internal_system_callback ) if ( !pyabc_internal_system_callback )
return -1; return -1;
Py_BLOCK_THREADS gstate = PyGILState_Ensure();
arglist = Py_BuildValue("(O)", PyString_FromString(cmd)); arglist = Py_BuildValue("(O)", PyString_FromString(cmd));
Py_INCREF(arglist); Py_INCREF(arglist);
...@@ -417,14 +419,14 @@ int Util_SignalSystem(const char* cmd) ...@@ -417,14 +419,14 @@ int Util_SignalSystem(const char* cmd)
if ( !res ) if ( !res )
{ {
Py_UNBLOCK_THREADS PyGILState_Release(gstate);
return -1; return -1;
} }
lres = PyInt_AsLong(res); lres = PyInt_AsLong(res);
Py_DECREF(res); Py_DECREF(res);
Py_UNBLOCK_THREADS PyGILState_Release(gstate);
return lres; return lres;
} }
...@@ -437,12 +439,14 @@ int Util_SignalTmpFile(const char* prefix, const char* suffix, char** out_name) ...@@ -437,12 +439,14 @@ int Util_SignalTmpFile(const char* prefix, const char* suffix, char** out_name)
PyObject* arglist; PyObject* arglist;
PyObject* res; PyObject* res;
PyGILState_STATE gstate;
*out_name = NULL; *out_name = NULL;
if ( !pyabc_internal_tmpfile_callback ) if ( !pyabc_internal_tmpfile_callback )
return 0; return 0;
Py_BLOCK_THREADS gstate = PyGILState_Ensure();
arglist = Py_BuildValue("(ss)", prefix, suffix); arglist = Py_BuildValue("(ss)", prefix, suffix);
Py_INCREF(arglist); Py_INCREF(arglist);
...@@ -452,7 +456,7 @@ int Util_SignalTmpFile(const char* prefix, const char* suffix, char** out_name) ...@@ -452,7 +456,7 @@ int Util_SignalTmpFile(const char* prefix, const char* suffix, char** out_name)
if ( !res ) if ( !res )
{ {
Py_UNBLOCK_THREADS PyGILState_Release(gstate);
return -1; return -1;
} }
...@@ -463,7 +467,7 @@ int Util_SignalTmpFile(const char* prefix, const char* suffix, char** out_name) ...@@ -463,7 +467,7 @@ int Util_SignalTmpFile(const char* prefix, const char* suffix, char** out_name)
Py_DECREF(res); Py_DECREF(res);
Py_UNBLOCK_THREADS PyGILState_Release(gstate);
return open(*out_name, O_WRONLY); return open(*out_name, O_WRONLY);
} }
...@@ -472,11 +476,13 @@ void Util_SignalTmpFileRemove(const char* fname, int fLeave) ...@@ -472,11 +476,13 @@ void Util_SignalTmpFileRemove(const char* fname, int fLeave)
{ {
PyObject* arglist; PyObject* arglist;
PyObject* res; PyObject* res;
PyGILState_STATE gstate;
if ( !pyabc_internal_tmpfile_remove_callback ) if ( !pyabc_internal_tmpfile_remove_callback )
return; return;
Py_BLOCK_THREADS gstate = PyGILState_Ensure();
arglist = Py_BuildValue("(si)", fname, fLeave); arglist = Py_BuildValue("(si)", fname, fLeave);
Py_INCREF(arglist); Py_INCREF(arglist);
...@@ -485,7 +491,7 @@ void Util_SignalTmpFileRemove(const char* fname, int fLeave) ...@@ -485,7 +491,7 @@ void Util_SignalTmpFileRemove(const char* fname, int fLeave)
Py_DECREF(arglist); Py_DECREF(arglist);
Py_XDECREF(res); Py_XDECREF(res);
Py_UNBLOCK_THREADS PyGILState_Release(gstate);
} }
void pyabc_internal_set_util_callbacks( PyObject* system_callback, PyObject* tmpfile_callback, PyObject* tmpfile_remove_callback ) void pyabc_internal_set_util_callbacks( PyObject* system_callback, PyObject* tmpfile_callback, PyObject* tmpfile_remove_callback )
...@@ -607,18 +613,18 @@ class _Cex(object): ...@@ -607,18 +613,18 @@ class _Cex(object):
return _cex_get_frame(self.pCex) return _cex_get_frame(self.pCex)
def cex_get_vector(): def cex_get_vector():
res = [] res = []
for i in xrange(_cex_get_vec_len()): for i in xrange(_cex_get_vec_len()):
cex = _cex_get_vec(i) cex = _cex_get_vec(i)
if cex is None: if cex is None:
res.append(None) res.append(None)
else: else:
res.append(_Cex(cex)) res.append(_Cex(cex))
return res return res
def cex_get(): def cex_get():
...@@ -1045,7 +1051,7 @@ def cmd_python(cmd_args): ...@@ -1045,7 +1051,7 @@ def cmd_python(cmd_args):
usage = "usage: %prog [options] <Python files>" usage = "usage: %prog [options] <Python files>"
parser = optparse.OptionParser(usage) parser = optparse.OptionParser(usage, prog="python")
parser.add_option("-c", "--cmd", dest="cmd", help="Execute Python command directly") parser.add_option("-c", "--cmd", dest="cmd", help="Execute Python command directly")
parser.add_option("-v", "--version", action="store_true", dest="version", help="Display Python Version") parser.add_option("-v", "--version", action="store_true", dest="version", help="Display Python Version")
......
...@@ -43,18 +43,6 @@ def popen_and_wait_with_timeout(timeout,cmd, *args, **kwargs): ...@@ -43,18 +43,6 @@ def popen_and_wait_with_timeout(timeout,cmd, *args, **kwargs):
return -1 return -1
@contextmanager @contextmanager
def replace_sys_argv(argv):
if 'argv' in sys.__dict__:
old_argv = sys.argv
sys.argv = argv
yield
sys.argv = old_argv
else:
sys.argv = argv
yield
del sys.argv
@contextmanager
def temp_file_name(suffix=""): def temp_file_name(suffix=""):
file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix) file = tempfile.NamedTemporaryFile(delete=False, suffix=suffix)
name = file.name name = file.name
...@@ -105,13 +93,12 @@ def run_reachx_cmd(effort, timeout): ...@@ -105,13 +93,12 @@ def run_reachx_cmd(effort, timeout):
def reachx_cmd(argv): def reachx_cmd(argv):
usage = "usage: %prog [options]" usage = "usage: %prog [options]"
parser = optparse.OptionParser(usage) 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("-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]") parser.add_option("-t", "--timeout", dest="timeout", type=int, default=0, help="timeout in seconds [default=0, unlimited]")
with replace_sys_argv(argv): options, args = parser.parse_args(argv)
options, args = parser.parse_args()
rc = run_reachx_cmd(options.effort, options.timeout) rc = run_reachx_cmd(options.effort, options.timeout)
print "%s command: jabc returned: %d"%(argv[0], rc) print "%s command: jabc returned: %d"%(argv[0], rc)
......
...@@ -63,5 +63,5 @@ setup( ...@@ -63,5 +63,5 @@ setup(
name='pyabc', name='pyabc',
version='1.0', version='1.0',
ext_modules=[ext], ext_modules=[ext],
py_modules=['pyabc','getch','pyabc_split','redirect'] py_modules=['pyabc','getch','pyabc_split','redirect', 'reachx_cmd']
) )
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment