Python implementation of the SAT-Metropolis algorithm presented in the accompanying paper: "SAT-Metropolis: Combining Markov Chain Monte Carlo with SAT/SMT sampling". SAT-Metropolis uses SAT/SMT samplers as proposal distributions to effectively sample in probabilistic inference problems with hard constraints.
Code for experiments in the accompanying paper: The notebook experiments/experiments.ipynb contains the code for all the experiments in the accompanying paper.
Get started with SAT-Metropolis: The notebooks in folders experiments/sat and experiments/smt contain multiple examples on using SAT-Metropolis with the different backends currently available, namely, SPUR, CMSGen and MegaSampler. Below we provide installation instructions for a conda environment for the library, and instructions to install each backend.
After completing the installation steps below, any of the Jupyter notebooks can be executed by selecting the sat_metropolis kernel; the guide below includes making this kernel available in the system. The conda environment includes jupyterlab to execute Jupyter notebooks.
-
Install miniconda
-
Create the
sat_metropolisconda environment using theenvironment.ymlfile:conda env create -n sat_metropolis -f environment.yml -
Activate environment:
conda activate sat_metropolis -
Add environemnt as a kernel:
python -m ipykernel install --user --name=sat_metropolis -
Install the
sat_metropolislibrary:python -m pip install . -
Download and install SPUR. The following are the same steps as in SPUR with some minor modifications.
git clone https://github.com/ZaydH/spur.gitcd spur/sudo snap install cmake --classicsudo apt install libgmp-dev- Spur would not compile with newer versions of g++ because gcc does not include
stdint.h. Thus, it is necessary to modify the flags in theCMakeFile.txtfile as follows:set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++11 -Wall -include stdint.h") set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -std=c++11 -O3 -DNDEBUG -Wall -include stdint.h") set(CMAKE_CXX_FLAGS_PROFILING "${CMAKE_CXX_FLAGS_PROFILING} -std=c++11 -O3 -g -DNDEBUG -Wall -fno-omit-frame-pointer -include stdint.h") ./build.shln -s <path_to_spur_repo>/build/Release/spur ~/.local/bin/spur
-
Download and install MegaSampler. The following are the same steps as in MegaSampler with some minor modifications.
sudo apt install git build-essential python3-minimal python3-dev libjsoncpp-dev python3-venvpython -m venv venv --upgradesource venv/bin/activategit clone https://github.com/chaosite/MeGASampler.gitgit clone https://github.com/chaosite/z3.git(patched z3 for SMTSampler coverage)pushd z3python scripts/mk_make.py --pythoncd buildmake installpopdcd MeGASamplermakeconda env config vars set LD_LIBRARY_PATH=<path_to_dir_hosting_virtual_environment>/venv/lib(this is an example to add the variable to a conda environment, it is also possible to simply add it to.bashrc)ln -s <path_to_megasampler>/megasampler ~/.local/bin/megasampler
-
Download and install CMSGen. The following are the same steps as in CMSGen.
sudo apt install zlib1g-dev help2mancd cmsgenmkdir build && cd buildcmake ..makesudo make installsudo ldconfig