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.0-cp313-cp313-manylinux_2_34_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.0-cp313-cp313-manylinux_2_34_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.0-cp313-cp313-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

pyapproxmc-4.3.0-cp312-cp312-manylinux_2_34_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.0-cp312-cp312-manylinux_2_34_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.0-cp312-cp312-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

pyapproxmc-4.3.0-cp311-cp311-manylinux_2_34_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.0-cp311-cp311-manylinux_2_34_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.0-cp311-cp311-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

pyapproxmc-4.3.0-cp310-cp310-manylinux_2_34_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.0-cp310-cp310-manylinux_2_34_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.0-cp310-cp310-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

pyapproxmc-4.3.0-cp39-cp39-manylinux_2_34_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ x86-64

pyapproxmc-4.3.0-cp39-cp39-manylinux_2_34_aarch64.whl (2.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.34+ ARM64

pyapproxmc-4.3.0-cp39-cp39-macosx_11_0_arm64.whl (2.2 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp313-cp313-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 b4833695072a549f15c67dd893cbee24ed1d4feb18c9e8175ff3aef1b0b485ab
MD5 f56b13db74c3d624ec8fdeee7d062d19
BLAKE2b-256 3bf4a06c53a26b7779b009e0ffc2801c59911cab9097a819a349e5efccede194

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp313-cp313-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 4fb547ae2506d4d522fd36a6e3e31eae16d199253c941d4980715b12a53beba0
MD5 fce4cceac520d74bdcaf092cb6e1f31f
BLAKE2b-256 1fdfcb62ee0df8838f17f5bf40d37b433ae64ca2a7c02ea307e2bc417f0c9e97

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 be7ce46dd001c44a279b2b0c76f50e43da5af389976e9876c56007da3471cba2
MD5 e0755b56712c5ff61d244f5adcc79587
BLAKE2b-256 38d7adc481ca6a79630c37ad23ced821c90aa87010456289c2702d771bbaf0ad

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 8ac45d74f2a8bee331702a3d29c14d3e52785f49958bd1089a0779c15e104de7
MD5 97d629eb8570d624328611e5dd85f3c3
BLAKE2b-256 f421005c1f1764438d624cb0b237ed8adaf04db6fa744078dbb3ed22a206920c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp312-cp312-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 ebb75ead6aaf5fdde960806aee902bd7c4b05ca772024a8e11d43aab68986821
MD5 ac0ef0f7fd701968cb609626f70211d8
BLAKE2b-256 9466dffda0f1bac9fd824bcee1339de44a16f6fe59318f57f108c1b87908403a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 00ed266f2aad49c4cfd47272fcef1d904a1d173d21d17fc24865f97d53ee6eac
MD5 4bffd7e78c4baadea65a3640d3e6c4eb
BLAKE2b-256 7b75b7e62f1e6eb78dd70a13355cad498dd48c018b8789f35b0261f428ce3446

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 203342efe8c5eb7e1bafa6a11e26cb54001f4fada2e99b3bf89f6343e8501a14
MD5 6bb62c2b51e29fdf56edf97876e31d09
BLAKE2b-256 04395594a7599ccb9a037ad4f0fab2bc6ef53503a3fd7b6ea140d136125d7eb7

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp311-cp311-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 74cf1f8eaf2887938eae308eaad7568d2846c4afe82d3172b2c6b12aa8822c05
MD5 d0e29603aaaec205e34691fdf3eefaef
BLAKE2b-256 a970dfa180a368b22ffa431f8266517c974d40dbbcd4fe7826e0192084d2340c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 6ca28361aeb9dba50f14e6fab25b6ed1ea74a45911608fd6c861fe01ea62b8f5
MD5 c9daf1b06ae74a7d24e9f18a8a20015d
BLAKE2b-256 b82ad22c0c80ccb3e602569987115ab8d0bfb57b33cad080501007c6ea69e7a1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a1a1cdfedb7936c00ea723f0b28b81c2df7697a52acb2ba10c4df1a6def33021
MD5 568841afa2481f1aa0a378ef9973d4fd
BLAKE2b-256 464fc9362b0cfbffc7981f31938aa02e8e01c5e7bc268f1c1f2f29e8158b477a

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp310-cp310-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 6d33bb1396ee19d769ae7de672d06a6b4fc8ce2d1af3e5d5678cbd8cad1f90df
MD5 685a9e96512e3cd3f1892ca0dbc39a59
BLAKE2b-256 1b054a7d4adb731e778ba260e13e16ca754f36ff45dbea0c5e27c302b46a97c2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 29a049ad481e85b7bf58e120285c9516ad421c689f1faf7aab72016773cdeb8b
MD5 c18acbc8d7b3b0eb12e7a08a412578c6
BLAKE2b-256 2c099b217297893985b90565fc9c019babddc849b56a3c1f265e73c177e3aa72

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp39-cp39-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 72a155ffbdd56a1f4c3fc727dc664c472062caf347026c379d0c31a5496acc99
MD5 e21601d1ab07af615947450ebc5959a3
BLAKE2b-256 e2d79ca74e98568af7f28a4b210b0bf45ddddb154955317c0c3b77d8fa22040b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp39-cp39-manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 25e4a51d6b05d06da0413ea33d03a253f13efcc3a0f9d8c7269094e6e6304a4e
MD5 a184b60b1bcceb3451f43d70a37a16a7
BLAKE2b-256 df53156c8dec4b013de258286523d44cd5cf019079bd4e8177ae83b41fecd491

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyapproxmc-4.3.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e129f8da4f7e2fa7df26c6c28d382e775030afa9322fafd7e7cf8ac13e077b62
MD5 bfdd1d150dc98974356bbd88d92e6572
BLAKE2b-256 7ca2a261d9a1b564ea56e4d420ff5d295144f91974ce93befeadf39bdb1358e4

See more details on using hashes here.

Provenance

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