-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpar.py
14312 lines (13392 loc) · 469 KB
/
par.py
1
2
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from pyabc import *
import pyabc_split
import redirect
import sys
import os
import time
import math
import filecmp
import random
import operator
import pyaig
### this will set up things to simulate the 4 core hwmcc'15 competition.
##import affinity
##affinity.sched_setaffinity(os.getpid(), [0, 2, 4, 6])
try:
import regression
except:
pass
global G_C,G_T,latches_before_abs,latches_before_pba,n_pos_before,x_factor,methods,last_winner
global last_cex,JV,JP, cex_list,max_bmc, last_cx, pord_on, trim_allowed, temp_dec, abs_ratio, ifbip
global if_no_bip, gabs, gla, sec_options,last_gasp_time, abs_ref_time, bmcs1, total_spec_refine_time
global last_gap
"""
The functions that are currently available from module _abc are:
int n_ands();
int n_pis();
int n_pos();
int n_latches();
int n_bmc_frames();
int prob_status(); 1 = unsat, 0 = sat, -1 = unsolved
int cex_get()
int cex_put()
int run_commandhar* cmd);
int n_nodes();
int n_levels();
bool has_comb_model();
bool has_seq_model();
bool is_true_cex();
bool is_valid_cex();
return 1 if the number of PIs in the current network and in the current counter-example are equal
int n_cex_pis();
return the number of PIs in the current counter-example
int n_cex_regs();
return the number of flops in the current counter-example
int cex_po();
returns the zero-based output PO number that is SAT by cex
int cex_frame();
return the zero-based frame number where the outputs is SAT
The last four APIs return -1, if the counter-example is not defined.
"""
#global variables
#________________________________________________
stackno_gabs = stackno_gore = stackno_greg= 0
STATUS_UNKNOWN = -1
STATUS_SAT = 0
STATUS_UNSAT = 1
RESULT = ('SAT', 'SAT', 'UNSAT', 'UNDECIDED', 'UNDECIDED', 'ERROR')
Sat = Sat_reg = 0
Sat_true = 1
Unsat = 2
Undecided = Undecided_reduction = 3
Undecided_no_reduction = 4
Error = 5
Restart = 6
xfi = x_factor = 1 #set this to higher for larger problems or if you want to try harder during abstraction
max_bmc = -1
last_time = 0
j_last = 0
seed = 113
init_simp = 1
temp_dec = True
ifpord1 = 1
K_backup = init_time = 0
last_verify_time = 20
last_cex = last_winner = 'None'
last_cx = 0
trim_allowed = True
pord_on = False
sec_sw = False
sec_options = ''
pairs = cex_list = []
TERM = 'USL'
##last_gasp_time = 10000 -- controls BMC_VER_result time limit
##last_gasp_time = 500
last_gasp_time = 1500 #set to conform to hwmcc15 for 1 hours
use_pms = True
#gabs = False #use the gate refinement method after vta
#abs_time = 100
####################################
#default abstraction methods
gabs = False #False = use gla refinement, True = use reg refinement.
gla = True #use gla_abs instead of vta_abs
##abs_time = 10000 #number of sec before initial abstraction terminates.
abs_time = 150
abs_time = 5000
abs_time = 500
abs_time = 200 #changed for hwmcc15
abs_time = 1000 #changed for hwmcc17
abs_ref_time = 50 #number of sec. allowed for abstraction refinement.
##total_spec_refine_time = 150
total_spec_refine_time = 200 # changed for hwmcc15
ifbip = 0 # sets the abtraction method to vta or gla, If = 1 then uses ,abs
if_no_bip = False #True sets it up so it can't use bip and reachx commands.
abs_ratio = .6 #this controls when abstraction is too big and gives up
abs_ratio = .80
#####################################
############## No bip Settings ########################
##abs_time = 500 #number of sec before initial abstraction terminates.
##abs_ref_time = 1000 #number of sec. allowed for abstraction refinement.
##if_no_bip = True #True sets it up so it can't use bip and reachx commands.
#######################################
def abstr_a(t1=200,t2=200,absr=0):
global abs_time, abs_ref_time, abs_ratio
if not absr == 0:
abs_ratio_old = abs_ratio
abs_ratio = absr
abs_time = t1
abs_ref_time = t2
abstracta(False)
if not absr == 0:
abs_ratio = abs_ratio_old
t_init = 2 #initial time for poor man's concurrency.
def set_global(s=''):
global G_C,G_T,latches_before_abs,latches_before_pba,n_pos_before,x_factor,methods,last_winner
global last_cex,JV,JP, cex_list,max_bmc, last_cx, pord_on, trim_allowed, temp_dec, abs_ratio, ifbip
global if_no_bip, gabs, gla, sec_options,last_gasp_time,abs_ref_time, abs_time,use_pms, engines
exec(s)
methods = ['PDR', 'INTRP', 'BMCe', 'SIM', 'REACHX',
'PRE_SIMP', 'simple', 'PDRM', 'REACHM', 'BMC3','Min_Retime',
'For_Retime','REACHP','REACHN','PDR_sd','prove_part_2',
'prove_part_3','verify','sleep','PDRM_sd','prove_part_1',
'run_parallel','INTRPb', 'INTRPm', 'REACHY', 'REACHYc','RareSim','simplify', 'speculate',
'quick_sec', 'BMC_J', 'BMC2', 'extract -a', 'extract', 'PDRa', 'par_scorr', 'dsat',
'iprove','BMC_J2','splitprove','pdrm_exact', 'AVY', 'PDRae', 'PDRMnc', 'PDRMyuf',
'PDRMnct', 'BMCsp', 'BMC3s' ]
engines = ['PDR', 'INTRP', 'BMCe', 'SIM', 'REACHX',
'PDRM', 'REACHM', 'BMC3',
'REACHP','REACHN','PDR_sd',
'PDRM_sd',
'INTRPb', 'INTRPm', 'REACHY', 'REACHYc','RareSim',
'BMC_J', 'BMC2', 'PDRa', 'dsat',
'iprove','BMC_J2','pdrm_exact', 'AVY', 'PDRae', 'PDRMnc', 'PDRMyuf',
'PDRMnct' , 'bmc_jump', 'BMCsp', 'BMC3s']
#'0.PDR', '1.INTERPOLATION', '2.BMCe', '3.SIMULATION',
#'4.REACHX', '5.PRE_SIMP', '6.simple', '7.PDRM', '8.REACHM', 9.BMC3'
# 10. Min_ret, 11. For_ret, 12. REACHP, 13. REACHN 14. PDRseed 15.prove_part_2,
#16.prove_part_3, 17.verify, 18.sleep, 19.PDRMm, 20.prove_part_1,
#21.run_parallel, 22.INTRP_bwd, 23. Interp_m 24. REACHY 25. REACHYc 26. Rarity Sim 27. simplify
#28. speculate, 29. quick_sec, 30 bmc3 -S, 31. BMC2 32. extract -a
#33. extract 34. pdr_abstract
#35 par_scorr, 36. dsat, 37. iprove 38. BMC_J2 39. splitprove 40. pdrm_exact
#41. AVY, 42. PDRae, 43. pdr -nc, 44. pdr -yuf, 45. pdrm -nct, 46 BMCsp, 47. BMC3s
win_list = [(0,.1),(1,.1),(2,.1),(3,.1),(4,.1),(5,-1),(6,-1),(7,.1)]
FUNCS = ["(pyabc_split.defer(pdr)(t))",
## "(pyabc_split.defer(abc)('&get;,pdr -vt=%f'%t))",
"(pyabc_split.defer(intrp)(t))",
## "(pyabc_split.defer(abc)('&get;,imc -vt=%f'%(t)))",
## "(pyabc_split.defer(abc)('&get;,imc-sofa -vt=%f'%(t)))",
"(pyabc_split.defer(bmce)(t))", #rkb -40 istemp change for hwmcc14 depth bound competition
## "(pyabc_split.defer(abc)('&get;,bmc -vt=%f'%t))",
"(pyabc_split.defer(simulate)(t))",
"(pyabc_split.defer(reachx)(t))",
## "(pyabc_split.defer(abc)('reachx -t %d'%t))",
"(pyabc_split.defer(pre_simp)())",
## "(pyabc_split.defer(super_prove)(2))",
"(pyabc_split.defer(simple)(t))",
"(pyabc_split.defer(pdrm)(t))",
"(pyabc_split.defer(abc)('&get;&reachm -vcs -T %d'%t))",
"(pyabc_split.defer(bmc3)(t))",
## "(pyabc_split.defer(abc)('bmc3 -C 1000000 -T %f'%t))",
"(pyabc_split.defer(abc)('dretime;&get;&lcorr;&dc2;&scorr;&put;dretime'))",
"(pyabc_split.defer(abc)('dretime -m;&get;&lcorr;&dc2;&scorr;&put;dretime'))",
"(pyabc_split.defer(abc)('&get;&reachp -vr -T %d'%t))",
"(pyabc_split.defer(abc)('&get;&reachn -vr -T %d'%t))",
## "(pyabc_split.defer(abc)('&get;,pdr -vt=%f -seed=521'%t))",
"(pyabc_split.defer(pdrseed)(t))",
"(pyabc_split.defer(prove_part_2)())",
"(pyabc_split.defer(prove_part_3)())",
"(pyabc_split.defer(verify)(JV,t))",
"(pyabc_split.defer(sleep)(t))",
"(pyabc_split.defer(pdrmm)(t))",
"(pyabc_split.defer(prove_part_1)())",
"(pyabc_split.defer(run_parallel)(JP,t,'TERM'))",
"(pyabc_split.defer(abc)('&get;,imc -bwd -vt=%f'%t))",
## "(pyabc_split.defer(abc)('int -C 1000000 -F 10000 -K 2 -T %f'%t))",
"(pyabc_split.defer(intrpm)(t))",
## "(pyabc_split.defer(abc)('int -C 1000000 -F 10000 -K 1 -T %f'%t))",
"(pyabc_split.defer(reachy)(t))",
## "(pyabc_split.defer(abc)('&get;&reachy -v -T %d'%t))",
"(pyabc_split.defer(abc)('&get;&reachy -cv -T %d'%t))",
## does rarity simulation
"(pyabc_split.defer(simulate2)(t))",
"(pyabc_split.defer(simplify)())",
"(pyabc_split.defer(speculate)())",
"(pyabc_split.defer(quick_sec)(t))",
"(pyabc_split.defer(bmc_j)(t))",
## "(pyabc_split.defer(abc)('bmc2 -C 1000000 -T %f'%t))",
"(pyabc_split.defer(bmc2)(t))",
"(pyabc_split.defer(extractax)('a'))",
"(pyabc_split.defer(extractax)())",
"(pyabc_split.defer(pdra)(t))",
"(pyabc_split.defer(pscorr)(t))",
"(pyabc_split.defer(dsat)(t))",
"(pyabc_split.defer(iprove)(t))",
"(pyabc_split.defer(bmc_j2)(t))",
"(pyabc_split.defer(splitprove)(t))",
"(pyabc_split.defer(pdrm_exact)(t))",
"(pyabc_split.defer(avy)(t))",
"(pyabc_split.defer(pdrae)(t))",
## "(pyabc_split.defer(bmc_par_jmps)(t))"
"(pyabc_split.defer(pdrmnc)(t))",
"(pyabc_split.defer(pdrmyuf)(t))",
"(pyabc_split.defer(pdrmnct)(t))",
"(pyabc_split.defer(BMCsp)(t))",
"(pyabc_split.defer(bmc3s)(t))"
]
## "(pyabc_split.defer(abc)('bmc3 -C 1000000 -T %f -S %d'%(t,int(1.5*max_bmc))))"
#note: interp given 1/2 the time.
## Similar engines below listed in the order of priority, high to low.
allreachs = [8,12,13,24,25]
allreachs = [24]
reachs = [24]
##allpdrs = [14,7,34,19,0]
#allpdrs = [34,7,14,0,42,43,44,45]
pdrs = allpdrs = [34,43,45,7,0]
bmcs1 = [9]
bmcs = allbmcs = [46,47,2,9,38]
exbmcs = exactbmcs = [9,2,31,46,47]
##exbmcs = [2,9,31]
##bmcs = [9,30,2,38]
#added AVY as a new interpolation method
#no AVY = 41 for hwmcc15
##allintrps = [41,23,1,22]
allintrps = [23,1,22]
##bestintrps = [41,23]
bestintrps = [23]
intrps = [23,1]
##intrps = [41,23,1] #putting ,imc-sofa first for now to test
##intrps = [41,23] #rkb
# done adding AVY
allsims = [26,3]
sims = [26]
allslps = [18]
slps = [18]
pre = [5]
combs = [36,37,39]
JV = pdrs+intrps+bmcs+sims #sets what is run in parallel '17. verify' above
JP = JV + [27] # sets what is run in '21. run_parallel' above 27 simplify should be last because it can't time out.
#_____________________________________________________________
# Function definitions:
# simple functions: ________________________________________________________________________
# set_globals, abc, q, x, has_any_model, is_sat, is_unsat, push, pop
# ALIASES
def initialize():
global xfi, max_bmc, last_time,j_last, seed, init_simp, K_backup, last_verify_time
global init_time, last_cex, last_winner, trim_allowed, t_init, sec_options, sec_sw
global n_pos_before, n_pos_proved, last_cx, pord_on, temp_dec, abs_time, gabs, gla,m_trace
global smp_trace,hist,init_initial_f_name, skip_spec, t_iter_start,last_simp, final_all, scorr_T_done
global last_gap, last_gasp_time, max_pos,pairs
xfi = x_factor = 1 #set this to higher for larger problems or if you want to try harder during abstraction
max_bmc = -1
last_time = 0
## last_gasp_time = 2001 #set to conform to hwmcc12
last_gasp_time = 1500 #set to conform to hwmcc15
last_gasp_time = 3600 #set to 1 hour
j_last = 0
seed = 113
init_simp = 1
temp_dec = True
K_backup = init_time = 0
last_verify_time = 20
last_cex = last_winner = 'None'
last_cx = 0
trim_allowed = True
pord_on = False
t_init = 2 #this will start sweep time in find_cex_par to 2*t_init here
sec_sw = False
sec_options = ''
smp_trace = m_trace = []
cex_list = []
n_pos_before = n_pos()
n_pos_proved = 0
## if n_ands() > 100000:
## abs_time = 300
## else:
## abs_time = 150 #timeout for abstraction
abs_time = 100000 #let size terminate this.
abs_time = 500
abs_time = 150
abs_time = 200 #for hwmcc15
abs_time = 1000 #for hwmcc17 examples
abs_ref_time = 50 #number of sec. allowed for abstraction refinement.
## total_spec_refine_time = 150 # timeout for speculation refinement
total_spec_refine_time = 200 # timeout for speculation refinement changed for hwmcc15
abs_ratio = .5
## hist = []
skip_spec = False
t_iter_start = 0
inf = 10000000
last_simp = [inf,inf,inf,inf]
final_all = 1
final_all = 0
scorr_T_done = 0
last_gap = 50
max_pos = 1000
pairs = []
## abs_time = 100
## gabs = False
## abs_time = 500
## gabs = True
def set_abs_method():
""" controls the way we do abstraction, 0 = no bip, 1 = old way, 2 use new bip and -dwr
see absab()
"""
global ifbip, abs_time,gabs,gla,if_no_bip
print 'current values ifbip = %d, abs_time = %d'%(ifbip,abs_time)
print 'Set method of abstraction: \n0 = vta for 500 and gla refin., \n1 = old way, \n2 = ,abs and -dwr, \n3 = vta for 100 followed by gla refine.,\n4 = vta for 500 then gla refine. but no bip methods gla refine., \n5 = gla and gla refine.'
s = raw_input()
s = remove_spaces(s)
if s == '1': #use the old way with ,abs but no dwr
ifbip = 1 #old way
abs_time = 100
if_no_bip = False
gabs = True
gla = False
elif s == '0':#use vta and gla refinement
ifbip = 0
abs_time = 500
if_no_bip = False
gabs = False
gla = False
elif s == '2': #use ,abc -dwr
ifbip = 2
abs_time = 100
if_no_bip = False
gabs = True #use register refinement
gla = False
elif s == '3': #use vta and gla refinement
ifbip = 0
abs_time = 100
if_no_bip = False
gabs = False
gla = False
elif s == '4': #use vta, gla refine. and no bip
ifbip = 0
abs_time = 100
if_no_bip = True
gabs = True
gla = False
elif s == '5': #use gla and gla_refinement
ifbip = 0
abs_time = 100
if_no_bip = False
gabs = False
gla = True
#should make any of the methods able to us no bip
print 'ifbip = %d, abs_time = %d, gabs = %d, if_no_bip = %d, gla = %d'%(ifbip,abs_time,gabs,if_no_bip,gla)
def ps():
out = print_circuit_stats()
return out
def iprove(t=100):
abc('iprove')
def dsat(t=100):
abc('dsat')
def splitprove(t=900):
abc('&get;&splitprove -v -P 30 -L 5 -T 15')
def n_real_inputs():
"""This gives the number of 'real' inputs. This is determined by trimming away inputs that
have no connection to the logic. This is done by the ABC alias 'trm', which changes the current
circuit. In some applications we do not want to change the circuit, but just to know how may inputs
would go away if we did this. So the current circuit is saved and then restored afterwards."""
## abc('w %s_savetempreal.aig; logic; trim; st ;addpi'%f_name)
abc('w %s_savetempreal.aig'%f_name)
with redirect.redirect( redirect.null_file, sys.stdout ):
## with redirect.redirect( redirect.null_file, sys.stderr ):
reparam()
n = n_pis()
abc('r %s_savetempreal.aig'%f_name)
return n
def timer(t):
btime = time.clock()
time.sleep(t)
print t
return time.clock() - btime
def sleep(t):
## print 'Sleep time = %d'%t
time.sleep(t)
return Undecided
def abc(cmd):
""" executes an ABC command and represses all outputs"""
abc_redirect_all(cmd)
def xa(cmd):
""" executes an ABC command and shows all outputs"""
return run_command( cmd )
def abc_redirect( cmd, dst = redirect.null_file, src = sys.stdout ):
"""This is our main way of calling an ABC function. Redirect, means that we suppress any output from ABC"""
with redirect.redirect( dst, src ):
return run_command( cmd )
def abc_redirect_all( cmd ):
"""This is our main way of calling an ABC function. Redirect, means that we suppress any output from ABC, including error printouts"""
with redirect.redirect( redirect.null_file, sys.stdout ):
with redirect.redirect( redirect.null_file, sys.stderr ):
return run_command( cmd )
##def convert(t):
## t = int(t*100)
## return str(float(t)/100)
def set_engines(N=0):
"""
Called only when read_file is called.
Sets the MC engines that are used in verification according to
if there are 4 or 8 processors. if if_no_bip = 1, we will not use any bip and reachx engines
"""
global reachs,pdrs,sims,intrps,bmcs,n_proc,abs_ratio,ifbip,bmcs1, if_no_bip, allpdrs,allbmcs
bmcs1 = [9] #BMC3
#for HWMCC we want to set N =
if N == 0:
N = n_proc = os.sysconf(os.sysconf_names["SC_NPROCESSORS_ONLN"])
## N = 4 # this was for hwmcc15
N = n_proc = 2*N
## N = n_proc = 8 ### simulate 4 processors for HWMCC - turn this off a hwmcc.
else:
n_proc = N
## print 'n_proc = %d'%n_proc
#strategy is to use 2x number of processors
if N <= 1:
reachs = [24]
pdrs = [7]
## bmcs = [30]
bmcs = [9]
intrps = []
sims = []
slps = [18]
elif N <= 2:
reachs = [24]
pdrs = [7]
bmcs = [46,47]
intrps = []
sims = []
slps = [18]
elif N <= 4: #this will be the operative one for hwmcc'15
reachs = [24] #reachy
pdrs = [7,34] #prdm pdr_abstract
if if_no_bip:
allpdrs = pdrs = [7,19] #pdrm pdrmm
bmcs = [46,47,2] #bmc3 bmc3 -S
intrps = [23] #interp_m
sims = [26] #Rarity_sim
slps = [18] #sleep
# 0.PDR, 1.INTERPOLATION, 2.BMC, 3.SIMULATION,
# 4.REACHX, 5.PRE_SIMP, 6.simple, 7.PDRM, 8.REACHM, 9.BMC3
# 10.Min_ret, 11.For_ret, 12.REACHP, 13.REACHN 14.PDRseed 15.prove_part_2,
# 16.prove_part_3, 17.verify, 18.sleep, 19.PDRMm, 20.prove_part_1,
# 21.run_parallel, 22.INTRP_bwd, 23.Interp_m 24.REACHY 25.REACHYc 26.Rarity Sim 27.simplify
# 28.speculate, 29.quick_sec, 30.bmc3 -S, 31.BMC2 32.extract -a 33.extract 34.pdr_abstract
# 35.par_scorr, 36.dsat, 37.iprove
# BIPS = 0.PDR, 1.INTERPOLATION, 2.BMC, 14.PDRseed, 22.INTRP_bwd, 34.pdr_abstract
# also reparam which uses ,reparam
elif N <= 8: #used for HWMCC'15
reachs = [24] #REACHY
allpdrs = pdrs = [7,34,14] #PDRM pdr_abstract PDR_seed
## intrps = [41,23,1] #Interp_m
intrps = [23] #rkb
allbmcs = bmcs = [46,47,9,2] #BMC3 bmc3 -S BMC
if if_no_bip:
allpdrs = pdrs = [7,19] #PDRM PDRMm
intrps = allintrps = [41,23] #Interp_m
bmcs = allbmcs = [46,47,9,38]
sims = [26] #Rarity_Sim
slps = [18] #sleep
else:
reachs = [24] #REACHY REACHX
pdrs = allpdrs
## pdrs = [7,34,14,19,0] #PDRM pdr_abstract PDR_seed PDRMm PDR
## pdrs = allpdrs =[7,34,14]
## intrps = [41,23,1] #Interp_m INTERPOLATION
## intrps = [41,23] #rkb
intrps = [23,1] #Interp_m INTERPOLATION
intrps = [23] #rkb
bmcs = allbmcs #allbmcs = [9,30,2,31,38,46,47]
if if_no_bip:
allpdrs = pdrs = [7,19] #PDRM PDRMm
intrps = allintrps = [41,23] #Interp_m
reachs = [24] #REACHY
bmcs = [46,47,9,38]
sims = [26] #Rarity_Sim
slps = [18] #sleep
print 'No. engines = %d,%d '%(N,n_proc)
print 'pdrs = %s'%str(pdrs)
print 'bmcs = %s'%str(bmcs)
def set_globals():
"""This sets global parameters that are used to limit the resources used by all the operations
bmc, interpolation BDDs, abstract etc. There is a global factor 'x_factor' that can
control all of the various resource limiting parameters"""
global G_C,G_T,x_factor
nl=n_latches()
na=n_ands()
np = n_pis()
#G_C = min(500000,(3*na+500*(nl+np)))
G_C = x_factor * min(100000,(3*na+500*(nl+np)))
#G_T = min(250,G_C/2000)
G_T = x_factor * min(75,G_C/2000)
G_T = max(1,G_T)
#print('Global values: BMC conflicts = %d, Max time = %d sec.'%(G_C,G_T))
def a():
"""this puts the system into direct abc input mode"""
print "Entering ABC direct-input mode. Type q to quit ABC-mode"
n = 0
while True:
print ' abc %d> '%n,
n = n+1
s = raw_input()
if s == "q":
break
run_command(s)
def remove_spaces(s):
y = ''
for t in s:
if not t == ' ':
y = y + t
return y
def seq_name(f):
names = []
f = f + '_'
names = []
while len(f)>0:
j = f.find('_')
if j == -1:
break
names = names + [f[:j]]
## print names
f = f[j+1:]
## print f
return names
def revert(f,n):
l = seq_name(f)
for j in range(n):
if len(l)>0:
l.pop()
name = construct(l)
return name
def n_eff_pos():
N=n_pos()
l=len(list_0_pos())
return N-l
def construct(l):
ll = l
name = ''
while len(l)>0:
name = '_'+ll.pop()+name
return name[1:]
def process_sat():
l = seq_name(f_name)
def add_trace(s):
global m_trace
m_trace = m_trace + [s]
def read_file_quiet_i(fname=None):
""" this preserves t_inter_start and is called internally by some functons."""
global t_iter_start
ts = t_iter_start
read_file_quiet(fname)
t_iter_start = ts
def read_file_quiet(fname=None):
"""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, init_initial_f_name, win_list,seed, sec_options
global win_list, init_simp, po_map, aigs, hist, init_initial_f_name
abc('fraig_restore') #clear out any residual fraig_store
set_engines() #temporary
init_simp = 1
win_list = [(0,.1),(1,.1),(2,.1),(3,.1),(4,.1),(5,-1),(6,-1),(7,.1)] #initialize winning engine list
po_map = range(n_pos())
initialize()
## x_factor = 1
## seed = 223
## max_bmc = -1
if fname is None:
print 'Type in the name of the aig file to be read in'
s = raw_input()
s = remove_spaces(s)
## print s
else:
s = fname
if s[-4:] == '.aig':
f_name = s[:-4]
elif s[-5:] == '.blif':
f_name = s[:-5]
else:
f_name = s
s = s+'.aig'
## run_command(s)
## print s
init_initial_f_name = initial_f_name = f_name
run_command('r %s;st'%s)
## run_command('fold') #only does something if some of the outputs are constraints.
sz = sizeof()
hist = []
aigs_pp('push','initial')
run_command('logic;undc;st;zero')
if not sz == sizeof():
aigs_pp('push','undc')
print 'history = %s'%hist
## if s[-4:] == '.aig':
## run_command('&r %s;&put'%s)
## run_command('r %s'%s)
## run_command('logic;undc;st;zero')
if s[-5:] == '.blif': #this is a blif file
## run_command('r %s'%s)
## run_command('logic,undc')
## abc('st;&get;&put') #changes names to generic ones for doing cec later.
## run_command('zero;w %s.aig'%f_name)
abc('&get;&put;w %s.aig'%f_name) #warning: changes names to generic ones.
run_command('fold')
set_globals()
## hist = []
## init_initial_f_name = initial_f_name = f_name
## run_command('fold') #only does something if some of the outputs are constraints.
## aigs_pp('push','initial')
#aigs = create push/pop history of aigs
#aigs.push() put the initial aig on the aig list.
print 'Initial f_name = %s'%f_name
abc('addpi') #only does something if there are no PIs
#check_pos() #this removes constant outputs with a warning -
#needed when using iso. Need another fix for using iso.
ps()
return
def aigs_pp(op='push', typ='reparam'):
global hist,init_initial_f_name
""" hist ia a sequence of types in {reparam, phase, initial, tempor}
and the corresponding aigs are stored in numbered files
These are used to unmap the cex back to the origina. The unmaapping is done by """
## print hist
if op == 'push':
hist.append(typ)
abc('w %s_aigs_%d.aig'%(init_initial_f_name,len(hist)))
if op == 'pop':
## print hist
abc('cexsave') #protect current cex from a read
abc('r %s_aigs_%d.aig'%(init_initial_f_name,len(hist)))
abc('cexload')
ps()
typ = hist.pop()
## print hist
return typ
def scl():
abc('&get;&scl;&put')
ps()
def cex_trim_g(F_init=0,tail=0,m=''):
abc('w %s_cex.aig'%f_name)
N=cex_frame()
G = N - tail
F = F_init
abc('cexsave')
while True:
print 'F = %d, G = %d'%(F,G)
abc('r %s_cex.aig'%f_name)
abc('cexload')
if m == '':
abc('cexcut -F %d -G %d'%(F,G))
else:
abc('cexcut -m -F %d -G %d'%(F,G))
## abc('drw')
## ps()
res = run_parallel(slps+bmcs,20)
## run_command('bmc2 -v -T 20')
## if is_sat(): #got a shortening of cex
if not res == Undecided:
Nb = cex_frame() #size of shortcut
abc('cexmerge -F %d -G %d'%(F,G))
abc('r %s_cex.aig'%f_name)
abc('cexload')
abc('testcex -a')
if cex_po() <0:
return 'ERROR2'
Nt=cex_frame() #current cex length
print 'Cex length reduced from %d to %d'%(N,Nt)
return
F = F + (G-F)/2
## G = N - i*delta
if F >= G:
return
def cex_trim(factor=1):
t_begin = time.time()
abc('w %s_cex.aig'%f_name)
N=cex_frame()
inc = min(N/10,100)
F = 0
G = inc
abc('cexsave')
abc('cexcut -n -F %d -G %d'%(F,G))
run_command('bmc2 -v -F %d -T 5'%(.9*inc))
inc = max(int(factor*n_bmc_frames()),2)
F = N - inc
G = N
print 'inc = %d'%inc
while True:
abc('r %s_cex.aig'%f_name)
abc('cexload')
abc('cexcut -n -F %d -G %d'%(F,G))
## abc('drw')
## ps()
## run_command('bmc2 -v -F %d -T 20'%(.9*inc))
run_parallel(slps+bmcs,10)
if not is_sat():
abc('cex_load') #leave current cex in buffer
Nb = inc
else:
Nb = cex_frame() #size of shortcut
abc('cexmerge -F %d -G %d'%(F,G))
abc('r %s_cex.aig'%f_name)
abc('cexload')
abc('testcex -a')
if cex_po() <0:
return 'ERROR2'
## abc('cexload')
Nt=cex_frame() #current cex length
print 'Cex length = %d'%Nt
G=F
F = max(0,F - inc)
print 'F = %d, G = %d'%(F,G)
if G <= 2:
abc('cexload')
print 'Time: %0.2f'%(time.time() - t_begin)
return
def read_file():
global win_list, init_simp, po_map
read_file_quiet()
## ps()
## init_simp = 1
## win_list = [(0,.1),(1,.1),(2,.1),(3,.1),(4,.1),(5,-1),(6,-1),(7,.1)] #initialize winning engine list
## po_map = range(n_pos())
def rf():
## set_engines(4) #temporary
read_file()
abc('zero')
def write_file(s):
"""this is the main method for writing the current circuit to an AIG file on disk.
It manages the name of the file, by giving an extension (s). The file name 'f_name'
keeps increasing as more extensions are written. A typical sequence is
name, name_smp, name_smp_abs, name_smp_abs_spec, name_smp_abs_spec_final"""
global f_name
"""Writes out the current file as an aig file using f_name appended with argument"""
f_name = '%s_%s'%(f_name,s)
print '^^^ New f_name = %s'%f_name
ss = '%s.aig'%(f_name)
print 'WRITING %s: '%ss,
ps()
abc('w '+ss)
def get_max_bmc(chtr=False):
return get_bmc_depth(chtr)
def get_bmc_depth(chtr=False):
""" 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
including g ones, for which it is known that there is not cex out to that depth."""
global max_bmc
c = cex_frame()
if c > 0:
b = c-1
else:
b = n_bmc_frames()
if b > max_bmc:
set_max_bmc(b,chtr)
if chtr:
report_bmc_depth(max_bmc)
return max_bmc
def null_status():
""" resets the status to the default values but note that the &space is changed"""
abc('&get;&put')
##def set_bmc_depth(b,chtr=False):
## set_max_bmc(b,chtr)
def set_max_bmc(b,chtr=False):
""" Keeps increasing max_bmc which is the maximum number of time frames for
which the current circuit is known to be UNSAT for"""
global max_bmc
if b > max_bmc and chtr:
max_bmc = b
report_bmc_depth(max_bmc)
return max_bmc
def report_bmc_depth(m):
## return #for non hwmcc applications
print 'u%d'%m
def print_circuit_stats():
"""Stardard way of outputting statistice about the current circuit"""
global max_bmc
i = n_pis()
o = n_pos()
l = n_latches()
a = n_ands()
s='ANDs'
if a == -1:
a = n_nodes()
s = 'Nodes'
## b = max(max_bmc,bmc_depth()) # don't want to do this because bmc_depth can change max_bmc
b = get_max_bmc(chtr=False)
c = cex_frame()
if b>= 0:
if c>b:
out ='PIs=%d,POs=%d,FF=%d,%s=%d,max depth=%d,CEX depth=%d'%(i,o,l,s,a,b,c)
elif is_unsat():
out = 'PIs=%d,POs=%d,FF=%d,%s=%d,max depth = infinity'%(i,o,l,s,a)
else:
out = 'PIs=%d,POs=%d,FF=%d,%s=%d,max depth=%d'%(i,o,l,s,a,b)
else:
if c>=0:
out = 'PIs=%d,POs=%d,FF=%d,%s=%d,CEX depth=%d'%(i,o,l,s,a,c)
else:
out = 'PIs=%d,POs=%d,FF=%d,%s=%d'%(i,o,l,s,a)
print out
return out
def is_unsat():
if prob_status() == 1:
return True
else:
return False
def is_sat():
if prob_status() == 0:
return True
else:
return False
def wc(file):
"""writes <file> so that costraints are preserved explicitly"""
abc('&get;&w %s'%file)
def rc(file):
"""reads <file> so that if constraints are explicit, it will preserve them"""
abc('&r -s %s;&put'%file)
#more complex functions: ________________________________________________________
#, abstract, pba, speculate, final_verify, dprove3
def timer(s):
btime = time.clock()
abc(s)
print 'time = %0.2f'%(time.clock() - btime)
def med_simp():
x = time.time()
abc("&get;&scl;&dc2;&lcorr;&dc2;&scorr;&fraig;&dc2;&put;dretime")
#abc("dc2rs")
ps()
print 'time = %0.2f'%(time.time() - x)
##def simplify_old(M=0):
## """Our standard simplification of logic routine. What it does depende on the problem size.
## For large problems, we use the &methods which use a simple circuit based SAT solver. Also problem
## size dictates the level of k-step induction done in 'scorr' The stongest simplification is done if
## n_ands < 20000. Then it used the clause based solver and k-step induction where |k| depends
## on the problem size """
## set_globals()
## abc('&get;&scl;&lcorr;&put')
## p_40 = False
## n =n_ands()
## if n >= 70000 and not '_smp' in f_name:
#### abc('&get;&scorr -C 0;&put')
## scorr_T(30)
## ps()
## n =n_ands()
## if n >= 100000:
## abc('&get;&scorr -k;&put')
## ps()
## if (70000 < n and n < 150000):
#### print '1'
## p_40 = True
## abc("&get;&dc2;&put;dretime;&get;&lcorr;&dc2;&put;dretime;&get;&scorr;&fraig;&dc2;&put;dretime")
#### print 2'
## ps()
## n = n_ands()
#### if n<60000:
## if n < 80000:
## abc("&get;&scorr -F 2;&put;dc2rs")
## ps()
## else: # n between 60K and 100K
## abc("dc2rs")
## ps()
## n = n_ands()
#### if (30000 < n and n <= 40000):
## if (60000 < n and n <= 70000):
## if not p_40:
## abc("&get;&dc2;&put;dretime;&get;&lcorr;&dc2;&put;dretime;&get;&scorr;&fraig;&dc2;&put;dretime")
## abc("&get;&scorr -F 2;&put;dc2rs")
## ps()
## else:
## abc("dc2rs")
## ps()
## n = n_ands()
#### if n <= 60000:
## if n <= 70000:
## abc('scl -m;drw;dretime;lcorr;drw;dretime')
## ps()
## nn = max(1,n)
## m = int(min( 70000/nn, 16))
## if M > 0:
## m = M
## if m >= 1:
## j = 1
## while j <= m:
## set_size()
## if j<8:
## abc('dc2')
## else:
## abc('dc2rs')
## abc('scorr -C 1000 -F %d'%j) #was 5000 temporarily 1000
## if check_size():
## break
## j = 2*j
## print 'ANDs=%d,'%n_ands(),
## if n_ands() >= .98 * nands:
## break
## continue
## if not check_size():
## print '\n'
## return get_status()
def simplify(M=0,N=0):
"""Our standard simplification of logic routine. What it does depende on the problem size.
For large problems, we use the &methods which use a simple circuit based SAT solver. Also problem
size dictates the level of k-step induction done in 'scorr' The stongest simplification is done if
n_ands < 20000. Then it used the clause based solver and k-step induction where |k| depends
on the problem size
Does not change #PIs.
"""
global smp_trace
set_globals()
smp_trace = smp_trace + ['&scl;&lcorr']
abc('&get;&scl;&lcorr;&put')
## abc('scl') # RKB temp
if n_latches == 0:
return get_status()