Skip to main content

Bindings to ApproxMC, an approximate model counter

Project description

pyapproxmc: Python bindings to ApproxMC

Python bindings to ApproxMC, an approximate model counter with PAC (Probably Approximately Correct) guarantees. ApproxMC counts the number of satisfying assignments of CNF formulas.

Installing

pip install pyapproxmc

Building from source

# Install build tools
pip install scikit-build-core build

# Clone the repository
git clone --recurse-submodules https://github.com/meelgroup/approxmc
cd approxmc

# Build and install into a virtual environment
python -m venv .venv && source .venv/bin/activate
pip install .

The build system uses scikit-build-core and CMake. All C++ dependencies (CryptoMiniSat, Arjun, and their sub-dependencies) are fetched and built automatically by CMake during the pip install step. The only system library required is GMP:

  • Linux: sudo apt-get install libgmp-dev (or dnf install gmp-devel)
  • macOS: brew install gmp

Usage

import pyapproxmc

c = pyapproxmc.Counter()
c.add_clause([1, 2, 3])
c.add_clause([3, 20])
count = c.count()
print("Approximate count is: %d*2**%d" % (count[0], count[1]))

count() may only be called once per Counter instance; create a new Counter if you need to count a different formula.

The above prints Approximate count is: 11*2**16. Since the largest variable in the clauses is 20, the formula has at most 2**20 models; the two clauses restrict this to approximately 11*2**16 ≈ 720896 models.

Counting over a projection set

Pass a projection set (sampling set) to count() to count models projected onto a subset of variables:

import pyapproxmc

c = pyapproxmc.Counter()
c.add_clause([1, 2, 3])
c.add_clause([3, 20])
count = c.count(range(1, 10))
print("Approximate count is: %d*2**%d" % (count[0], count[1]))

This prints Approximate count is: 7*2**6, the approximate count projected over variables 1–9.

Adding clauses from arrays

For performance-critical code, multiple clauses can be added in one call via add_clauses() with a flat, zero-terminated array.array. This uses the buffer protocol and avoids per-element Python overhead:

import pyapproxmc
from array import array

c = pyapproxmc.Counter()
# Clauses [1,2,3] and [3,20], each terminated by 0
c.add_clauses(array('i', [1, 2, 3, 0, 3, 20, 0]))
count = c.count()

Note: add_clause() (singular) also accepts any iterable including arrays, but iterates element by element and does not use the buffer protocol.

Counter constructor parameters

Parameter Default Description
seed 1 Random seed for reproducibility
verbosity 0 Output verbosity (0 = silent)
epsilon 0.8 Tolerance: how approximate the count is
delta 0.2 Confidence: probability the count is within tolerance

Example:

c = pyapproxmc.Counter(seed=42, epsilon=0.5, delta=0.1)

Version

