combining component caching and clause learning for effective model counting tian sang university of...
TRANSCRIPT
Combining Component Caching Combining Component Caching and Clause Learning for Effective and Clause Learning for Effective
Model Counting Model Counting
Tian SangTian SangUniversity of WashingtonUniversity of Washington
Fahiem Bacchus (U Toronto), Paul Beame (UW), Fahiem Bacchus (U Toronto), Paul Beame (UW), Henry Kautz (UW), & Toniann Pitassi (U Toronto)Henry Kautz (UW), & Toniann Pitassi (U Toronto)
Why #SAT?Why #SAT?
Prototypical #P complete problemPrototypical #P complete problem Natural encoding for counting problemsNatural encoding for counting problems
Test-set sizeTest-set size CMOS power consumptionCMOS power consumption
Can encode probabilistic inferenceCan encode probabilistic inference
GeneralityGenerality
SATSAT #SAT#SAT Bayesian NetworksBayesian Networks Bounded-alternation Quantified Boolean Bounded-alternation Quantified Boolean
formulasformulas Quantified Boolean formulasQuantified Boolean formulas Stochastic SATStochastic SAT
#P complete
NP complete
PSPACE complete
Our ApproachOur Approach
Good old Davis-Putnam-Logemann-Good old Davis-Putnam-Logemann-LovelandLoveland
Clause learning (“no good-caching”)Clause learning (“no good-caching”) Bounded component analysisBounded component analysis Formula cachingFormula caching
DPLLDPLL((FF))while exists unit clause while exists unit clause (y) (y) F F
F F F F||yy
if if FF is empty, report satisfiable and halt is empty, report satisfiable and haltif if FF contains the empty clause contains the empty clause
Add a conflict clause C to FAdd a conflict clause C to Freturn falsereturn false
choose a literal choose a literal xx
return return DPLLDPLL((FF||xx) || ) || DPLLDPLL((FF||xx))
DPLL with Clause LearningDPLL with Clause Learning
Conflict GraphConflict Graph
Decision scheme(p q b)
1-UIP scheme(t)
p
q
b
a
x1
x2
x3
y
yfalset
Known Clauses(p q a)
( a b t)(t x1)(t x2)(t x3)
(x1 x2 x3 y)(x2 y)
Current decisionsp falseq falseb true
Component AnalysisComponent Analysis
Can use DPLL to count modelsCan use DPLL to count models Just don’t stop when first assignment is foundJust don’t stop when first assignment is found
If formula breaks into If formula breaks into separate componentsseparate components (no shared variables), can count each (no shared variables), can count each separately and multiply results:separately and multiply results: #SAT(C#SAT(C1 C C2) = #SAT(C) = #SAT(C1) * #SAT(C) * #SAT(C2))
(Bayardo & Shrag 1996)(Bayardo & Shrag 1996)
Formula CachingFormula Caching
New idea: cache number of models of New idea: cache number of models of residual formulas at each noderesidual formulas at each node Bacchus, Dalmao & Pitassi 2003Bacchus, Dalmao & Pitassi 2003 Beame, Impagliazzo, Pitassi, & Segerlind 2003Beame, Impagliazzo, Pitassi, & Segerlind 2003
Matches time/space tradeoffs of best known Matches time/space tradeoffs of best known exact probabilistic inference algorithms:exact probabilistic inference algorithms:
(1) ( )
( log )
2
2
O O w
O w n
n wwhere is tree - width of formula
if only linear space is used for cache
#SAT with Component Caching#SAT with Component Caching#SAT(F) #SAT(F) // Returns fraction of all truth// Returns fraction of all truth
// assignments that satisfy F// assignments that satisfy F a = 1;a = 1;for each G for each G to_components(F) to_components(F) { {
if (G == if (G == ) m = 1;) m = 1;else if (else if ( G) m = 0; G) m = 0;else else if (in_cache(G)) m = if (in_cache(G)) m =
cache_value(G);cache_value(G);else { select v else { select v G; G;
m = ½ * #SAT(G|v) + m = ½ * #SAT(G|v) + ½ * #SAT(G|½ * #SAT(G|v);v);
insert_cache(G,m);insert_cache(G,m);}}
if (m == 0) return 0;if (m == 0) return 0;a = a * m; }a = a * m; }
return a;return a;
Putting it All TogetherPutting it All Together
Goal: combineGoal: combine Clause learningClause learning Component analysisComponent analysis Formula cachingFormula caching
to create a to create a practicalpractical #SAT algorithm #SAT algorithm Not Not quitequite as straightforward as it looks! as straightforward as it looks!
Issue 1: How Much to Cache?Issue 1: How Much to Cache?
EverythingEverything Infeasible – often > 10,000,000 nodesInfeasible – often > 10,000,000 nodes
Only sub-formulas on current branchOnly sub-formulas on current branch Linear spaceLinear space Similar to recursive conditioningSimilar to recursive conditioning
[Darwiche 2002[Darwiche 2002]]
Can we do better?Can we do better?
Age versus Cumulative HitsAge versus Cumulative Hits
age = time elapsed since the entry was cachedage = time elapsed since the entry was cached
Efficient Cache ManagementEfficient Cache Management
Age-bounded cachingAge-bounded caching Separate-chaining hash tableSeparate-chaining hash table Lazy deletion of entries older than Lazy deletion of entries older than KK when when
searching chainssearching chains Constant amortized timeConstant amortized time
Issue 2: Interaction of Component Issue 2: Interaction of Component Analysis & Clause LearningAnalysis & Clause Learning
As clause learning progresses, formula As clause learning progresses, formula becomes becomes hugehuge
1,000 clauses 1,000 clauses 1,000,000 learned clauses 1,000,000 learned clauses
Finding connected components becomes Finding connected components becomes too costlytoo costly
Components using learned clauses Components using learned clauses unlikely to reoccur!unlikely to reoccur!
Bounded Component AnalysisBounded Component Analysis
Use only clauses Use only clauses derived from originalderived from original formula forformula for Component analysisComponent analysis ““Keys” for cached entriesKeys” for cached entries
Use Use all the learned clausesall the learned clauses for unit for unit propagationpropagation
Can this possibly be sound?Can this possibly be sound?
Almost!
Safety TheoremSafety Theorem
Given:Given:
original formula Foriginal formula F
learned clauses Glearned clauses G
partial assignment partial assignment F|F| is satisfiable is satisfiable
AAi is a component of F| is a component of F|
satisfies Asatisfies Ai
F| G|
A2A1 A3
Then:
can be extended to satisfy G|
It is safe to use learned clauses for unit propagation for SAT sub-formulas
UNSAT Sub-formulasUNSAT Sub-formulas
But if F|But if F| is is unsatisfiableunsatisfiable, all bets are off..., all bets are off... Without component caching, there is still no Without component caching, there is still no
problem – because the final value is 0 in any problem – because the final value is 0 in any casecase
With component caching, could cause With component caching, could cause incorrect values to be cachedincorrect values to be cached
Solution:Solution:Flush siblings (& their descendents) of UNSAT Flush siblings (& their descendents) of UNSAT
components from cachecomponents from cache
Safe Caching + Clause Safe Caching + Clause Learning ImplementationLearning Implementation
......else if (else if ( G) { m = 0; G) { m = 0;add a conflict clause; add a conflict clause; }}......if (m==0) {if (m==0) {
flush_cache( siblings(G) )flush_cache( siblings(G) )if (G is not last child of F) if (G is not last child of F)
flush_cache(G);flush_cache(G);return 0; }return 0; }
a = a * m;a = a * m;......
EvaluationEvaluation
Implementation based on zChaff Implementation based on zChaff (Moskewicz, Madigan, Zhao, Zhang, & Malik 2001)(Moskewicz, Madigan, Zhao, Zhang, & Malik 2001)
BenchmarksBenchmarks Random formulasRandom formulas Pebbling graph formulasPebbling graph formulas Circuit synthesisCircuit synthesis Logistics planningLogistics planning
Random 3-SAT, 75 VariablesRandom 3-SAT, 75 Variables
sat/unsat threshhold
Random 3-SAT ResultsRandom 3-SAT Results
relsat CC+CL
3,809 2
5,997 5
5,806 5
31,660 20
75V, R=1.0
relsat CC+CL
17,822 75
24,066 70
24,606 52
time out 121
75V, R=1.4
relsat CC+CL
7,060 35
15,047 101
75V, R=1.6
relsatrelsat CC+CLCC+CL
13,15013,150 179179
32,99832,998 547547
75V, R=2.0
Results: Pebbling FormulasResults: Pebbling Formulaslayerslayers var/clausevar/clause solutionssolutions relsatrelsat CC+CLCC+CL LinearLinear CCCC CLCL
77 56/9256/92 7.79E+107.79E+10 11 0.010.01 0.070.07 0.040.04 0.270.27
88 72/12172/121 4.46E+144.46E+14 4949 0.020.02 0.040.04 0.180.18 44
99 90/15490/154 5.94E+235.94E+23 14381438 0.060.06 66 0.500.50 6262
1010 110/191110/191 6.95E+186.95E+18 XX 0.060.06 0.670.67 0.920.92 69616961
1515 240/436240/436 3.01E+543.01E+54 XX 0.530.53 465465 106106 XX
2020 420/781420/781 5.06E+955.06E+95 XX 33 XX XX XX
2525 650/1226650/1226 1.81E+1511.81E+151 XX 3535 XX XX XX
3030 930/1771930/1771 1.54E+2181.54E+218 XX 3737 XX XX XX
X means time-out after 12 hours
SummarySummary
A A practical exact model-counting algorithmpractical exact model-counting algorithm can be built by the careful combination ofcan be built by the careful combination of Bounded component analysisBounded component analysis Component cachingComponent caching Clause learningClause learning
Outperforms the best previous algorithm Outperforms the best previous algorithm by orders of magnitudeby orders of magnitude
What’s Next?What’s Next?
Better heuristicsBetter heuristics component orderingcomponent ordering variable branchingvariable branching
Incremental component analysisIncremental component analysis Currently consumes 10-50% of run time!Currently consumes 10-50% of run time!
Applications to Bayesian networksApplications to Bayesian networks Compiler for discrete BN to weighted #SATCompiler for discrete BN to weighted #SAT Direct BN implementationDirect BN implementation
Applications to other #P problemsApplications to other #P problems Testing, model-based diagnosis, …Testing, model-based diagnosis, …
Questions?Questions?
Results: Planning FormulasResults: Planning Formulas
pddlpddl var/clausevar/clause solutionssolutions relsatrelsat CC+CLCC+CL CCCC CLCL LinearLinear
11 939/3785939/3785 5.64E+205.64E+20 <1<1 0.570.57 588588 0.750.75 102102
22 1337/247771337/24777 3.23E+103.23E+10 44 6565 64326432 6666 245245
33 1413/294871413/29487 2.80E+112.80E+11 44 119119 55455545 118118 261261
44 2303/209632303/20963 2.34E+282.34E+28 200200 239239 XX 37663766 22792279
55 2701/295342701/29534 7.24E+387.24E+38 49574957 15071507 XX XX XX
1212 2324/318572324/31857 8.29E+368.29E+36 1232312323 950950 XX 3308233082 1616216162
X means time-out after 12 hours
Results: Circuit SynthesisResults: Circuit Synthesis
var/clausevar/clause solutionssolutions relsatrelsat CC+CLCC+CL CCCC CLCL LinearLinear
rara 1236/114161236/11416 1.86E+2861.86E+286 1818 88 99 99 88
rbrb 1854/113241854/11324 5.39E+3715.39E+371 8080 1616 1717 2222 2222
2bit_2bit_
compcomp66
150/370150/370 9.41E+209.41E+20 272272 201201 109109 746746 424424
2bit_2bit_
add10add10590/1422590/1422 00 667667 475475 XX 509509 505505
rand1rand1 304/578304/578 1.86E+541.86E+54 17311731 3131 186186 13311331 11281128
rcrc 2472/179422472/17942 7.71E+3937.71E+393 22602260 14851485 34353435 13271327 17471747
X means time-out after 12 hours
Bayesian Nets to Weighted Bayesian Nets to Weighted CountingCounting
Introduce new vars so all internal vars are Introduce new vars so all internal vars are deterministicdeterministic
A
B
AA ~A~A
B B .2.2 .6.6
A A .1.1
Bayesian Nets to Weighted Bayesian Nets to Weighted CountingCounting
Introduce new vars so all internal vars are Introduce new vars so all internal vars are deterministicdeterministic
A
B
AA ~A~A
B B .2.2 .6.6
A A .1.1 A
B
P Q
A A .1.1 PP .2.2 Q Q .6.6
( ) ( )B A P A Q
Bayesian Nets to Weighted Bayesian Nets to Weighted CountingCounting
Weight of a model Weight of a model is product of is product of variable weightsvariable weights
Weight of a Weight of a formula is sum of formula is sum of weights of its weights of its modelsmodels
A
B
P Q
A A .1.1 PP .2.2 Q Q .6.6
( ) ( )B A P A Q
Bayesian Nets to Weighted Bayesian Nets to Weighted CountingCounting
Let F be the Let F be the formula defining all formula defining all internal variablesinternal variables
Pr(query) =Pr(query) =weight(F & query)weight(F & query)
A
B
P Q
A A .1.1 PP .2.2 Q Q .6.6
( ) ( )B A P A Q
Bayesian Nets to CountingBayesian Nets to Counting
Unweighted counting is case where all Unweighted counting is case where all non-defined variables have weight 0.5non-defined variables have weight 0.5
Introduce sets of variables to define other Introduce sets of variables to define other probabilities to desired accuracyprobabilities to desired accuracy
In practice: just modify #SAT algorithm to In practice: just modify #SAT algorithm to weighted #SATweighted #SAT