Skip to main content

Pythonic interface between AIGs and SAT solvers.

Project description

py-aiger-sat

Pythonic interface between AIGs and SAT solvers.

Build Status codecov 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.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)

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)}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py-aiger-sat-1.0.1.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_aiger_sat-1.0.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file py-aiger-sat-1.0.1.tar.gz.

File metadata

  • Download URL: py-aiger-sat-1.0.1.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.3 Linux/5.0.0-32-generic

File hashes

Hashes for py-aiger-sat-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c8774e7fb6b308fa59b26d99cef24e260cf747d9be0beb76c4968af9f85c6fb8
MD5 4c1ef29d0b5b975bb916712ae3fc5161
BLAKE2b-256 6444b366ef356094b9525bde6ae4da59ce6b582a31be1899830f30986d3a6ff8

See more details on using hashes here.

File details

Details for the file py_aiger_sat-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: py_aiger_sat-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.3 Linux/5.0.0-32-generic

File hashes

Hashes for py_aiger_sat-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2fbefcde1dac45e70180cd2a6922f34ef5ca50dff5bc9d44e884ccf37846af23
MD5 a4b25be97a4b682c47be0e9fb2a42820
BLAKE2b-256 d81e4eb1efb2e471249b238104efe5a7ea556442a3c75d86c8b9eb86e7a9d556

See more details on using hashes here.

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