Skip to main content

py-aiger-sat

Pythonic interface between AIGs and SAT solvers.

Build Status PyPI version License: MIT

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.solvers 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)

BitVector Support

py-aiger-sat also natively supports the py-aiger-bv bitvector library.

To enable this support, make sure that py-aiger-bv is installed, either manually:

$ pip install py-aiger-bv

or by installing py-aiger-sat with the bitvector option:

$ pip install py-aiger-sat[bitvector] or $ poetry install --extras=bitvector

Usage is analogous to the non-bitvector usage.

from aiger_bv import atom
from aiger_sat import sat_bv

# Object API
expr = atom(4, 'x') & atom(4, 'y') < 2
f = sat_bv.SolverBVWrapper()
f.add_expr(expr)

model = f.get_model()

# Function API.
model = sat_bv.solve(expr)

print(model)
# {'x': (False, False, True, True), 'y': (False, False, True, True)}

Metadata

Release files for py-aiger-sat 3.0.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py-aiger-sat 3.0.7
File Size Uploaded
py_aiger_sat-3.0.7.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for py-aiger-sat 3.0.7
File Interpreter ABI Platform
py_aiger_sat-3.0.7-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / py_aiger_sat-3.0.7.tar.gz

Download URL py_aiger_sat-3.0.7.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
d59532d92ffb5f8de87f41503c3ef6890bbbe9494a9e13d96509294acf01e2e9
BLAKE2b-256 checksum
How to use checksums
e8ba81ac15ed663d6e5d2b7b5ef3fecc2c0a3dbb8a32d388ae353cc2fe8ed16d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.6.19

Release files / py_aiger_sat-3.0.7-py3-none-any.whl

Download URL py_aiger_sat-3.0.7-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
301bf572ff67b14bb0121fa74a838219c6867506949206d462568e1c55e7ddbb
BLAKE2b-256 checksum
How to use checksums
a6053b1ce109e32a7136c1942841f784d700bc26e12132acd94dc510ce21cb52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.6.19

Release history Release notifications | RSS feed

This release

3.0.7 This release

2 release files

3.0.6

2 release files

3.0.5

2 release files

3.0.4

2 release files

3.0.3

2 release files

3.0.2

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page