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 seedverbosity
-- sets the verbosity of the system (default = 0)epsilon
-- Tolerance parameter, i.e. sets how approximate the returned count is. Default = 0.8delta
-- 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
Built Distributions
Hashes for pyunigen-2.5.5-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | adddf082681879cade8ae125c7bcd90829ad32ca2b0f409c9ec8d9f069495a48 |
|
MD5 | e7c826b0961754cc3e64fb2762006d56 |
|
BLAKE2b-256 | a3169bad3f731365e69fcb0db944fea49608e1db3ffa43b035eec9ee120a3fc1 |
Hashes for pyunigen-2.5.5-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a5e8ab1fae39041af1e3f0552ca46b08504be31aa9a70d74efb81a919a1e2c8 |
|
MD5 | db7f4bacc42a34178efadfd3ed2c09b3 |
|
BLAKE2b-256 | 4a95331dd20dfa76df91b16e50d80a72f78811402a135132fd11bee6646caec0 |
Hashes for pyunigen-2.5.5-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 548704f2527083986c0d3a5acb0a826733350cc3e4711ebb36aecf1a1edef84b |
|
MD5 | 712a49f1d4e3ead20b1458a616fd6e0b |
|
BLAKE2b-256 | 0d82ffaf35b5a387407ce14875701c4aeebaf22776bad65ac8c3e207bc0cc4d5 |
Hashes for pyunigen-2.5.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 003fd35006660cea41363a7301550e7d470008c11aaef5deb2a8f70eafcf7afc |
|
MD5 | ac1ccab74e3a5061fada9c0139d7f145 |
|
BLAKE2b-256 | 09936972e5f60b879e2215c03d7186ef26a6f7875bf53f25ffb28551505a145a |
Hashes for pyunigen-2.5.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee60744c545d2e5effcf8e115b3ce5e3796312328967aa913abef83a65bb89ea |
|
MD5 | 85b3afa90f5460c23b06be77af42e31e |
|
BLAKE2b-256 | 3508cadf2a662dbcb2b2aec73986ea7a54cdae006a67e431a8e3726ed30ee59b |
Hashes for pyunigen-2.5.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b2ec8461fdd7c48796b5ac52941f151ebfd2c1c69d99d47a1ba98adf408af36b |
|
MD5 | b7ee4d46fa3da6cc249891bc516aec1b |
|
BLAKE2b-256 | 5a2dcdf4d09d3ec45e801af2b8c3032c84f74563574bf3e0056b8b2d07ff916f |
Hashes for pyunigen-2.5.5-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d525b80b97dce075f31851211f128377d0962152d8eca236846174c28364d32 |
|
MD5 | 83f27db438d6fea7c9b8e3c84d8d77eb |
|
BLAKE2b-256 | d82115b16f04942eeb01d820c4f303f64893a5c78b091b0fea596bb372073553 |
Hashes for pyunigen-2.5.5-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a96cd7b369afe22291af6455816edeced409f19772907f385158f3df44be778 |
|
MD5 | 01b65d09957f6789c46af99eec9447e2 |
|
BLAKE2b-256 | 93226b9d3e74e5884346534d18db3b29e6ad80543dcf93de1d4a468db7ce255e |