Pythonic interface between AIGs and SAT solvers.
Project description
py-aiger-sat
Pythonic interface between AIGs and SAT solvers.
Table of Contents
Installation
If you just need to use aiger_sat
, you can just run:
$ pip install py-aiger-sat
For developers, note that this project uses the poetry python package/dependency management tool. Please familarize yourself with it and then run:
$ poetry install
Usage
aiger_sat
has two seperate API's. The first, called the Object API,
centers around the SolverWrapper
object - a thin wrapper around a
pysat
solver. The second is a Function API which exposes 4 functions
solve
, is_sat
, is_valid
, and are_equiv
. The function API is
primarily useful for simple 1-off SAT instances, where as the object
API is more useful when incremental solves are needed, or the
underlying pysat
solver must be exposed.
Object API
from aiger_sat import SolverWrapper
solver = SolverWrapper() # defaults to Glucose4
from pysat.solver import Glucose3
solver2 = SolverWrapper(solver=Glucose3)
solver
operate on boolean expressions in the form of aiger
circuits with a single output. For example,
import aiger
x, y, z = map(aiger.atom, ['x', 'y', 'z'])
expr = (x & y) | ~z
solver.add_expr(expr)
assert solver.is_sat()
model = solver.get_model()
print(model) # {'x': True, 'y': False, 'z': False}
assert expr(model)
Further, aiger_sat
supports making assumptions and computing
unsat_cores.
# Make invalid assumption.
assert not solver.is_sat(assumptions={
'x': False,
'z': True,
})
assert not solver.unsolved
core = solver.get_unsat_core()
assert core == {'x': False, 'z': True}
Function API
import aiger
import aiger_sat
x, y, z = map(aiger.atom, ['x', 'y', 'z'])
assert aiger_sat.is_sat(x & y & z)
model = aiger_sat.solve(x & y & z)
assert model == {'x': True, 'y': True, 'z': True}
assert aiger_sat.is_valid(aiger.atom(True))
expr1 = x & y
expr2 = x & y & (z | ~z)
assert aiger_sat.are_equiv(expr1, expr2)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for py_aiger_sat-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4f3fb668810949c32f327734731e5912e7bbc0f2017d2cae440f99269dca759 |
|
MD5 | 000ab3332ae1bc589bb71abcf7a66fd9 |
|
BLAKE2b-256 | 9ab1772a8f952ea20be9d40c985df0340f31ee0fb40bfac2410c21542a3f84bd |