Tag Archives: machine learning

Predicting Clause Usefulness

In this post, I will be taking a shot at building prediction models for learnt clause usefulness by running over 150 unsatisfiable CNF problems, extracting over 140 features for each learnt clause, and then calculating whether the clause was used in the UNSAT proof. Here I need to thank Marijn Heule who has helped me adding a clause ID to each clause in his DRAT checker so I could perform supervised learning on the collected data. Thanks Marijn!

The first works on machine learning in SAT has been by the crowd creating portifolio solvers such as SATZilla that calculate features of a CNF and then run the SAT solver that is predicted to solve that instance the fastest. This has been achieved by coming up with a set of easy-to-calculate but useful features and then using a standard prediction method to fit SAT solvers to CNFs. The issue, as always with machine learning, is overfitting. Unfortunately, CNFs tended to stay very similar between old SAT Competitions, and overfitting was richly rewarded. Hence, these portfolio solvers sometimes did well in competitions but sometimes relatively poorly in practice.

The second wave of improvements came with MapleSAT where a multi-armed bandit (MAB) framework was used to sometimes to pick branching variables. This won the 2016 SAT Competition‘s Main Track and was a novel and truly interesting idea, manipulating the branching heuristic based on the feature that the researchers called “learning rate“.

With this blog post, I hope to inspire a third wave of improvements in SAT solver performance. Learnt clause usefulness metrics have been a a very hot potato since the glucose SAT solver which engineered and used a new feature, glues, to decide the usefulness on. Maybe with the work and data provided below, we could use features not used before, or combine them in novel ways to achieve better prediction accuracy.

A History of Clause Usefulness Heuristics

For a long time, learnt clauses were chosen to be kept around in the clause database based on the feature called their “activity”, which measured how often was the clause involved in generating conflict clauses. This was the heuristic used in the original MiniSat.

The next big step came with glues that was present in the earliest of the Glucose solver family. This was a huge step in a different direction — suddenly a new feature has been engineered, “glue”, and the heuristic used to decide has changed. It was now the glue of the clause, relative to the other clauses, that determined whether the clause stayed or was discarded.

The next step was a hybrid approach, that stays until today. This says that a learnt clause has very low glue should stay no matter what, clauses with slightly higher glues should stick around for a while at least, and clauses with much higher glues should be only kept around for a short while, based on their activities. This is the strategy used by MapleSAT, a very successful SAT solver.

DRAT and the Era of Knowing What’s Good

The DRAT-trim proof checker has ushered in a new possibility in the era of SAT solving. We could finally know how the UNSAT proof was built, and furthermore, we could know which lemmas, i.e. which learnt clauses were actually used to build that proof. This means that we could finally measure all sorts of features of clauses, e.g. their glue or their size, or their activity, store this along with the clause, and once the SAT solver has finished and we know which clauses were actually useful, try to build predictive models using supervised machine learning. However, for whatever reason, nobody did this.

Thanks to Marijn Heule, who I asked to help me parse Clause IDs in DRAT, I have finally built a system that does exactly as above. It gathers over 140 features about each learnt clause, then when the solving finishes, it runs DRAT and then associates a “OK” or “BAD” nominal class value with the features. The output is an SQLite file for each solved problem. I have picked 153 problems that all solved as UNSAT within less than 10 minutes from the past 6 years of SAT competitions, and have run my setup on it. The solver used was CryptoMiniSat and so as not to taint the results, I have set it not to delete any clause at all from the database (i.e. no clause cleaning was performed) and set it to preprocess the instance but not to perform any in-processing. Furthermore, the restart heuristic was set to be the one pioneered by swdia5by, i.e. glue-based and geometric restarts are combined, in an iterative way.

The Features

