CrystalBall replaces CryptoMiniSat’s “throw away the highest-glue learnt clauses” heuristic with an xgboost model trained on the solver’s own UNSAT proofs. At each clause-database reduce the model ranks the candidate clauses by how much they will still be used, and the reduce removes the lowest-ranked ones.
All the code lives in the master branch of
CryptoMiniSat, under
scripts/crystal/.
This repository only has this README. The old crystalball branch of
CryptoMiniSat is out of date, so don’t use it. For details, see
scripts/crystal/README.md and scripts/crystal/CLAUDE.md there.
sudo apt-get install build-essential cmake git pkg-config libgmp-dev zlib1g-dev libsqlite3-dev
pip3 install xgboost pandas numpy scikit-learn
The predictor build needs xgboost’s C API, which means xgboost/c_api.h and
libxgboost.so. You can use the library that ships with the pip package. The
pip package doesn’t include the headers, so get them from the xgboost
repository:
git clone --depth 1 https://github.com/dmlc/xgboost ~/xgboost-src
XGB_LIB=$(python3 -c 'import xgboost, os; print(os.path.join(os.path.dirname(xgboost.__file__), "lib", "libxgboost.so"))')
git clone https://github.com/msoos/cryptominisat
cd cryptominisat
git clone https://github.com/msoos/cryptominisat-predictors src/predict
src/predict/ holds the model that gets embedded into the predictor build.
It is a separate git repository.
The pipeline expects three builds next to each other in the repository root:
| dir | cmake option | what it is |
|---|---|---|
build/ |
(none) | the normal solver, the baseline |
build_stats/ |
-DSTATS=ON |
writes clause data to SQLite and a proof, which give the training data |
build_pred/ |
-DFINAL_PREDICTOR=ON |
ranks reduce candidates with the xgboost model |
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc)
cd ..
mkdir build_stats && cd build_stats
cmake -DCMAKE_BUILD_TYPE=Release -DSTATS=ON ..
make -j$(nproc)
cd ..
mkdir build_pred && cd build_pred
cmake -DCMAKE_BUILD_TYPE=Release -DFINAL_PREDICTOR=ON \
-DXGBOOST_INCLUDE_DIR=$HOME/xgboost-src/include -DXGBOOST_LIBRARY=$XGB_LIB ..
make -j$(nproc)
cd ..
CMake downloads CaDiCaL and CaDiBack from GitHub. If you already have them
built, pass -Dcadical_DIR=... and -Dcadiback_DIR=... instead. The scripts
in scripts/build_scripts/ (build_stats.sh, build_final_predictor.sh) do
the same builds, but they expect pre-built ../cadical/build and
../cadiback/build.
The predictor build already has a trained model built in, so it works on its own:
./build_pred/cryptominisat5 --xor 0 problem.cnf
Solver options must come before the CNF file, because anything after the CNF
is read as the proof file. --predloc DIR loads
DIR/predictor-used_later-disc-xgb.json instead of the embedded model.
The pipeline only works on UNSAT instances, because the labels come from the UNSAT proof. Here is an instance to try:
wget https://www.msoos.org/largefiles/goldb-heqc-i10mul.cnf.gz
gunzip goldb-heqc-i10mul.cnf.gz
Give the pipeline a copy of the CNF, because it works in <cnf>-dir/ next to
the file. The proof it writes takes about 1 GB per million conflicts, and it is
deleted once the labels are made.
cd scripts/crystal
./ballofcrystal.sh /path/to/goldb-heqc-i10mul.cnf
The pipeline:
The models end up in goldb-heqc-i10mul.cnf-dir/:
../../build_pred/cryptominisat5 --predloc /path/to/goldb-heqc-i10mul.cnf-dir problem.cnf
To train on many instances:
./ballofcrystal.sh --gather-only a.cnf
./ballofcrystal.sh --gather-only b.cnf
./learn.sh outdir a.cnf-dir b.cnf-dir # train on all of them
./eval_corpus.sh outdir c.cnf d.cnf # normal vs predictor on each
run_corpus.sh runs all three steps in one go. To check that the pipeline
works, run test_small.sh. It takes about 3 minutes, runs the whole pipeline
on a small random UNSAT instance, and needs pip3 install cnfgen.
cd goldb-heqc-i10mul.cnf-dir
sqlite3 data-min.db
sqlite> select count() from reduceDB;
To get an HTML report on a model (importances, SHAP values, trees), install
shap and graphviz with pip, then run:
./model_report.py <learn dir>/predictor-used_later-disc-xgb.json -o report.html
MIT, the same as CryptoMiniSat.