Denoising Diffusion for Sampling SAT Solutions
Abstract
Generating diverse solutions to the Boolean Satisfiability Problem (SAT) is a hard computational problem with practical applications for testing and functional verification of software and hardware designs.
We explore the way to generate such solutions using Denoising Diffusion coupled with a Graph Neural Network to implement the denoising function.
We find that the obtained accuracy is similar to the currently best purely neural method and the produced SAT solutions are highly diverse, even if the system is trained with non-random solutions from a standard solver.
Introduction
Boolean Satisfiability Problem (SAT) is a significant NP-complete problem with numerous practical applications – product configuration, hardware verification, and software package management, to name a few.
There is no known single efficient algorithm that solves every SAT problem, but heuristics have been developed that are well-suited to instances arising in practice.
Here we consider an even harder task of sampling solutions of a SAT instance which is the key component for functional verification of software and hardware designs.
Most SAT solvers return the same solution if run repeatedly; therefore, special approaches are needed to obtain several solutions, especially if it is required to sample more or less uniformly from the solution space.
UniGen [Chakraborty et al., 2014, Soos et al., 2020] and QuickSampler [Dutra et al., 2018] are some algorithms for this purpose.
UniGen guarantees approximate uniformity of the sampled solutions but is very slow in certain cases.
So, we are interested in whether the application of neural networks and denoising diffusion can produce diverse samples in less time.
Deep learning methods can accelerate solving NP-hard problems.
Purely neural SAT solvers have been developed [Selsam et al., 2019, Amizadeh et al., 2019, Ozolin , š et al., 2022] that can solve small instances.
Hybrid solvers that provide neural heuristics within existing solvers [Selsam and Bjørner, 2019, Han, 2020] are more practical for real-life instances.
Also, deep learning methods are used for
Combinatorial Optimization [Li et al., 2018, Bengio et al., 2021, Cappart et al., 2021] including MIP [Nair et al., 2020], TSP [Gaile et al., 2022] and VRP [Nazari et al., 2018].
Denoising diffusion
[Yang et al., 2022], coupled with neural networks, provide a learnable way for sampling from a given distribution.
Diffusion models have achieved state-of-the-art results for image generation [Ho et al., 2022, Vahdat et al., 2021, Rombach et al., 2021].
Diffusion has been applied to discrete binary [Sohl-Dickstein et al., 2015] and categorical [Hoogeboom et al., 2021b]
data, text generation [Austin et al., 2021], symbolic music generation [Mittal et al., 2021], graph generation [Niu et al., 2020], and autoregressive modelling [Hoogeboom et al., 2021a].
But we are not aware of any attempt to use it for sampling SAT solutions.
In this paper, we apply denoising diffusion to sample solutions of SAT.
We use Categorical Diffusion introduced by [Hoogeboom et al., 2021b] and couple it with QuerySat [Ozolin , š et al., 2022] graph neural network to implement the denoising function.
We find that this approach achieves solving accuracy comparable to the state-of-the-art purely neural SAT solver (QuerySat) and finds diverse solutions of similar characteristics as UniGen up to 8000 times faster, in some cases.
Background: Diffusion Models
Given data x 0 (variable assignment in our case), a diffusion model [Sohl-Dickstein et al., 2015] consists of predefined variational distributions q ( x t | x t − 1 ) that gradually introduce noise over time steps t ∈ { 1 , ..., T } .
The diffusion trajectory is defined such that q ( x t | x t − 1 ) adds a small amount of noise around x t − 1 .
This way, information is gradually destroyed and at the final time step, x T carries almost no information about x 0 .
A nice property of the diffusion process is that it can be reversed if the gradient of the distribution can be estimated which is often expressed as a function that denoises the data.
Usually, the Normal distribution for noise is used which is simple to work with and produces excellent results for images [Ho et al., 2022] and sound [Kong et al., 2021].
To deal with the discrete SAT solution values, here we employ diffusion for categorical data, namely the Multinomial Diffusion [Hoogeboom et al., 2021b].
Having K categories (2 in our case – True and False), x t is encoded as one-hot vector for each variable.
The multinomial diffusion process is defined using a categorical distribution that has a small probability β t of resampling a category uniformly and a large (1 − β t ) probability of sampling the previous value x t − 1 :
[Equation]
where C denotes a categorical distribution with probability parameters after | .
For such diffusion process the probability of any x t given x 0 is expressed as:
[Equation]
where α t = 1 − β t and ¯ α t = (cid:81) tτ
=
α τ .
For the reverse distribution step, we follow the common practice to parametrize it using x 0 .
According to [Hoogeboom et al., 2021b], the distribution for the previous time step t − 1 can be computed from the value x t at the next step and the initial value x 0 as: q ( x t − 1 | x t , x 0 ) =
C ( x t − 1 | θ post ( x t , x 0 )) , where θ post ( x t , x 0 ) =
˜ θ/
K (cid:88) k
= ˜
θ k , and ˜ θ
=
[ α t x t + (1 − α t ) /K ] ⊙ [¯ α t − 1 x 0 + (1 − ¯
α t − 1 ) /K ] (3)
During the reverse process, an approximation ˆ x 0 is used instead of x 0 which is produced by a neural network µ : ˆ x 0 = µ ( x t , ¯ α t ) .
The neural network is trained by feeding it with the cumulative noise magnitude 1 ¯ α t and noisy sample x t which is produced by the forward diffusion and asking the network to produce a clean sample ˆ x 0 .The loss function for training is the KL divergence between the true distribution and the predicted one:
[Equation]
Background: GNNs for Solving SAT
We consider SAT formulas in conjunctive normal form and represent them as a bipartite variablesclauses graph, likewise known as an SAT factor graph Biere et al.
In such a graph, the edge between variables and clauses graph exists whenever the variable is present in the clause.
Two types of edges are used to distinguish a variable from its negation.
Variables-clauses graph of SAT formula with n variables and m clauses can be represented as a sparse n × m adjacency matrix.
Graph Neural Networks(GNN), especially message-passing networks, are commonly used for solving graphs-based tasks.
Such network architectures are simple, yet have strong inductive bias over the graph Zhou et al.
For boolean satisfiability solving, the currently best neural architecture is
QuerySat [Ozolin , š et al., 2022] which is capable of predicting solutions to random 3-SAT formulas up to 400 variables.
QuerySat is a recurrent GNN, specially tailored for SAT solving, which at each iteration exchanges the information between variables and clauses, gives a candidate prediction, and evaluates how far it is from a valid solution.
It is trained with 32 recurrent iterations but at inference time the number of iterations can be increased to yield better results.
The prediction at the final iteration is used as the result.
We use QuerySat architecture with 32 recurrent iterations as the µ network for denoising.
Diffusion for SAT Sampling
To train the neural network µ , we generate a dataset with SAT formulas and their solutions.
The solution is one-hot encoded and treated as x 0 but the SAT instance is used to build the GNN network so the µ function gets conditioned on the given instance.
Then for each example we randomly sample ¯ α t according to noising schedule ¯ α t = 1 − (cid:112) t/T and obtain x t by sampling q ( x t | x 0 ) as given in
Eq. 2.
The neural network µ ( x t , ¯ α t ) is trained using KL divergence given by Eq.
4 to estimate x 0 .
After the model has been trained, we can use it for sampling a solution to the given SAT formula.
We employ the standard denoising diffusion algorithm.
Given the total number of steps T , the algorithm works backward from step T toward step 1.
The distribution x T is created with equal probabilities of
True and False for each variable and then at each step t a sample from it is drawn which is presented to the neural network µ .
The neural network returns the estimated probabilities of SAT variable assignment ˆ x 0 .
The value of the previous timestep x t − 1 is obtained by sampling the distribution q ( x t − 1 | x t , ˆ x 0 ) given by Eq. 3.
The algorithm returns the assignment ˆ x 0 with argmax applied to each variable.
Evaluation
We evaluate the proposed SAT sampling algorithm on two datasets: random 3-SAT and 3-Clique instances.
The 3-SAT instances consist of random clauses of 3 literals at the satisfiability threshold, i.e., with the clause/variable ratio of about 4.3.
We also test on 3-SAT instances with clause/variable ratio 3.
The 3-Clique instances represent SAT encoding of the task to find triangles in a graph.
See
Appendix A for the dataset details.
At first, let us evaluate the accuracy of the produced solutions i.e. the fraction of the instances that are fully solved.
For accuracy evaluation, we consider an instance solved if a solution is found at any of the diffusion steps, this increases our chances to spot a solution since a great amount of randomness is involved in the diffusion process.
We compare our solution, named DiffusionSat, with QuerySat.
For DiffusionSat we consider two choices for the number of diffusion steps – 32 or 128.
For QuerySat we use two setups of 32 or 4K recurrent iterations, as it was done in [Ozolin , š et al., 2022].
Note that the amount of computing for QuerySat 4K is roughly the same as for DiffusionSat 128.
Since the small instances used for training are solved almost perfectly, for accuracy evaluation, we use about 4x larger ones.
We consider two solvers for generating the solutions that are used for DiffusionSat training – Glucose [Audemard and Simon, 2018] and UniGen3 [Soos et al., 2020].
Glucose is a standard SAT solver that does not guarantee any particular distribution of the produced solutions but UniGen provides approximately uniformly distributed solutions.
Diffusion models are intended to reproduce the same distribution of samples that was supplied for training, so we may get different results in both cases.
The accuracy results are given in Table 1.
It depicts the average and the standard deviation oftest runs.
We see that QuerySat is better for 3-SAT but DiffusionSat is better for 3-Clique.
Notably,
DiffusionSat 128 achieves 100% solved instances of 3-Clique where QuerySat 4K gets about 95% while both these cases use the same amount of computing.
Also, we can notice that increasing the number of diffusion steps increases the accuracy.
Notice that UniGen always produces correct solutions, so it is not evaluated.
In order to evaluate sample diversity, we produce 100 solutions of each instance and count how many of them are unique.
Incorrect solutions, which may appear due to non-perfect accuracy of
DiffusionSat, are filtered out.
The evaluation is performed on 3-SAT instances of size 5–100 variables [Table] [Table] and on 3-Clique instances obtained from graphs with 4 to 40 vertices.
Our first evaluation revealed that 3-SAT at the satisfiability threshold and 3-Clique instances have only a few solutions – they have been designed to be maximally hard and are not well-suited to evaluate diversity.
So, we included a dataset with 3-SAT instances with clause/variable ratio of 3 which have many solutions.
Table 2 shows the solution diversity.
We see that QuerySat produces only a few different solutions, although it employs some randomness internally.
The best results are produced by DiffusionSat, even surpassing UniGen.
Interestingly, there is not much difference whether DiffusionSat has been trained with diverse solutions or with those coming from a standard SAT solver – both produce slightly better diversity than UniGen.
To get more insight how diverse are the solutions, we inspect how many variables are equal in two solution samples on 3-SAT instances, see Appendix C. For the clause/variable ratio of 4.3 about 85% variables are equal and for ratio 3 – about 65%.
Notice that completely random assignment would yield 50% but that may not be a valid solution.
We find that DiffusionSat and UniGen perform pretty similarly regarding this metric.
We evaluated the time taken to produce one solution sample on 3-SAT instance with 100 variables.
DiffusionSat (with 32 diffusion steps) processes one batch of about 95 instances in 5.7 seconds.
That means, one instance takes 0.06s.
UniGen takes about 0.22s per instance of clause ratio 4.3 but much longer – about 500s (with high variance from 70s to 1300s) for clause ratio 3, see also Appendix C.
When compared, DiffusionSat produces a solution more than 8000 times faster for the latter case (although using GPU and batched instances).
Conclusion
We have shown how to combine denoising diffusion with GNN and apply it for generating SAT solutions.
From theoretical point of view, if trained with uniformly distributed samples and the neural network being able to perfectly learn the denoising function, the samples produced by diffusion are also uniformly distributed.
Both these requirements are hard to satisfy in practice, but we have shown that DiffusionSat generates highly diverse samples of similar characteristics than UniGen which is known to generate nearly uniform distribution.
Moreover, there is no need to use uniform distribution for training, as training on solutions from a standard SAT solver gives equally good results.
Besides, for 3-SAT formulas with clause/variable ratio 3, DiffusionSat is much faster that UniGen.
There are some limitations of this work: (a) We have tested only two properties of diversity, more thorough tests should be done to draw conclusions about uniformity.
Also, more datasets should be considered.
(b) Training sets with larger instances may be infeasible to generate, QuerySat has an advantage here, not requiring to know the solutions for training.
(c) DiffusionSat is an incomplete solver – it cannot prove that an instance is UNSAT.
(d) SAT instances up only to 50K clauses can be solved with the current A6000 GPU(with 48GB memory).
Acknowledgments and Disclosure of Funding
This research is supported by the Latvian Council of Science, project lzp-2021/1-0479.
Computing resources are supported by NVIDIA Academic Grant "Deep Learning of Algorithms".
A Appendix: Datasets
3-Clique and 3-SAT tasks are generated using the CNFGen library Lauria et al.
[2017], which allows encoding several popular problems as SAT instances.
We generate hard 3-SAT instances at the satisfiability boundary where the relationship between the number of clauses ( m ) and variables ( n ) is m = 4 .
258 n + 58 .
26 n − 23 Crawford and Auton [1996].
The train and validation sets of 3-SAT tasks consist of formulas with 5 to 100 variables.
Since the small instances used for training are solved almost perfectly, for accuracy evaluation, we use larger ones – up to 405 variables.
Such larger test instances were also used in the QuerySat paper [Ozolin , š et al., 2022] and show the generalization ability of the methods.
The test set for sample diversity evaluation has instances of the same size as used for training, i.e. with 5 to 100 variables.
For diversity evaluation, we have another test set with clause-to-variable ratio m = 3 n .
These instances are much easier and have many solutions.
For the 3-Clique task, we generate Erd˝os–Rényi graphs with edge probability p .
The goal of this task is to find all triangles in the graph. We use p = 3 13 / ( v (2 − 3 v + v 2 )) 13 , where v is the vertex count in the graph.
Such generation produces graphs in which a few triangles are expected.
The graphs are then encoded as SAT instances using the CNFGen library.
Train and validation sets consist of SAT encodings of graphs with 4 to 40 vertices.
They end up encoded into SAT formulas of sizes up tovariables and 7K clauses.
The test set for accuracy evaluation has graphs with 4 to 100 vertices.
The test set for diversity evaluation has graphs with 4 to 40 vertices.
B Appendix: Implementation and Training
We have implemented DiffusionSat in Tensorflow based on the official code of QuerySat 2 .
From there, we employ the GNN neural backbone to implement the µ network, the dataset generation and accuracy evaluation code.
So, the accuracy results of DiffusionSat and QuerySat are obtained in the same conditions and are directly comparable.
The backbone network that is employed inside
DiffusionSat has 32 recurrent iterations that is the same as used for training QuerySat.
For generating SAT solutions we use Glucose4 solver from python-sat 3 library and UniGen3 4 .
Only satisfiable instances are used in training.
Training is performed for 166K steps with AdaBelief optimizer [Zhuang et al., 2020] having learning rate 3e-3.
Several instances are batched together to increase training and inference speed.
Training on a single Nvidia RTX A6000 GPU takes about 1 day.
To evaluate 3SAT instances with clause/variable ratio 3, we do not perform separate training, we use the same model trained for the 4.3 ratio – it works very well.
C Appendix: Additional Results
In order to evaluate diversity, we inspected how many variables are equal in two solution samples on 3-SAT instances.
The results for DiffusionSat and UniGen are quite similar.
[Table]
The running time comparison between DiffusionSat and UniGen is given in Fig 1.
This graph shows the time to produce one solution sample of a 3-SAT instance with increasing variable count.
DiffusionSat is run on a A6000 GPU, 32 diffusion steps are used, instances are batched and time is reported by dividing the wall-clock time with the instance count in the batch.
UniGen is run on a CPU, one instance at a time. In such setup, we can see that DiffusionSat is much faster and scales linearly depending on the instance size. UniGen, in contrary, shows at least exponential scaling on instances of clause/variable ratio 3 reaching already about 500 seconds on a 100 variable instance.
[Figure]