The features saved broadly fall into four categories:

  1. Features computed once in a while on the whole CNF. These are similar to those engineered in SATZilla and other portifolio solvers. Thanks go to Yuri Malitsky and Horst Samulowitz who sent me “features_fast.c”. This includes things like statistics about clauses and variable distribution, etc. These start with “feat.” such as “feat.horn_min”
  2. Features of the previous restart. This includes things like the number of binary clauses learnt, average branch depth, average learnt clause glue size, clause size, etc. These start with “rst.” such as “rst.propLongRed” — the number of propagations made by long redundant (what most solvers call “learnt”) clauses.
  3. Features of the current clause such as its size, glue, its variables’ average standardised activity (i.e. divided by “var_inc”), etc. These start with “cls.” such as “cl.conflicts_this_restart”, i.e. the number of conflicts in this restart.
  4. Some computed features, such as “cl.glue_rel” which is equal to “cl.glue” / “cl.glue_hist”

The final “class” attribute is set to either “OK” meaning the clause was used in the final UNSAT proof, or “BAD” meaning it was not. Obviously, we want to never keep the BAD ones, and only keep the OK ones. If we could predict based on the four types of features above (which are all available at the time of the clause creation) which clauses we should keep, then we potentially could solve problems a lot faster. Partially because we would just throw the clauses away that we predict to be useless, and partially because we could steer the solver towards regions of the search space that contain more useful clauses — e.g. by restarting when we decide that where we are is a poor place to be.

The Data

CSV is available HERE

First of all, a disclaimer. There are a million ways this can be done differently, improved, or made worse. I have collected over a hundred features and I think they are useful. I also have conducted the experiments on over 150 problems each running at most 10 minutes (but at least 10’000 conflicts), using CryptoMiniSat, never deleting any clause. This constitutes millions of data points.  I have spent over two years in doing this, and I have been analysing different versions of this dataset for multiple months.  Hence, I may well be biased, in both the way the data has been collected and how I’m analysing it. To counter these biases, I am making the data available so you can perform your own analysis and CryptoMiniSat is made fully open source, including all that you need to completely and precisely re-generate this (or any other) data. See the bottom of this post for some how-tos.

I am only making available the sampled CSV for space and practicality reasons. I created a CSV that contains 153 problems’ datapoints, picking 10’000 randomly from each, which was then randomly sampled to 30’000 elements. This 51MB data is available here. I strongly suggest using Weka to read this file. In case you have trouble using Weka and/or creating predictive models, I’d suggest the free online course Data Mining with Weka.

Note: I have the 1530k line file as well, but it’s 2.6GB. If you really need it, please let me know at my email. For almost all analysis, 30k datapoints is sufficient — Weka will not be able to practically work with any dataset over 100k elements. In case you want to perform deep learning, we can take a shot at that 2.6GB data piece together. However, I think clustering and per-cluster prediction models are a lower-hanging fruit.

Preliminary Analysis

So, what does the data tell us? Throughout here I will use a percentage split of 66% for the training-test set, using the 30k-line data file above. All results below are trivially reproducible.

Zero Rule Check
First of all let’s do a ZeroR analysis, i.e. decide to keep or not keep a clause without looking at any data. We get:

So we have about 50% useful and 50% useless clauses. Note that this is may not be representative for problems that are difficult. We picked problems that solve under 10 minutes that have at least 10’000 conflicts.

One Rule Check
Next up, let’t do the slightly less trivial setup and do a OneR, i.e. one rule analysis. Here, Weka is only allowed to pick one feature to decide. One would hope this to be glue. It isn’t. Let’s set the minimum bucket size to 100, which means Weka won’t give us a 100 different small decisions (i.e. won’t overfit, which one can observe in some portifolio solvers). We get:

What is very strange here is that the best predictor is not glue. In fact, the next best predictors are, in order:

  1. cl.decision_level (72.3 %)
  2. rst.branchDepth (67.4%)
  3. rst.branchDepthDelta (67.6 %)
  4. cl.decision_level_hist (67.1 %)
  5. cl.backtrack_level_hist (67.1 %)

