Skip to main content

Bindings to UniGen, an approximate sampler

Project description

pyunigen: bindings to the UniGen almost uniform sampler

This directory provides Python bindings to UniGen on the C++ level, i.e. when importing pycryptosat, the CryptoMiniSat solver becomes part of the Python process itself.

Installing

pip install pyunigen

Compiling

If you don't want to use the pip package, you can compile it as:

apt-get install python-dev
cd python
git clone https://github.com/msoos/cryptominisat
git clone https://github.com/meelgroup/arjun
git clone https://github.com/meelgroup/approxmc
cd ..
python -m build

You will then find the files under "dist/".

Usage

The pyunigen module has one object, Sampler that has two functions sample and add_clause.

The funcion add_clause() takes an iterable list of literals such as [1, 2] which represents the truth 1 or 2 = True. For example, add_clause([1]) sets variable 1 to True.

The function sample() samples the system of equations that have been added with add_clause():

>>> from pyunigen import Sampler
>>> c = Sampler()
>>> c.add_clause([1, 5])
>>> c.add_clause([10, 11, 12])
>>> cells, hashes, samples = c.sample(num=2, sampling_set=range(1,5))
>>> print("There are approx. ", cells*2**hashes, " solutions over the sampling set. Samples: ", samples)
There are approx.  16  solutions over the sampling set. Samples:  [[1, -2, 3, -4], [1, 2, -3, -4]]

The return value is a tuple of cells and hashes. Which gives how many solutions there are, probabilistically approximately

You can give the following arguments to Counter:

  • seed -- sets the random seed
  • verbosity -- sets the verbosity of the system (default = 0)
  • epsilon -- Tolerance parameter, i.e. sets how approximate the returned count is. Default = 0.8
  • delta -- Confidence parameter, i.e. sets how probabilistically correct the returned count is. Default = 0.20

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

pyunigen-2.5.6.tar.gz (461.0 kB view hashes)

Uploaded Source

Built Distributions

pyunigen-2.5.6-pp39-pypy39_pp73-win_amd64.whl (479.5 kB view hashes)

Uploaded PyPy Windows x86-64

pyunigen-2.5.6-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (753.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyunigen-2.5.6-pp38-pypy38_pp73-win_amd64.whl (479.5 kB view hashes)

Uploaded PyPy Windows x86-64

pyunigen-2.5.6-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (753.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyunigen-2.5.6-pp37-pypy37_pp73-win_amd64.whl (479.5 kB view hashes)

Uploaded PyPy Windows x86-64

pyunigen-2.5.6-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (768.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pyunigen-2.5.6-cp311-cp311-win_amd64.whl (479.3 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pyunigen-2.5.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pyunigen-2.5.6-cp310-cp310-win_amd64.whl (479.3 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pyunigen-2.5.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pyunigen-2.5.6-cp39-cp39-win_amd64.whl (479.3 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pyunigen-2.5.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pyunigen-2.5.6-cp38-cp38-win_amd64.whl (479.3 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pyunigen-2.5.6-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pyunigen-2.5.6-cp37-cp37m-win_amd64.whl (479.4 kB view hashes)

Uploaded CPython 3.7m Windows x86-64

pyunigen-2.5.6-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.0 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

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