Metadata-Version: 2.2
Name: pyunigen
Version: 2.8.0
Summary: Bindings to UniGen, an almost-uniform sampler
Keywords: sat,sampling,uniform-sampling
Author-Email: Mate Soos <soos.mate@gmail.com>
Maintainer-Email: Mate Soos <soos.mate@gmail.com>
License: MIT License
         
         Copyright (c) 2018 Meel Group
         Kuldeep Meel
         Mate Soos
         Daniel Freemont
         and others
         
         Permission is hereby granted, free of charge, to any person obtaining a copy
         of this software and associated documentation files (the "Software"), to deal
         in the Software without restriction, including without limitation the rights
         to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
         copies of the Software, and to permit persons to whom the Software is
         furnished to do so, subject to the following conditions:
         
         The above copyright notice and this permission notice shall be included in all
         copies or substantial portions of the Software.
         
         THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
         IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
         FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
         AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
         LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
         OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
         SOFTWARE.
         
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Utilities
Requires-Python: >=3.9
Description-Content-Type: text/markdown

# pyunigen: bindings to the UniGen almost uniform sampler

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

## Installing

```
pip install pyunigen
```

Pre-built wheels are available for Linux (x86-64, ARM64) and macOS (Apple
Silicon).

## Compiling
If you don't want to use the pip package, you can build it from a checkout.
It needs GMP and MPFR; CMake builds UniGen's other dependencies from sibling
checkouts next to `unigen/`, or fetches them from GitHub:

```
pip install .
```

## Usage

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

The function `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

The samples are over the sampling set, by default all variables. UniGen
simplifies the CNF with [Arjun](https://github.com/meelgroup/arjun) and maps
every sample back to its variables. On an unsatisfiable CNF, `sample()` returns
`(0, 0, [])`. `sample()` can only be called once per `Sampler`.

You can give the following arguments to `Sampler`:
* `seed` -- sets the random seed
* `verbosity` -- sets the verbosity of the system (default = 0)
* `epsilon` -- Tolerance parameter of the count, i.e. sets how approximate it is. Default = 0.8
* `delta` -- Confidence parameter of the count, i.e. sets how probabilistically correct it is. Default = 0.20
* `kappa` -- Uniformity parameter (see the TACAS-15 paper). Default = 0.638
* `multisample` -- Return multiple samples from each cell. Default = False
* `arjun` -- Simplify the CNF with Arjun before sampling. Default = True