So they all seem to have something to do with the branch depth/decision depth. If forced, Weka will draw the line at glue 15 and below to be OK and 16 and above to be BAD, giving a 61.9% accuracy.

J48 Decision Tree
Let’s try to see if we can get some interesting result with J48, a standard decision tree-building setup. I’m going to put a minimum of 400 elements in any bucket, or we will have overfitting.

Interesting… so we first branch on backtrack_level, which is not unsurprising, given the OneR results above. Then we either use the glue distribution variance of the last time we measured the features, “feat.red_glue_distr_var” or the previous restart’s average branch depth delta (i.e. backjump-size), “rst.branchDepthDelta”. The lower branches are interesting as well.

Random Decision Tree
Just for completeness sake, let’s try to do a RandomTree as well. Let’s set the MinNum to 500 so we can combat overfitting. We then get a pretty complicated tree with the following stats:

Which is pretty fair performance, but the tree is hard to understand and its performance is worse than J48, though not substantially.

There are other analyses that could be done, for example clustering of similar problems — you can find the CNF filename in feature “fname” (though you should never make any decisions based on that in your decision trees). Building problem classes may be interesting — we could cut up the CSV into different classes and create different prediction models for each. I am pretty sure this would significantly boost our prediction performance.

Visualisations
You can use Weka to visualize the data in many ways. Here is one:

You can use such visualisations to find anomalies, incorrect datapoints, or skews in the collection of data. If you do find any of these, please email me. I am happy to correct them of course — we might even achieve better prediction.

How to Do This at Home

It’s quite easy to create data for your own CNF instances. Just follow the README on the CryptoMiniSat GitHub repository, which says to get a clean Debian or Ubuntu distribution and then:

This will do predictive analysis using Python’s scikit-learn’s DecisionTreeClassifier (which may or may not be what you want) on a test problem and build a nice visual PNG tree too using graphviz:

Note that this decision tree is highly non-representative — it ran on a single, incredibly small instance. You can look at test_predict/data.sqlite.csv with Weka to run your own analysis and build your own, custom trees. To run this on a CNF of your own choice, run:

You will then have your scikit-learn tree generated and more importantly, you will have the CSV under “myoutput/data.sqlite.csv” so you can read that with Weka and do your own analysis. Beware that you probably want to cut down the size of that CSV before loading it into Weka — but randomise first or you will only see the beginning of the solving. Concatenating CSVs of different runs is easy, just make sure to strip the topmost line from CSV: it’s the header and should not be repeated. For randomisation, use “shuf file” and for cutting the header off, use “tail -n +2 file”. To get only the header, use “head -n 1 file”:

Conclusion

I think the above could help how choosing parameters/features and cutoffs when deciding whether to keep a learnt clause and in determining when we are in a bad place in search. This has been done experimentally until now, playing with the cutoffs, trying new cutoffs, and running all the problems on a large cluster, many times.

With the above data in hand, I think we could do better. Of course we will still be using clusters, verifying what the data analysis is indicating. But we may be able to check, engineer and determine the features and their cutoffs better. And finally, with all this data, I am hopeful that we will be able to have a discussion grounded in more data than just solving times.

Machine Learning and SAT

I have lately been digging myself into a deep hole with machine learning. While doing that it occurred to me that the SAT community has essentially been trying to imitate some of ML in a somewhat poor way. Let me explain.

CryptoMiniSat and clause cleaning strategy selection

When CryptoMiniSat won the SAT Race of 2010, it was in large part because I realized that glucose at the time was essentially unable to solve cryptographic problems. I devised a system where I could detect which problems were cryptographic. It checked the activity stability of variables and if they were more stable than a threshold, it was decided that the problem was cryptographic. Cryptographic problems were then solved using a geometric restart strategy with clause activities for learnt database cleaning. Without this hack, it would have been impossible to win the competition.
Continue reading