Registry / data / pycosat

pycosat

JSON →
library0.6.6pypypi✓ verified 88d ago

Python bindings to PicoSAT, a popular SAT solver written in C. Version 0.6.6 is the latest. The library is mature but receives infrequent updates; it is in maintenance mode.

pip install pycosat
INSTALL
IMPORT
SIG · PYCOSAT
P
pycosat
datapythonv0.6.6
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

itersolve
✓ from pycosat import itersolve
✗ from pycosat import solve
itersolve is the generator version; solve is not a public function in pycosat.

Solve a simple CNF SAT problem using the generator itersolve.

import pycosat # Solve a SAT problem: each clause is a list of integers cnf = [[1, -2], [-1, 3], [-2, -3]] solution = pycosat.itersolve(cnf) for sol in solution: print(sol)
Debug
Known issues
deprecatedThe function `solve` is not available; use `itersolve` or `blocksolve`.
fix
Replace `pycosat.solve(...)` with `next(pycosat.itersolve(...))` for a single solution.
affects: >=0.6
breakingIn version 0.6.4, a memory leak was fixed in `blocksolve()`. If you rely on heavy iteration, upgrade to avoid cumulative memory usage.
fix
Upgrade to 0.6.4 or later: `pip install --upgrade pycosat`.
affects: <0.6.4
gotchapycosat only accepts DIMACS CNF format, not other SAT formats like DIMACS WCNF or OPB. Variables must be positive integers.
fix
Convert your problem to DIMACS CNF (list of lists of non-zero integers, no 0).
affects: all
Errors
Common errors & fixes
AttributeError: module 'pycosat' has no attribute 'solve'
pycosat does not expose a `solve` function; use `itersolve` or `blocksolve` instead.
fix
Use `next(pycosat.itersolve(cnf))` or `list(pycosat.itersolve(cnf))`.
MemoryError: Unable to allocate ...
pycosat uses the PicoSAT library which may allocate large arrays for huge CNF formulas. Also, a memory leak in versions <0.6.4 could cause OOM.
fix
Upgrade to 0.6.4+ and consider splitting the problem into smaller chunks.
Upgrade
Version history
0.6.6latest on PyPI · released Oct 3, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
6 hits · last 30 days
node
6
Resources
pycosat — pip install pycosat · libregistry