Skip to main content

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.

Release files for bauhaus 1.2.0

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

Source distribution (sdist)

Source distribution for bauhaus 1.2.0
File Size Uploaded
bauhaus-1.2.0.tar.gz 18.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bauhaus 1.2.0
File Interpreter ABI Platform
bauhaus-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 35.2 kB

Release files / bauhaus-1.2.0.tar.gz

Download URL bauhaus-1.2.0.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f82f5f9a9c541831a883a8c14b8ee71121b53e3b7ad5db29c85032175b7240a1
BLAKE2b-256 checksum
How to use checksums
f361d3694733f1b47ba7dfa6cbb04dc40e501da2c2b18e91749213a3d03957fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release files / bauhaus-1.2.0-py3-none-any.whl

Download URL bauhaus-1.2.0-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bcc11c7388a532d6f715ecc5ca0a7f8ee5f9b70f74b5f329bb1f50de61ea8767
BLAKE2b-256 checksum
How to use checksums
f1b155d0de6cd37f2a4cec7211be4f967b74531afa6ede2076d6f725a6957ad8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.9.20

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.0.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