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.1-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.1-cp313-cp313-manylinux_2_34_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.1-cp313-cp313-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyapproxmc-4.3.1-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.1-cp312-cp312-manylinux_2_34_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.1-cp312-cp312-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyapproxmc-4.3.1-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.1-cp311-cp311-manylinux_2_34_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.1-cp311-cp311-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyapproxmc-4.3.1-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.1-cp310-cp310-manylinux_2_34_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.1-cp310-cp310-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyapproxmc-4.3.1-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.1-cp39-cp39-manylinux_2_34_aarch64.whl (3.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.1-cp39-cp39-macosx_11_0_arm64.whl (2.4 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9ae7b223613c3dabdd1215f161ded2e01d02e2a824ddd667c29fd27d0a65a6f0
MD5 ad06736784deb9fc88203cc492d66b11
BLAKE2b-256 c0d90b421fa8b91b826e463367e202ccabd2e182a9e8f7823832d2ec754755ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp313-cp313-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 1d7fafe90a2879b9ffb5d15ae14b0d8662228f9f73e7871b1690ee9a04514870
MD5 545b0fc211e145b1551ce5f01f3f22bb
BLAKE2b-256 0011c004b1c6493e7f062fdf15c577fe698e843030122f347bd67574433d5d82

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f35e354651d10d36f387e0d36faefb9b73d662b084a6ae7b049bd84096918c17
MD5 0b42e0510b3efbea885565fc9018a073
BLAKE2b-256 c2342bd212044727b90fa01fae9178fa852d51fb6f786241a4a8b11179690fef

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 430fbb9224625c9091b56505bba75efbdb1dabbd602740fc49f632906d4519ed
MD5 34efab53baf6a1ebf46602267c382ee4
BLAKE2b-256 b844bd78f0da4a92c5fee665392e77aa9dad8e5494d37b318bb458c410274bfc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp312-cp312-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 53f171b50ca63114238233849d0faccd3e691b193420b41b81ac6870e0645d21
MD5 0049e4214b2609219a4d5f0001aa9128
BLAKE2b-256 4ffe95e4ae21a29346f92b3585db2cb28cbf2b7bb2826ca9d7d415f626873190

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 006f6c9581e687e167004691056ca7aa0437a7660783c6e3f9b88764054b9ffe
MD5 c6b268c9ec80d38a5c8df4bf372de08c
BLAKE2b-256 b8a1a390d3d7539ccabedc3319723c5af87b59a9e73200501822b8751afd5684

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 9c8de84a686621a5495b5f225199ec92645eadd5b11c351e5ea7933f1f3b6cdf
MD5 6f836d581874dc3a8c184aab0386c4ae
BLAKE2b-256 ca967948a6ce7951a974b208a05eb449aff46b8b96f2e1e3a95fb6e4f63996b7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp311-cp311-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 81e18cdd1099c6d141636b2c8100b828fa10ee2980825f7fc1a468cdce94d232
MD5 e404cf6bdaac0b1a770f0fb20c49b263
BLAKE2b-256 267a541475f512f98889ab3338b1f2b07a3d29210a85e547aaf8efaecf9f2f9d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 149d2c9fecf6f127ff7f31c8ebb931e89b5f83210183425b089e93f393b5bb29
MD5 782f47dd22aa2574c11df1786c01e656
BLAKE2b-256 7f80e495202ded3148232366a5bdad24956a70f32de15b89187a7c85f998587a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 437c19f7998ac604622ac1e75707fc5f751e87963494af6bb95d2748f5a378b5
MD5 153914f876381b5cfecd00f2e2c844bf
BLAKE2b-256 003fc34ee5a4e2d8503b54b08c0132bd3f8967db9dc65159ab04f04eed985b0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp310-cp310-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 2eef00400a259cc2be798a07491bdbed1ca6718676ff75d3d5116b3c73cc1c97
MD5 dd5d36c675ab0da684f8bbe115d75e51
BLAKE2b-256 5f90cd010b6021db4cf56e8a340341870773b5c96fc816116a7f554c64522405

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6eafedfe8b8f72a09ff744fa218f70f1b38ceeec381573cd40323260eea7a4fd
MD5 7d25133c56592d2b882b15a0eff71fcb
BLAKE2b-256 a952eaa137834fa4b9414504ffbcf7c1b4b3bf90aeb47e25b0ad3e84c8fd5fe7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp39-cp39-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 63f34c2c4aef7acc1affb478d83ac9154891e7eef8941823a75ddf6e6947e190
MD5 b9fd6b8beb858f98860a80a5a2602e8f
BLAKE2b-256 5c178f9a0c20264bc5b3b0b2e0539e98685528ab9d80e645cf51f274dae6ee40

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp39-cp39-manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp39-cp39-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 0793b99032c27ae559232e458d17c4dcbde1819eff7c4849c0f07b6d38a81866
MD5 7a20e9cca73cb21ec0a47cfa2e3a5a20
BLAKE2b-256 d9012eff7fb8c96379234c4cf22179606f5d5846242c9596125f45ceda336550

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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.1-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyapproxmc-4.3.1-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a06aa1e9b351f6e65898589062c7a4c8c4243e4c4c6a5c9d6ff8354fe79eefc5
MD5 23ac6950acff29bd20415a43cc392d26
BLAKE2b-256 a6928baaac8136527e4d5e7268245ab4d54d7fa2094834cec8b16fc5583a0fb6

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyapproxmc-4.3.1-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