Learning a SAT Solver from Single-Bit Supervision

We present NeuroSAT , a message passing neural network that learns to solve SAT problems after only being trained as a classifier to predict satisfiability . Although it is not competitive with state-of-the-art SAT solvers , NeuroSAT can solve problems that are substantially larger and more difficult than it ever saw during training by simply running for more iterations . Moreover , NeuroSAT generalizes to novel distributions ; after training only on random SAT problems , at test time it can solve SAT problems encoding graph coloring , clique detection , dominating set , and vertex cover problems , all on a range of distributions over small random graphs . 1 INTRODUCTION . The propositional satisfiability problem ( SAT ) is one of the most fundamental problems of computer science . Cook ( 1971 ) showed that the problem is NP-complete , which means that searching for any kind of efficiently-checkable certificate in any context can be reduced to finding a satisfying assignment of a propositional formula . In practice , search problems arising from a wide range of domains such as hardware and software verification , test pattern generation , planning , scheduling , and combinatorics are all routinely solved by constructing an appropriate SAT problem and then calling a SAT solver ( Gomes et al. , 2008 ) . Modern SAT solvers based on backtracking search are extremely well-engineered and have been able to solve problems of practical interest with millions of variables ( Biere et al. , 2009 ) . We consider the question : can a neural network learn to solve SAT problems ? To answer , we develop a novel message passing neural network ( MPNN ) ( Scarselli et al. , 2009 ; Li et al. , 2015 ; Gilmer et al. , 2017 ) , NeuroSAT , and train it as a classifier to predict satisfiability on a dataset of random SAT problems . We provide NeuroSAT with only a single bit of supervision for each SAT problem that indicates whether or not the problem is satisfiable . When making a prediction about a new SAT problem , we find that NeuroSAT guesses unsatisfiable with low confidence until it finds a solution , at which point it converges and guesses satisfiable with very high confidence . The solution itself can almost always be automatically decoded from the network ’ s activations , making NeuroSAT an end-to-end SAT solver . See Figure 1 for an illustration of the train and test regimes . Although it is not competitive with state-of-the-art SAT solvers , NeuroSAT can solve SAT problems that are substantially larger and more difficult than it ever saw during training by simply performing more iterations of message passing . Despite only running for a few dozen iterations during training , at test time NeuroSAT continues to find solutions to harder problems after hundreds and even thousands of iterations . The learning process has yielded not a traditional classifier but rather a procedure that can be run indefinitely to search for solutions to problems of varying difficulty . Moreover , NeuroSAT generalizes to entirely new domains . Since NeuroSAT operates on SAT problems and since SAT is NP-complete , NeuroSAT can be queried on SAT problems encoding any kind of search problem for which certificates can be checked in polynomial time . Although we train it using only problems from a single random problem generator , at test time it can solve SAT problems encoding graph coloring , clique detection , dominating set , and vertex cover problems , all on a range of distributions over small random graphs . The same neural network architecture can also be used to help construct proofs for unsatisfiable problems . When we train it on a different dataset in which every unsatisfiable problem contains a small contradiction ( call this trained model NeuroUNSAT ) , it learns to detect these contradictions instead of searching for satisfying assignments . Just as we can extract solutions from NeuroSAT ’ s activations , we can extract the variables involved in the contradiction from NeuroUNSAT ’ s activations . When the number of variables involved in the contradiction is small relative to the total number of variables , knowing which variables are involved in the contradiction can enable constructing a resolution proof more efficiently . 2 PROBLEM SETUP . Background . A formula of propositional logic is a boolean expression built using the constants true ( 1 ) and false ( 0 ) , variables , negations , conjunctions , and disjunctions . A formula is satisfiable provided there exists an assignment of boolean values to its variables such that the formula evaluates to 1 . For example , the formula ( x1 ∨ x2 ∨ x3 ) ∧ ¬ ( x1 ∧ x2 ∧ x3 ) is satisfiable because it will evaluate to 1 under every assignment that does not map x1 , x2 and x3 to the same value . For every formula , there exists an equisatisfiable formula in conjunctive normal form ( CNF ) , expressed as a conjunction of disjunctions of ( possibly negated ) variables.1 Each conjunct of a formula in CNF is called a clause , and each ( possibly negated ) variable within a clause is called a literal . The formula above is equivalent to the CNF formula ( x1∨x2∨x3 ) ∧ ( ¬x1∨¬x2∨¬x3 ) , which we can represent more concisely as { 1|2|3 , 1|2|3 } . A formula in CNF has a satisfying assignment if and only if it has an assignment such that every clause has at least one literal mapped to 1 . A SAT problem is a formula in CNF , where the goal is to determine if the formula is satisfiable , and if so , to produce a satisfying assignment of truth values to variables . We use n to denote the number of of variables in a SAT problem , and m to denote the number of clauses . Classification task . For a SAT problem P , we define φ ( P ) to be true if and only if P is satisfiable . Our first goal is to learn a classifier that approximates φ . Given a distribution Ψ over SAT problems , we can construct datasetsDtrain andDtest with examples of the form ( P , φ ( P ) ) by sampling problems P ∼ Ψ and computing φ ( P ) using an existing SAT solver . At test time , we get only the problem P and the goal is to predict φ ( P ) , i.e . to determine if P is satisfiable . Ultimately we care about the solving task , which also includes finding solutions to satisfiable problems . 1This transformation can be done in linear time such that the size of the resulting formula has only grown linearly with respect to the original formula ( Tseitin , 1968 ) . 3 MODEL . A SAT problem has a simple syntactic structure and therefore could be encoded into a vector space using standard methods such as an RNN . However , the semantics of propositional logic induce rich invariances that such a syntactic method would ignore , such as permutation invariance and negation invariance . Specifically , the satisfiability of a formula is not affected by permuting the variables ( e.g . swapping x1 and x2 throughout the formula ) , by permuting the clauses ( e.g . swapping the first clause with the second clause ) , or by permuting the literals within a clause ( e.g . replacing the clause 1|2 with 2|1 . The satisfiability of a formula is also not affected by negating every literal corresponding to a given variable ( e.g . negating all occurrences of x1 in { 1|2 , 1|3 } to yield { 1|2 , 1|3 } ) . We now describe our neural network architecture , NeuroSAT , that enforces both permutation invariance and negation invariance . We encode a SAT problem as an undirected graph with one node for every literal , one node for every clause , an edge between every literal and every clause it appears in , and a different type of edge between each pair of complementary literals ( e.g . between xi and xi ) . NeuroSAT iteratively refines a vector space embedding for each node by passing “ messages ” back and forth along the edges of the graph as described in Gilmer et al . ( 2017 ) . At every time step , we have an embedding for every literal and every clause . An iteration consists of two stages . First , each clause receives messages from its neighboring literals and updates its embedding accordingly . Next , each literal receives messages from its neighboring clauses as well as from its complement , then updates its embedding accordingly . Figure 2 provides a high-level illustration of the architecture . More formally , our model is parameterized by two vectors ( Linit , Cinit ) , three multilayer perceptrons ( Lmsg , Cmsg , Lvote ) and two layer-norm LSTMs ( Ba et al. , 2016 ; Hochreiter & Schmidhuber , 1997 ) ( Lu , Cu ) . At every time step t , we have a matrix L ( t ) ∈ R2n×d whose ith row contains the embedding for the literal ` i and a matrix C ( t ) ∈ Rm×d whose jth row contains the embedding for the clause cj , which we initialize by tiling Linit and Cinit respectively . We also have hidden states L ( t ) h ∈ R2n×d and C ( t ) h ∈ Rm×d for Lu and Cu respectively , both initialized to zero matrices . Let M be the ( bipartite ) adjacency matrix defined by M ( i , j ) = 1 { ` i ∈ cj } and let Flip be the operator that takes a matrix L and swaps each row of L with the row corresponding to the literal ’ s negation . A single iteration consists of applying the following two updates : ( C ( t+1 ) , C ( t+1 ) h ) ← Cu ( [ C ( t ) h , M > Lmsg ( L ( t ) ) ] ) ( L ( t+1 ) , L ( t+1 ) h ) ← Lu ( [ L ( t ) h , Flip ( L ( t ) ) , MCmsg ( C ( t+1 ) ) ] ) After T iterations , we compute L ( T ) ∗ ← Lvote ( L ( T ) ) ∈ R2n , which contains a single scalar for each literal ( the literal ’ s vote ) , and then we compute the average of the literal votes y ( T ) ← mean ( L ( T ) ∗ ) ∈ R. We train the network to minimize the sigmoid cross-entropy loss between the logit y ( T ) and the true label φ ( P ) . Our architecture enforces permutation invariance by operating on nodes and edges according to the topology of the graph without any additional ordering over nodes or edges . Likewise , it enforces negation invariance by treating all literals the same no matter whether they originated as a positive or negative occurrence of a variable . We stress that none of the learned parameters depend on the size of the SAT problem and that a single model can be trained and tested on problems of arbitrary and varying sizes . At both train and test time , the input to the model is simply any bipartite adjacency matrix M over any number of literals and clauses . The learned parameters only determine how each individual literal and clause behaves in terms of its neighbors in the graph . Variation in problem size is handled by the aggregation operators : we sum the outgoing messages of each of a node ’ s neighbors to form the incoming message , and we take the mean of the literal votes at the end of message passing to form the logit y ( T ) .

Summary: This paper presents the NeuroSAT architecture, which uses a deep, message passing neural net for predicting the satisfiability of CNF instances. The architecture is also able to predict a satisfiable assignment in the SAT case, and the literals involved in some minimal conflicting set of clauses (i.e. core) in the UNSAT case. The NeuroSAT architecture is based on a vector space embedding of literals and clauses, which exploits (with message passing) some important symmetries of SAT instances (permutation invariance and negation invariance). This architecture is tested on various classes of random SAT instances, involving both unstructured (RS) problems, and structured ones (e.g. graph colorings, vertex covers, dominating sets, etc.).