import pyapproxmc
print(pyapproxmc.__version__)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.2-cp313-cp313-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.2-cp312-cp312-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.2-cp311-cp311-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.2-cp310-cp310-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_x86_64.whl (3.4 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_aarch64.whl (3.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.2-cp39-cp39-macosx_11_0_arm64.whl (2.3 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

Details for the file pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 26a0302cef2e4bb515b39796a1364177098a6b50e352eea19469ca1b93fe534f
MD5 b9bbefc734853ab463739e973b9fd2d8
BLAKE2b-256 1cf5f9b264c4aeda2d51190222768d66b981b63f1dc9bd3550293da8b2fce3b4

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_x86_64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6b28c90ed97a8fd137901484d9c031ce25e11da16f8c301bb00dcf46ee103d29
MD5 187157e90fac475ad54b7fceb27ac840
BLAKE2b-256 674efa9f7c421f36529f24b29191c8d2cddc9f99029d74933ffcc5769f21e332

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp313-cp313-manylinux_2_34_aarch64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 714eb11be241c0b1c29f3869a32ad202b891055e69096be63e9b08792811713a
MD5 a183e16d637799295f98d9e60f2d1224
BLAKE2b-256 4ef140ab1da433f8e32beac8d5acd5ae60cdc3282a4c962f92c1f5cd5b558b5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 34d55a3624966987e1b649c2c23ae75bf18a0b64b1f7f347c1ab19845b7b8c61
MD5 0e9c512302b9194c7f6c032db7bb4cba
BLAKE2b-256 97dc97f6e47764a50151bc855764c37a55f44a2ab2780dee5e018b04dcdbd953

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_x86_64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 f1e35143a90de557361141522ebb46f926ef8d37e1bcfdbd1be7a1f026d27960
MD5 0b616d990bb56d991c751e3dab0280d2
BLAKE2b-256 17477b8471fbf7973712574fa0ceb69d80b0b6be5ad869042b50540970fc0884

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp312-cp312-manylinux_2_34_aarch64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7ef31867d62b7c842f6803ef8cc473069d377f0df0b2d1a4c63328b9b4b3c55a
MD5 0cf0b24044d8691599d536f07877b852
BLAKE2b-256 9538454a70c57218f2a22d2ca697531ad97426c00a428acc40ccdabde7a8880b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp312-cp312-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 29aaafa52d4fdfe72fd72577a691d389fd1f071bb1b33b7a46ea424909b796cf
MD5 377fa49dd2c3e7f301c7dbe43c6f101e
BLAKE2b-256 f4aa4ea06404b422cb82ed0b94eb239087f8ed844f22cfae58646f62a77c7e8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_x86_64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 98042ff989180ce115008b31cbb92ab746ba4c1a4f7c22bb178ac3efa44cb4b7
MD5 34a02d6f123267ca7485e9d8c4829d64
BLAKE2b-256 26db17998a1998b011c4c5c5d13fc6bb2921d99c082d237b032dc84137fa692f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp311-cp311-manylinux_2_34_aarch64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 212d231448c55cb9368ce6511a5795300a0e8d9620f18232dc8522b7d6a8416b
MD5 1637f56249288709beef713321601f09
BLAKE2b-256 9ca982ef58fde4f7d695019a97f028ba705624b2b46abb0334af2f2a0d2b2e67

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp311-cp311-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 2f976a644f875ad7d85b9f0f5643d9b31f9b0212cf168c57e01f76f29b61fd53
MD5 9de027360afdca2c91c0fde65cd60fc3
BLAKE2b-256 660eca5f6c8c46460efc8647d7d6b6ab276f41c946195390188943c0f229143a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_x86_64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 91c6b8edf67154c703a28f729ba3601a035cd8f9452bcbccada82f5a6356e16c
MD5 2ed3b239981c48a69bc199a6c68ec85e
BLAKE2b-256 e4ae4b8d46896c6c6345bc82ecb1615d466b8f0861c99b89a49956796b99aab6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp310-cp310-manylinux_2_34_aarch64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6f7fc46e83489f47d1fef647e7a74ab7f65734b93ea5091013ae9b8a49df7e62
MD5 3ef2906eb7b7b77cfb971fcc0faf3cdd
BLAKE2b-256 7b92c7281193ea21f024b2f74f6177b3feb2578e14f531d837973c95b446b13c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp310-cp310-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 30aec797cd367fc0d6c14ae8635f8bf9b2bde9d8efd72deb6deafd4ebcdf98e1
MD5 24b0bfb5502a65ee5b39800fc70fc5fb
BLAKE2b-256 1fdd1d9b197bea57be9791b8a73dbfae276394280cb4ad5d2b43febf83e9bf19

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_x86_64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 082ae113150b131010ec90961c759fc535e1cb2f8abbfef161683ae03cfc3a17
MD5 98244977e46c870baf06beb4a9fa41a8
BLAKE2b-256 a11664e4098963583d03d8a365642fd6a73c794c0f2222579771ac379787b802

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp39-cp39-manylinux_2_34_aarch64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyapproxmc-4.3.2-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.2-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 5de122ffe5db3e947d07d1fdfbc03d54d3331745c13452474255e44517efdb8e
MD5 19bdebcf4aac80f47f898132ffc127af
BLAKE2b-256 3f1989f01f81dc13900802c426d091c424aac9f0eb432241e8717f20e6567451

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.2-cp39-cp39-macosx_11_0_arm64.whl:

Publisher: python-wheels.yml on meelgroup/approxmc

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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