Skip to main content

This library can be used to sample satisfying assignments for a CNF/DNF obeying a given literal-weighted weight function and projected upon a given sampling set.

Project description

WAPS-Sampler

WAPS, Weighted And Projected Sampler, generates samples on a sampling set conforming to a weight distribution defined by a literal-weighted weight function. It operates by using a compiled deterministic decomposable negation normal form (d-DNNF) of a CNF. It expects CNF in the DIMACS format and d-DNNF in the same format as that produced by the C2D compiler. Is is based on our paper titled "WAPS:Weighted and Projected Sampling" as published in TACAS-2019 conference.

Installation

sudo apt-get install graphviz
sudo apt-get install libgmp-dev
sudo apt-get install libmpfr-dev
sudo apt-get install libmpc-dev
pip install -r requirements.txt
wget -P bin/ http://www.cril.univ-artois.fr/KC/ressources/d4
chmod u+x bin/d4

For now, D4 compiler and Dsharp_PCompile (modified for our use case, see the "PCompile" procedure) are included as default for compiling CNF to d-DNNF. Any other compiler can be easily used with slight modifications.

Running WAPS

You can run WAPS by using 'waps.py' Python script present in waps directory. A simple invocation looks as follows:

python3 waps.py <cnffile>

The usage instructions and default values to arguments can be found by running

python3 waps.py -h

Weight Format

WAPS supports providing weights in CNF itself apart from being provided separately in a file. Weight of a literal is in [0,inf], specified by line starting with 'w',literal, and weight separated by space. Later, WAPS normalizes it such that weight(l)+weight(-l)=1 where l is a literal. While weights for both positive and negative literals should be specified, if weight of only positive literal is specified, waps assumes it to be normalized and assigns weight of negative literal as 1 - weight(l). By default, every literal's weight is set to 0.5, if its value is not given in CNF or the weightfile.

Specifying sampling set

WAPS supports providing sampling set in CNF itself. It is specified by lines starting with 'c ind' ,var indexes separated by space, and ended by 0. If sampling set is not provided, by default, every variable specified in formula is assumed to be a part of sampling set.

Output Format

The output samples are stored in samples.txt by default. Each line of the output consists of a serial number of the sample followed by a satisfying assignment projected on sampling set. The satisfying assignment consists of literals seperated by space. Note that turning random assignment (--randAssign) to 0 can lead to partial assignments in each line. In such cases, the unassigned sampling variables can be chosen to be True or False.

Also, WAPS can output a graphical representation of d-DNNF for the input NNF. In this d-DNNF, the leaves consists of literals and internal nodes can be OR ('O') or AND ('A') nodes as expected for an NNF. However, internal nodes also contain 2 numbers seperated by space in our representation. This second one gives the annotation. The first one, only serves the purpose of distinguishing between individual OR and AND nodes and has no other meaning.

Benchmarks

Benchmarks can be found here.

Python Usage

WAPS is also available as a library on PyPI, installable via pip.

sudo apt-get install graphviz
sudo apt-get install libgmp-dev
sudo apt-get install libmpfr-dev
sudo apt-get install libmpc-dev
wget https://github.com/meelgroup/WAPS/master/bin/Dsharp_PCompile
wget http://www.cril.univ-artois.fr/kc/ressources/d4
chmod u+x Dsharp_PCompile
chmod u+x d4
sudo mv Dsharp_PCompile /usr/local/bin/
sudo mv d4 /usr/local/bin/
pip install waps

Please reload your shell so that binaries are accessible via PATH.

A typical usage is as follows:

from waps import sampler

sampler = sampler(cnfFile="toy.cnf")
sampler.compile()
sampler.parse()
sampler.annotate()
samples = sampler.sample()
print(list(samples))

You can find more information on usage by:

from waps import sampler
help(sampler)

Issues, questions, bugs, etc.

Please click on "issues" at the top and create a new issue. All issues are responded to promptly.

How to Cite

@inproceedings{GSRM19,
author={Gupta, Rahul and  Sharma, Shubham and  Roy, Subhajit and  Meel, Kuldeep S.},
title={WAPS: Weighted and Projected Sampling},
booktitle={Proceedings of Tools and Algorithms for the Construction and Analysis of Systems (TACAS)},
month={4},
year={2019},
code={https://github.com/meelgroup/WAPS},
abstract={Previous work on applying Knowledge compilation has focused on uniform sampling over all the variables. Since the constraints are written in high level languages such as Verilog, the popular CNF encoding schemes as Tseitin encoding introduces additional auxiliary variables. The resulting CNF formulas are not equivalent but equisatisfiable. In particular, for a formula $G$ specified in high level language we obtain a CNF formula F such that $G (X) = \exists Y F(X,Y)$. This makes one wonder if it is possible to extend Knowledge compilation based techniques to sample over a subset of variables. Furthermore, languages such as Verilog allow specification of weights to user-defined constraints, so there is a need to sample according to the posterior distribution. In this paper, we provide affirmative question to the above two questions: We propose KUS that samples over user defined subset of variables from posterior distribution for a given prior distribution defined over product spaces.},
}

Contributors

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

waps-1.0.2.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

waps-1.0.2-py3-none-any.whl (11.1 kB view details)

Uploaded Python 3

File details

Details for the file waps-1.0.2.tar.gz.

File metadata

  • Download URL: waps-1.0.2.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for waps-1.0.2.tar.gz
Algorithm Hash digest
SHA256 437dd8f029befcd4904e2ece48f7fa7f2242e0e516e1a9a78e4af518ac0876c6
MD5 610282139fc18bb820bf01b08f568fd5
BLAKE2b-256 5889c7c565db9ce4320916d1b93ae206071ddc15a373816fb0ce567201f0f042

See more details on using hashes here.

File details

Details for the file waps-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: waps-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 11.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for waps-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 afefe88980853a725ac32282f849023e89f6522af1d75540261eea5362186845
MD5 e7c41f68b608ba8c0471839745a39443
BLAKE2b-256 cc4f7bc67ad167f7731028375302552d8ade14b2b0156c9cadfbfb51016229ed

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page