Skip to main content

Build logical theories for SAT solvers on the fly

Project description

Bauhaus

bauhaus is a Python package for spinning up propositional logic encodings from object-oriented Python code.

Features

  • Create propositional variables from Python classes
  • Build naive SAT encoding constraints from propositional variables
    • At most one
    • At least one
    • Exactly one
    • At most K
    • Implies all
  • Compile constraints into a theory in conjunctive or negation normal form
  • With python-nnf, submit a theory to a SAT solver
  • Theory introspection

Installation

Install bauhaus by running

pip install bauhaus

How is it used?

Create Encoding objects that you intend to compile to an SAT. Encoding objects will store your model's propositional variables and constraints on the fly.

from bauhaus import Encoding, proposition, constraint
e = Encoding()

Create propositional variables by decorating class definitions with @proposition.

@proposition(e) # Each instance of A is stored as a proposition
class A(object): pass

Create constraints by decorating classes, methods, or invoking the constraint methods.

# Each instance of A implies the right side
@constraint.implies_all(e, right=['hello'])
# At most two of the A instances are true
@constraint.at_most_k(e, 2)
@proposition(e)
class A(object):

    def __init__(self, val):
        self.val = val

    def __repr__(self):
        return f"A.{self.val}"

    # Each instance of A implies the result of the method
    @constraint.implies_all(e)
    def method(self):
        return self.val

# At most one of the inputs is true.
constraint.add_at_most_one(e, A, A.method, Var('B'))

Compile your theory into conjunctive or negation normal form (note: the theory is truncated),

objects = [A(val) for val in range(1,4)]
theory = e.compile()
>> And({And({Or({Var(3), ~Var(A.3)}), Or({Var(1), ~Var(A.1)}),
        ...
        And({Or({~Var(A.1), ~Var(A.2), ~Var(A.3)})})})

And view the origin of each constraint, from the propositional object to the final constraint. (Note: the introspection is truncated)

e.introspect()
>>
constraint.at_most_k:  function = A  k = 2:

(~Var(A.3), ~Var(A.1)) =>
Or({~Var(A.1), ~Var(A.2), ~Var(A.3)})


(~Var(A.3), ~Var(A.2)) =>
Or({~Var(A.1), ~Var(A.2), ~Var(A.3)})


(~Var(A.1), ~Var(A.2)) =>
Or({~Var(A.1), ~Var(A.2), ~Var(A.3)})


Final at_most_k: And({Or({~Var(A.1), ~Var(A.2), ~Var(A.3)})})
...
...

Contribute

Head over to our code of conduct and get a feel for the library by reading our architecture design and documentation.

Support

If you are having issues, please let us know. Reach out to us at karishma.daga@queensu.ca or by creating a GitHub issue.

License

The project is licensed under the MIT license for the Queen's Mu Lab

Citing This Work

bauhaus was created by Karishma Daga under mentorship of Christian Muise at Queen's University, Kingston.

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

bauhaus-1.1.2.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

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

bauhaus-1.1.2-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

Details for the file bauhaus-1.1.2.tar.gz.

File metadata

  • Download URL: bauhaus-1.1.2.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for bauhaus-1.1.2.tar.gz
Algorithm Hash digest
SHA256 21d7f7dbb9033c076f236729391c5c79dd62101313a44d34d77e26f3c08c19fb
MD5 2d3c40e59ea6970c60fa4ffdc6339842
BLAKE2b-256 f4c29fb8e17737003379e9bfea03abe01ecea5cb80acfbe1138d68a87e7739cd

See more details on using hashes here.

File details

Details for the file bauhaus-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: bauhaus-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.7

File hashes

Hashes for bauhaus-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d73c0b1b133854a6476c03731a08e2d59d27641e580f77d8307b02781dfc73e2
MD5 1c7dea551b7e30fac566160fea0d16b4
BLAKE2b-256 38594c5832ebb26a83b9249baa3d91624e46527cb0352d35bc64cca737d5e8e3

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