-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresultsUtils.py
1110 lines (950 loc) · 36.5 KB
/
resultsUtils.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
#!/usr/bin/env python
from pylab import *
import MySQLdb as mdb
import os
import sys
import csv
import progressbar
from sets import Set
TIMEOUT = 900
###############
# TODO move this in different file at some point
def getFamily(path):
tokens = path.split('/')
return tokens[5]
class Job:
def __init__(self, job_id, description, tlimit, mlimit, pb_set_id, args, binary, log):
self.id = job_id
self.description = description
self.time_limit = tlimit
self.memory_limit = mlimit
self.problem_set_id = pb_set_id
self.binary = binary
self.log = log
def __str__(self):
return "Job "+ str(self.id)+ ":\n" + \
" "+ self.description+ "\n" + \
" time_limit "+ str(self.time_limit)+ "+ mem_limit "+ str(self.memory_limit)+ "\n" +\
" problem_set "+ str(self.problem_set_id) + "\n" +\
" binary "+ self.binary+ "\n" +\
" log "+ self.log
@staticmethod
def getFromDB(cur, job_id):
cur.execute("""SELECT
id, description, time_limit, memory_limit,
problem_set_id, args, timestamp, binary_path, log_path
from Jobs where Jobs.id = %s;""", job_id)
jobs = cur.fetchall()
assert(len(jobs)==1)
assert(jobs[0][0] == job_id)
description = jobs[0][1]
time_limit = int(jobs[0][2])
memory_limit = int(jobs[0][3])
problem_set_id = int(jobs[0][4])
args = jobs[0][5]
binary = jobs[0][7]
log = jobs[0][8]
return Job(job_id, description, time_limit,\
memory_limit, problem_set_id, args, binary, log)
class Result:
Sat, Unsat, Unknown = "unsat", "sat", "unknown"
@staticmethod
def fromStr(string):
if (string == "unsat"):
return Result.Unsat
if( string == "sat"):
return Result.Sat;
assert (string == "unknown")
return Result.Unknown
@staticmethod
def str(res):
if (res == Result.Sat):
return "sat"
if (res == Result.Unsat):
return "unsat"
if (res == Result.Unknown):
return "unknown"
class Status:
Timeout, Memout, Solved = "Timeout", "Memout", "Solved"
@staticmethod
def fromStr(string):
if (string == "timeout"):
return Status.Timeout
if( string == "memout"):
return Status.Memout
assert (string == "solved")
return Status.Solved
def write(txt):
sys.stdout.write(txt)
def initializeProgressBar(max_value):
"""Set up the command-line progress bar with max_value
"""
bar = progressbar.ProgressBar(maxval=max_value, widgets=[progressbar.Bar('=', '[', ']'), ' ', progressbar.Percentage()])
return bar
def numLinesInFile(fname):
""" Counts the number of lines in the given file.
"""
with open(fname, 'rb') as f:
for i, l in enumerate(f):
pass
return i + 1
class Problem:
def __init__(self, pb_id, path):
self.id = pb_id
self.path = path
@staticmethod
def getFromDB(cur, problem_id):
cur.execute("""SELECT id, path
from Problems where Problems.id = %s;""", problem_id)
pbs = cur.fetchall()
assert(len(pbs)==1)
assert(int(pbs[0][0]) == problem_id)
return Problem(problem_id, pbs[0][1])
def __hash__(self):
return self.id
def __str__(self):
return "(id " + str(self.id) + ", path " + self.path + ")"
def __eq__(self, other):
if not isinstance(other, Problem):
return False
return self.id == other.id
class ProblemResult:
def __init__(self, result, status, cpu_time, mem, exit_status):
self.result = result
self.status = status
self.cpu_time = cpu_time
self.memory = mem
self.exit_status = exit_status
def __str__(self):
res = "(result: "+self.result + ", " \
" status: "+self.status + ", " \
" cpu_time: "+str(self.cpu_time) + ", " \
" memory: "+str(self.memory) +")" \
" exit_status: "+str(self.exit_status) + ")"
return res
def isSolved(self):
return self.status == Status.Solved and \
(self.result == Result.Sat or self.result == Result.Unsat)
@staticmethod
def getFromDB(cur, job_id, problem_id):
cur.execute("""SELECT
job_id, problem_id, result, cpu_time, memory, exit_status, status
from JobResults where job_id = %s and problem_id = %s;""", (job_id, problem_id))
jobs = cur.fetchall()
assert(len(jobs)==1)
assert(jobs[0][0] == job_id and jobs[0][1] == problem_id)
result = Result.fromStr(jobs[0][2])
cpu_time = float(jobs[0][3])
memory = float(jobs[0][4])
exit_status = int(jobs[0][5])
status = Status.fromStr(jobs[0][6])
return ProblemResult(result, status, cpu_time, memory, exit_status)
@staticmethod
def getFromDB(cur, job_id):
cur.execute("""SELECT
problem_id, result, cpu_time, memory, exit_status, status
from JobResults where job_id = %s;""", (job_id))
jresults = cur.fetchall()
assert(len(jresults))
pb_results = {}
for jres in jresults:
problem_id = int(jres[0])
result = Result.fromStr(jres[1])
cpu_time = float(jres[2])
memory = float(jres[3])
exit_status = int(jres[4])
status = Status.fromStr(jres[5])
pb_res = ProblemResult(result, status, cpu_time, memory, exit_status)
pb_results[problem_id] = pb_res
return pb_results
class ProblemSet:
def __init__(self, pb_set_id, description, problems):
self.id = pb_set_id
self.description = description
self.problems = problems
@staticmethod
def getFromDB(cur, problem_set_id):
print "Getting problem set ", problem_set_id, " from data-base"
cur.execute("""SELECT
id, description from ProblemSets where id = %s;""", (problem_set_id))
res = cur.fetchall()
assert(len(res)==1)
assert(res[0][0] == problem_set_id)
description = res[0][1]
cur.execute("""SELECT t1.problem_id, t2.path FROM ProblemSetToProblem t1
INNER JOIN Problems t2 ON t1.problem_id = t2.id
WHERE t1.problem_set_id = %s;""", (problem_set_id))
res = cur.fetchall()
assert (len(res))
problems = []
for r in res:
pb_id = int(r[0])
path = r[1]
pb = Problem(pb_id, path)
problems.append(pb)
return ProblemSet(problem_set_id, description, problems)
def __hash__(self):
return self.id
def __eq__(self, other):
if not isinstance(other, ProblemSet):
return False
return self.id == other.id
class CumulativeResult:
def __init__(self):
self.solved = 0
self.cpu_time = 0.0
def __str__(self):
res = "(solved: "+self.solved + ", " \
" cpu_time: "+self.cpu_time + ")"
return res
def addResult(self, res):
if (res.status != Status.Solved):
return
if (res.result == Result.Unknown):
return
self.solved += 1
self.cpu_time += res.cpu_time
class SolverToCumulativeResult:
def __init__(self):
self.solved = 0
self.total_time = 0.0
def addResult(self, result):
if (result.isSolved):
self.solved += 1
self.total_time += result.cpu_time
class CummulativeResults:
def __init__(self):
self.table = {}
def addSolverResult(self, solver, result):
if not solver in self.table:
self.table[solver] = CumulativeResult()
self.table[solver].addResult(result)
def getResult(self, solver):
assert (solver in self.table)
return self.table[solver]
def getBest():
max_solved = 0
min_time = None
best = None
for sv in self.table:
entry = self.table[sv]
# first iteration
if best == None:
max_solved = entry.solved
min_time = entry.total_time
best = sv
continue
# clearly not better
if entry.solved < max_solved:
continue
if entry.solved > max_solved:
max_solved = entry.solved
min_time = entry.total_time
best = sv
continue
if entry.total_time < min_time:
min_time = entry.min_time
best = sv
return best
def getBest(solverToRes, solvers):
max_solved = 0
min_time = None
best = None
for sv in solvers:
assert (sv in solverToRes)
entry = solverToRes[sv]
# first iteration
if best == None:
max_solved = entry.solved
min_time = entry.total_time
best = sv
continue
# clearly not better
if entry.solved < max_solved:
continue
if entry.solved > max_solved:
max_solved = entry.solved
min_time = entry.total_time
best = sv
continue
if entry.total_time < min_time:
min_time = entry.min_time
best = sv
return best
class SummaryTable:
def __init__(self, families, problem_set):
self.solvers = []
self.table = {}
for f in families:
self.table[f] = {}
self.fam_count = {}
for f in families:
self.fam_count[f] = 0
for pb in problem_set.problems:
fam = getFamily(pb.path)
self.fam_count[fam] = self.fam_count[fam] + 1
def addSolver(self, solver):
if (not solver in self.solvers):
self.solvers.append(solver)
def addResult(self, sv, pb, res):
fam = getFamily(pb.path)
res2solv = self.table[fam]
if not sv in res2solv:
res2solv[sv] = CumulativeResult()
res2solv[sv].addResult(res)
def removeFamilies(self, fams):
for fam in fams:
del self.table[fam]
del self.fam_count[fam]
def csv(self):
print "family, count, ",
for solver in self.solvers:
sv_name = solver
print sv_name, " solved, ",
print sv_name, " time, ",
print ""
for fam in self.table:
print fam, ", ", self.fam_count[fam], ", ",
sv2res = self.table[fam]
for solver in self.solvers:
result = sv2res[solver]
print result.solved, ", ",
print round(result.cpu_time,2), ", ",
print ""
def laTex(self, solvers):
print "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
print "% Printing table for ",
for sv in solvers:
print sv, " ",
print "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"
n = len(solvers)
write("\\begin{tabular}{| l |")
for i in range(n):
write(" r r |")
write("}\n")
# headers
write("\\cline{2-"+str(2*n+1)+"}\n")
write("\\multicolumn{1}{c|}{}\n")
for solver in solvers:
write("& \\multicolumn{2}{c|}{\\textsf{"+solver+"}}\n")
write ("\\\\\n")
write("\\cline{2-"+str(2*n+1)+"}\n")
write ("\\multicolumn{1}{l}{\\tiny\\textsf{set}}\n")
for solver in solvers:
write("& \\multicolumn{1}{r}{\\tiny\\textsf{solved}} & \\multicolumn{1}{r}{\\tiny\\textsf{time (s)}} \n")
write ("\\\\\n\\hline\n")
i= 0
# total for each solver
summary = SolverToCumulativeResult()
for fam in sorted(self.table.keys()):
if i % 2 == 0:
write("\\rowcolor[gray]{.95}\n")
i+=1
# family
fam_str = fam.replace("_","\_")
write("\\textsf{"+fam_str+"}\n")
# count
write("("+str(self.fam_count[fam])+")\n")
best = getBest(self.table[fam], solvers)
# results
sv_to_res = self.table[fam]
for sv in solvers:
res = sv_to_res.getResult(sv)
if sv == best:
time = "\\textbf{"+str(round(res.cpu_time,2))+"} "
solved = "\\textbf{"+str(res.solved)+"} "
else:
time = str(round(res.cpu_time,2))+" "
solved = str(res.solved)+" "
write("& "+solved + " & " + time )
summary.addSolverResult(sv, res)
write("\n")
write ("\\\\\n")
write("\\hline\n")
write("\\multicolumn{1}{c|}{}")
# pick best sum
best_total = summary.getBest()
for sv in solvers:
sum_res = summary.getResult(sv)
if sv == best_total:
time = "\\textbf{"+str(round(sum_res.total_time,2))+"} "
solved = "\\textbf{"+str(sum_res.solved)+"} "
else:
time = str(round(sum_res.cpu_time,2))+" "
solved = str(sum_res.solved)+" "
write("& "+solved + " & " + time + "\n")
write("\\\\\n\\cline{2-"+str(2*n+1)+"}\n")
write("\\end{tabular}\n")
class SolverToResult:
def __init__(self):
self.table = {}
def addResult(self, solver, result):
assert (not solver in self.table)
self.table[solver] = result
def hasResult(self, solver):
return (solver in self.table)
def getResult(self, solver):
assert (solver in self.table)
return self.table[solver]
def allAgree(self):
result = None
for sv in self.table:
res = self.table[sv]
if (res.status != Status.Solved):
continue
if (res.result == Result.Unknown):
continue
if (result == None):
result = res.result
if (result != res.result):
return False
return True
class ResultsTable:
def __init__(self):
self.table = {} # pb_id => SolverToResult
self.solvers = Set()
self.id_to_problem = {}
self.problem_to_id = {}
self.id_count = 0
def newId(self):
self.id_count += 1
return self.id_count
def getResult(self, solver, problem):
assert solver in self.solvers
sv_res = self.table[solver]
pb_id = self.problem_to_id[problem]
assert pb_id in sv_res
return sv_res[pb_id]
def addResult(self, problem, solver, result):
if not (problem in self.table):
self.table[problem] = SolverToResult()
self.table[problem].addResult(solver, result)
def addProblem(self, problem):
if not problem in self.problem_to_id:
pb_id = self.newId()
self.problem_to_id[problem] = pb_id
self.id_to_problem[pb_id] = problem
return self.problem_to_id[problem]
def addSolver(self, sv_config):
if (not sv_config in self.solvers):
self.solvers.add(sv_config)
# adds results for the job to the results of the given solver
def addJobToSolver(self, cur, solver, job_id):
print "Adding job ", job_id, " to solver ", solver
job = Job.getFromDB(cur, job_id)
problem_set = ProblemSet.getFromDB(cur, job.problem_set_id)
print "Getting results for job ", job_id, "..."
bar = initializeProgressBar(len(problem_set.problems))
job_results = ProblemResult.getFromDB(cur, job_id)
assert len(job_results) == len(problem_set.problems), "Missing problems from job"
i = 0
for pb in problem_set.problems:
i = i + 1
bar.update(i)
pb_id = pb.id
pb_local_id = self.addProblem(pb)
pb_res = job_results[pb_id]
self.addResult(pb_local_id, solver, pb_res)
def addJobToSolverIncomplete(self, cur, solver, job_id):
print "Adding job ", job_id, " to solver ", solver
job = Job.getFromDB(cur, job_id)
problem_set = ProblemSet.getFromDB(cur, job.problem_set_id)
print "Getting results for job ", job_id, "..."
bar = initializeProgressBar(len(problem_set.problems))
job_results = ProblemResult.getFromDB(cur, job_id)
# assert len(job_results) == len(problem_set.problems), "Missing problems from job"
i = 0
for pb in problem_set.problems:
i = i + 1
bar.update(i)
pb_id = pb.id
pb_local_id = self.addProblem(pb)
if pb_id in job_results:
pb_res = job_results[pb_id]
self.addResult(pb_local_id, solver, pb_res)
def readRun(self, solver, bench_file, path):
print "Reading run of solver ", solver, " from path ", path
self.addSolver(solver)
num_lines = numLinesInFile(bench_file)
bench_count = 0
bar = initializeProgressBar(num_lines)
with open(bench_file, 'rb') as bfile:
for bench in bfile:
bench_count += 1
bar.update(bench_count)
bench = bench.strip()
mangled_path = path + bench.replace("/","_")
pb_id = self.addProblem(bench)
res = ProblemResult.readResult(mangled_path)
self.addResult(pb_id, solver, res)
def printTable(self):
print "problem, ",
for solver in self.solvers:
sv_name = solver
print sv_name, "_result, ",
print sv_name, "_cpu_time, ",
print sv_name, "_memory, ",
print sv_name, "_status, ",
print sv_name, "_exit_status,",
print ""
for pb in self.id_to_problem:
assert pb in self.table
path = self.id_to_problem[pb].path
restosolv = self.table[pb]
print path, ", ",
for solver in self.solvers:
result = restosolv.getResult(solver)
print result.result, ", ",
print result.cpu_time, ", ",
print result.memory, ", ",
print result.status, ", ",
print result.exit_status, ", ",
print ""
def uniqueSolves(self, sv1, sv2):
errors = []
sv1_solves = []
sv2_solves = []
for pb_id in self.table:
problem = self.id_to_problem[pb_id]
sv2res = self.table[pb_id]
res1 = sv2res.getResult(sv1)
res2 = sv2res.getResult(sv2)
if (res1.result == res2.result):
continue
if (res1.result == Result.Sat or
res1.result == Result.Unsat):
assert (res2.result == Result.Unknown)
sv1_solves.append((problem, res1))
else:
assert (res1.result == Result.Unknown)
assert (res2.result == Result.Sat or
res2.result == Result.Unsat)
sv2_solves.append((problem, res2))
print "Unique solves: ", sv1, " ", len(sv1_solves)
for p in sv1_solves:
print p[0].path, " ", p[1].cpu_time, " ", p[1].result
print "Unique solves: ", sv2, " ", len(sv2_solves)
for p in sv2_solves:
print p[0].path, " ", p[1].cpu_time, " ", p[1].result
def uniqueSolvesIncomplete(self, sv1, sv2):
errors = []
sv1_solves = []
sv2_solves = []
for pb_id in self.table:
problem = self.id_to_problem[pb_id]
sv2res = self.table[pb_id]
if not sv2res.hasResult(sv1) or not sv2res.hasResult(sv2):
continue
res1 = sv2res.getResult(sv1)
res2 = sv2res.getResult(sv2)
if (res1.result == res2.result):
continue
if (res1.result == Result.Sat or
res1.result == Result.Unsat):
assert (res2.result == Result.Unknown)
sv1_solves.append((problem, res1))
else:
assert (res1.result == Result.Unknown)
assert (res2.result == Result.Sat or
res2.result == Result.Unsat)
sv2_solves.append((problem, res2))
print "Unique solves: ", sv1, " ", len(sv1_solves)
for p in sv1_solves:
print p[0].path, " ", p[1].cpu_time, " ", p[1].result
print "Unique solves: ", sv2, " ", len(sv2_solves)
for p in sv2_solves:
print p[0].path, " ", p[1].cpu_time, " ", p[1].result
def checkCorrectness(self):
errors = []
for pb_id in self.table:
problem = self.id_to_problem[pb_id]
sv2res = self.table[pb_id]
result = None
for sv in sv2res.table:
res = sv2res.getResult(sv)
if (res.status != Status.Solved):
continue
if (res.result == Result.Unknown):
errors.append((problem, sv))
continue
if (res.result == Result.Sat or res.result == Result.Unsat):
if (result == None):
result = res.result
if (result != res.result):
print "Different answer on problem: "
print problem
for s in sv2res.table:
print s, ": ", sv2res.getResult(s).result, " time: ", sv2res.getResult(s).cpu_time
print "\nPotential crashes: "
for er in errors:
print " ", er[1], " on ", er[0]
def removeFamilies(self, fams):
remove = Set()
for pb_id in self.table:
problem = self.id_to_problem[pb_id]
for fam in fams:
if (problem.path.find(fam) != -1):
remove.add((pb_id, problem))
break
for (pb_id, pb) in remove:
del self.table[pb_id]
del self.id_to_problem[pb_id]
del self.problem_to_id[pb]
def removeCrashes(self):
errors = []
for pb_id in self.table:
problem = self.id_to_problem[pb_id]
sv2res = self.table[pb_id]
crash = False
for sv in sv2res.table:
res = sv2res.getResult(sv)
if (res.result == Result.Unknown and
res.status == Status.Solved and
res.cpu_time < 290):
crash = True
if crash:
errors.append((pb_id, problem))
print "\nPotential crashes: ",len(errors)
for er in errors:
print " ", er[1], " on ", er[0]
print "\nRemoving crashes.."
for (pb_id, pb) in errors:
del self.table[pb_id]
del self.id_to_problem[pb_id]
del self.problem_to_id[pb]
def getCactusData(self, solvers):
data = {}
for sv in solvers:
data[sv] = []
for pb in self.table:
sv2res = self.table[pb]
for sv in solvers:
sv_res = sv2res.table[sv]
if (sv_res.isSolved()):
data[sv].append(float(sv_res.cpu_time))
for sv in solvers:
data[sv] = sort(data[sv])
return data
def csv(self):
print "problem, ",
for solver in self.solvers:
sv_name = solver
print sv_name, " result, ",
print sv_name, " cpu_time, ",
print sv_name, " mem, ",
print sv_name, " status, ",
print sv_name, " exit, ",
print ""
for pb in self.id_to_problem:
assert pb in self.table
path = self.id_to_problem[pb]
restosolv = self.table[pb]
print path, ", ",
for solver in self.solvers:
result = restosolv.getResult(solver)
print result.result, ", ",
print result.cpu_time, ", ",
print result.mem, ", ",
print result.status, ", ",
print result.exit_status, ", ",
print ""
def fromCSV(self, path):
fields = ["result", "cpu_time", "mem", "status", "exit"]
num_lines = numLinesInFile(path)
bar = initializeProgressBar(num_lines - 1)
num_problems = 0
solvers = Set ()
with open(path, 'rb') as csvfile:
reader = csv.DictReader(csvfile)
headers = reader.next()
for h in headers:
tokens = h.split()
if (len(tokens) == 0):
continue
if (len(tokens) == 1):
assert (tokens[0] == "problem")
continue
solver = tokens[0]
assert (len(tokens) == 2 and tokens[1] in fields)
self.addSolver(solver)
solvers.add(solver)
for row in reader:
num_problems +=1
bar.update(num_problems)
problem = row["problem"]
pb_id = self.addProblem(problem)
for sv in solvers:
result = row[" "+sv+" "+"result"].strip()
cpu_time = float(row[" "+sv+" "+"cpu_time"])
mem = float(row[" "+sv+" "+"mem"])
status = row[" "+sv+" "+"status"].strip()
exit_status = int(row[" "+sv+" "+"exit"])
res = ProblemResult(result, status, cpu_time, 0, mem, exit_status)
self.addResult(pb_id, sv, res)
def mkSummary(self, families, problem_set):
sum_table = SummaryTable(families, problem_set)
for sv in self.solvers:
sum_table.addSolver(sv)
for pb_id in self.table:
pb = self.id_to_problem[pb_id]
sv2res = self.table[pb_id]
for sv in sv2res.table:
res = sv2res.getResult(sv)
sum_table.addResult(sv, pb, res)
return sum_table
def summary(self):
crashes = {}
cres = {}
errors = []
for solver in self.solvers:
cres[solver] = CumulativeResult()
crashes[solver] = []
for pb in self.id_to_problem:
assert pb in self.table
path = self.id_to_problem[pb]
restosolv = self.table[pb]
# skipping problems the solvers disagree on
if (not restosolv.allAgree()):
errors.append((path, restosolv))
continue
for sv in self.solvers:
result = restosolv.getResult(sv)
cres[sv].addResult(result)
if (result.status == Status.Solved and result.result == "Unknown"):
# probably a crash
crashes[sv].append(path)
for sv in self.solvers:
print sv, " solved, ",
print sv, " time, ",
print sv, " crashes, ",
print ""
for sv in self.solvers:
print cres[sv].solved, ", ",
print cres[sv].cpu_time, ", ",
print len(crashes[sv]), ", ",
print ""
print "Solvers do not agree on the following problems "
for (pb, sv2res) in errors:
print "On problem ", pb
for sv in self.solvers:
print sv, " ", sv2res.getResult(sv).result
print ""
def getScatterResults(self):
results = []
for pb in self.id_to_problem:
solver2res = self.table[pb]
result = Result.Unknown
assert (solver2res.allAgree())
for sv in solver2res.table:
res = solver2res.getResult(sv)
if (res.result == Result.Unknown):
continue
if (result == Result.Unknown):
result = res.result
else:
continue
assert (result == res.result)
results.append(result)
return results
def getScatterResultsIncomplete(self, sv1, sv2):
results = []
for pb in self.id_to_problem:
if not pb in self.table:
continue;
solver2res = self.table[pb]
if not solver2res.hasResult(sv1) or not solver2res.hasResult(sv2):
continue
result = Result.Unknown
assert (solver2res.allAgree())
for sv in solver2res.table:
res = solver2res.getResult(sv)
if (res.result == Result.Unknown):
continue
if (result == Result.Unknown):
result = res.result
else:
continue
assert (result == res.result)
results.append(result)
return results
def getScatterData(self, xsolver, ysolver, timeout):
xs = []
ys = []
for pb in self.id_to_problem:
solver2res = self.table[pb]
x_res = solver2res.getResult(xsolver)
y_res = solver2res.getResult(ysolver)
x_point = timeout
y_point = timeout
if (not solver2res.allAgree()):
print "Solvers do not agree on ",pb, ": ", self.id_to_problem[pb]
for sv in solver2res.table:
print " ",sv,": ",solver2res.table[sv]
assert(false)
if (x_res.status == Status.Solved and x_res.result != "Unknown"):
x_point = x_res.cpu_time
if (y_res.status == Status.Solved and y_res.result != "Unknown"):
y_point = y_res.cpu_time
xs.append(x_point)
ys.append(y_point)
return (xs, ys)
def getScatterDataIncomplete(self, xsolver, ysolver, timeout):
xs = []
ys = []
for pb in self.id_to_problem:
if not pb in self.table:
continue
solver2res = self.table[pb]
if not solver2res.hasResult(xsolver) or not solver2res.hasResult(ysolver):
continue
x_res = solver2res.getResult(xsolver)
y_res = solver2res.getResult(ysolver)
x_point = timeout
y_point = timeout
if (not solver2res.allAgree()):
print "Solvers do not agree on ",pb, ": ", self.id_to_problem[pb]
for sv in solver2res.table:
print " ",sv,": ",solver2res.table[sv]
assert(false)
if (x_res.status == Status.Solved and x_res.result != "Unknown"):
x_point = x_res.cpu_time
if (y_res.status == Status.Solved and y_res.result != "Unknown"):
y_point = y_res.cpu_time
xs.append(x_point)
ys.append(y_point)
return (xs, ys)
def makeScatterPlot(title, x_data, y_data, results, x_label, y_label, limit):
font = {'family' : 'sans-serif',
'weight' : 'normal',
'size' : 22}
rc('font', **font)
figure(figsize=(7, 7), dpi=80)
#ax = fig.add_subplot(1,1,1) # one row, one column, first plot
ax = gca()
gcf().subplots_adjust(bottom=0.18)
gcf().subplots_adjust(left=0.18)
for k, spine in ax.spines.items(): #ax.spines is a dictionary
spine.set_zorder(-1)
spine.set_position(('outward', 10))
ax.spines['top'].set_color('none')
ax.spines['right'].set_color('none')
if limit == None:
limit = max(max(x_data), max(y_data))
low_limit = min(min(x_data), min(y_data))
else:
low_limit = 0
xlim(low_limit, limit)
ylim(low_limit, limit)
x_diagonal = range(int(limit))
plot(x_diagonal, x_diagonal, color="grey", linestyle="-", linewidth="0.3")
grid(True)
# ax.set_tick_params('both','minor','off')
if (results == None):
scatter(x_data, y_data, color="red", marker="^", clip_on=False)
else:
# split Failure and Success
xsuccess, xfailed, xunknown = [], [], []
ysuccess, yfailed, yunknown = [], [], []
for i, res in enumerate(results):
if (res == Result.Unsat):
xfailed.append(x_data[i])
yfailed.append(y_data[i])
elif res == Result.Sat:
xsuccess.append(x_data[i])
ysuccess.append(y_data[i])
else:
xunknown.append(x_data[i])
yunknown.append(y_data[i])
scatter(xfailed, yfailed, color="red", marker="x", clip_on=False)
scatter(xsuccess, ysuccess, color="green", marker="^", clip_on=False)
scatter(xunknown, yunknown, color="black", marker="o", clip_on=False)
# ax.set_title(solverx+" vs "+solvery)