Skip to main content

Sentential Decision Diagrams

Project description

Python wrapper package to interactively use Sententical Decision Diagrams (SDD).

Full documentation available on http://pysdd.readthedocs.io.

Dependencies

  • Python >=3.6

  • Cython

Optional:

  • cysignals

  • numpy

Make sure to have the correct development tools installed:

  • C compiler (see Installing Cython)

  • The Python development version that includes Python header files and static library (e.g. libpython3-dev, python-dev, …)

Installation

$ pip install PySDD

Python package

The wrapper can be used as a Python package and allows for interactive use.

The following example builds an SDD for the formula a∧b ∨ b∧c ∨ c∧d.

from pysdd.sdd import SddManager, Vtree, WmcManager
vtree = Vtree(var_count=4, var_order=[2,1,4,3], vtree_type="balanced")
sdd = SddManager.from_vtree(vtree)
a, b, c, d = sdd.vars

# Build SDD for formula
formula = (a & b) | (b & c) | (c & d)

# Model Counting
wmc = formula.wmc(log_mode=False)
print(f"Model Count: {wmc.propagate()}")
wmc.set_literal_weight(a, 0.5)
print(f"Weighted Model Count: {wmc.propagate()}")

# Visualize SDD and Vtree
with open("output/sdd.dot", "w") as out:
    print(formula.dot(), file=out)
with open("output/vtree.dot", "w") as out:
    print(vtree.dot(), file=out)

The SDD and Vtree are visualized using Graphviz DOT:

https://people.cs.kuleuven.be/wannes.meert/pysdd/sdd.png https://people.cs.kuleuven.be/wannes.meert/pysdd/vtree.png

More examples are available in the examples directory. An interactive Jupyter notebook is available in notebooks/examples.ipynb

Command Line Interface

A Python CLI application is installed if you use pip, pysdd. Or it can be used directly from the source directory where it is called pysdd-cli.py. This script mimicks the original sdd binary and adds additional features (e.g. weighted model counting)

$ pysdd -h
$ ./pysdd-cli.py -h
usage: pysdd-cli.py [-h] [-c FILE | -d FILE | -s FILE] [-v FILE] [-W FILE]
                [-V FILE] [-R FILE] [-S FILE] [-m] [-t TYPE] [-r K] [-q]
                [-p] [--log_mode]

Sentential Decision Diagram, Compiler

optional arguments:
  -h, --help  show this help message and exit
  -c FILE     set input CNF file
  -d FILE     set input DNF file
  -s FILE     set input SDD file
  -v FILE     set input VTREE file
  -W FILE     set output VTREE file
  -V FILE     set output VTREE (dot) file
  -R FILE     set output SDD file
  -S FILE     set output SDD (dot) file
  -m          minimize the cardinality of compiled sdd
  -t TYPE     set initial vtree type (left/right/vertical/balanced/random)
  -r K        if K>0: invoke vtree search every K clauses. If K=0: disable
              vtree search. By default (no -r option), dynamic vtree search is
              enabled
  -q          perform post-compilation vtree search
  -p          verbose output
  --log_mode  weights in log

Weighted Model Counting is performed if the NNF file containts a line
formatted as follows: "c weights PW_1 NW_1 ... PW_n NW_n".

Memory management

Python’s memory management is not used for the internal datastructures. Use the SDD library’s garbage collection commands (e.g. ref, deref) to perform memory management.

Compilation from source

$ pip install git+https://github.com/wannesm/PySDD.git#egg=PySDD

The repository should contain all the required files and libraries (unless you use Windows). If you want to compile from source, note that some c-source files from the SDD package have been updated to work with this wrapper and are included in this repository. Do not overwrite these new files with the original files.

  • Download the SDD package from http://reasoning.cs.ucla.edu/sdd/.

  • Install the SDD package in the PySDD package in directories pysdd/lib/sdd-2.0 and pysdd/lib/sddlib-2.0 without overwriting the already available files.

  • Run python3 setup.py build_ext --inplace or make build to compile the library in the current directory. If you want to install the library such that the library is available for your local installation or in your virtual environment, use python3 setup.py install.

For some Linux platforms, it might be necessary to recompile the libsdd-2.0 code with the gcc option -fPIC and replace the pysdd/lib/sdd-2.0/lib/Linux/libsdd.a library with your newly compiled version.

The Windows platform is not supported. There is some initial support but we cannot offer guarantees or detailed instructions (but are happy to accept pull requests).

References

This package is inspired by the SDD wrapper used in the probabilistic programming language ProbLog.

References:

Other languages:

Contact

License

Python SDD wrapper:

Copyright 2017-2018, KU Leuven and Regents of the University of California. Licensed under the Apache License, Version 2.0.

SDD package:

Copyright 2013-2018, Regents of the University of California Licensed under the Apache License, Version 2.0.

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

PySDD-0.2.11.tar.gz (1.1 MB view details)

Uploaded Source

Built Distributions

PySDD-0.2.11-cp311-cp311-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.11 Windows x86-64

PySDD-0.2.11-cp311-cp311-macosx_13_0_arm64.whl (1.8 MB view details)

Uploaded CPython 3.11 macOS 13.0+ ARM64

PySDD-0.2.11-cp310-cp310-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.10 Windows x86-64

PySDD-0.2.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

PySDD-0.2.11-cp310-cp310-macosx_12_0_arm64.whl (1.7 MB view details)

Uploaded CPython 3.10 macOS 12.0+ ARM64

PySDD-0.2.11-cp310-cp310-macosx_11_0_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 11.0+ x86-64

PySDD-0.2.11-cp39-cp39-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.9 Windows x86-64

PySDD-0.2.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

PySDD-0.2.11-cp39-cp39-macosx_11_0_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.9 macOS 11.0+ x86-64

PySDD-0.2.11-cp38-cp38-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.8 Windows x86-64

PySDD-0.2.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.6 MB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

PySDD-0.2.11-cp38-cp38-macosx_10_15_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.8 macOS 10.15+ x86-64

PySDD-0.2.11-cp37-cp37m-win_amd64.whl (1.5 MB view details)

Uploaded CPython 3.7m Windows x86-64

PySDD-0.2.11-cp37-cp37m-macosx_10_15_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.7m macOS 10.15+ x86-64

File details

Details for the file PySDD-0.2.11.tar.gz.

File metadata

  • Download URL: PySDD-0.2.11.tar.gz
  • Upload date:
  • Size: 1.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for PySDD-0.2.11.tar.gz
Algorithm Hash digest
SHA256 c1ab11c8e3ce98fb415bb233a87834bfb57c5c50c12a509e4cbf2e496117363d
MD5 70fbfd99e91b9db027c6fd3335c964f0
BLAKE2b-256 e2eb26991dfeb4a9e6ffb5f2c51673e492b407a10de066836eb302cedd528d76

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: PySDD-0.2.11-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for PySDD-0.2.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 860244fce8b0e21cfaa93503bd799e0ac7260b5551508601f8396d91c578112a
MD5 d9a25fd3c96383a346662c9c168e053c
BLAKE2b-256 e7531a07f4c708e96a42ca528462768b5c58bff99a3c4e7febf2e8e103d68528

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp311-cp311-macosx_13_0_arm64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp311-cp311-macosx_13_0_arm64.whl
Algorithm Hash digest
SHA256 a508df1d81f9878df3ebb3291b203be26e53cd5bd5469d4915c22e7185eead87
MD5 4df2523e32238a868da15fe464e9aa23
BLAKE2b-256 443ab5a3bbb6448f1a52c71561986284d46281dc23c9e627f03444527025b351

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: PySDD-0.2.11-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for PySDD-0.2.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ca9953810fef638b0d25d2db0eaea1ea9cba861efcd267ac717c0f11da7e82cb
MD5 cbd533f07e1067d6a352cf49d44b1650
BLAKE2b-256 f093536261f6a333e855085d4e789cef3370554cc7b5079dd650448164b1071b

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3fd1ae873fc0d28ba178e9f7ea47e2e0bcb1c03c75dcd1069e9cd40baa891592
MD5 2f3eb1306c8981325da855a50f62e618
BLAKE2b-256 84621d20609aa9de542781b24ae4e19419067839f1010ce4359a484a803143a2

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp310-cp310-macosx_12_0_arm64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp310-cp310-macosx_12_0_arm64.whl
Algorithm Hash digest
SHA256 b88c4f2a41b95f6b38dd55df03e6e6ceea9c25f01e14b8614f0831e3b11d2919
MD5 83f27bc08a6189ee5abbfecc5bf1fcb7
BLAKE2b-256 908090ecc5763565faf24f8ef61465de074792b8e5f63159cc4ae0a333e4700c

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp310-cp310-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp310-cp310-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 25a7c18a7a2eb033becd3a328c0d62c736e3bc9ec6233438f396322c2ca328cc
MD5 01bd157bd827d223010ac83f46a18094
BLAKE2b-256 9fc09afac5d24007a70a12b58cab9d1efbf41e58d27d28188720af51f8b0ed1e

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: PySDD-0.2.11-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for PySDD-0.2.11-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 d7893811f4d941c0dec191a130bc4eb2710b9c9e423f4cd1afa27d90401fcec7
MD5 e6f4abb90e22738e95b8a1a6ce88b734
BLAKE2b-256 034b3e60b401b2a20e56630c366843279e1ffe58a572041479264984b1920be7

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 161a1204b9f3badda9c7bec30139affd7bcdafee56a8eacbb681c7bd69405fb0
MD5 9da3168228dc23900068760775453ee7
BLAKE2b-256 ec91c09be4f78a7b863820201abb504ecf693de1a3667eaf1c793cfd9a93b515

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp39-cp39-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp39-cp39-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 7e8ad919777d51a6be4ad91835900cc9f27bf1cce17d11b9a41fa34c2177b404
MD5 be82a073f019518350e37ee61be6417b
BLAKE2b-256 3ff779d3e67d2bcf0dccfc0c7621113ac4b319acff419c11f8d9b770c8434f5b

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: PySDD-0.2.11-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for PySDD-0.2.11-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 24c59e2be75d53c41ab0aab0742d4bff461a51caac810bad4ff9187ba593bae6
MD5 e3faa30ddfa1b57cdc3ed1e9f8144bd9
BLAKE2b-256 521f29cb6ca20a9f8560574d18592fc63cd0d7b93f8f09f27ed27e2e99000742

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 33ba2adca0844d0cb0462aa4960252585529a3a37cb2f45cc090ac364a805129
MD5 8746a97008848489043ec300c4558077
BLAKE2b-256 98a5ae9bc67920a328be29ab8e5ee7a98dae9dee73c7c9a982458d50c90b0dac

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 040c8e401a644b45481a19141b9599ca82dcb60c03f0cb948ddd839016f1248d
MD5 167b764a923827f6b2ee54ea96fd4a64
BLAKE2b-256 c1c21d65b3adc46ccfc7056dcb50bbc44b9fd8fa7da3f2aa5ec05c4e2fb44ed2

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: PySDD-0.2.11-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.1

File hashes

Hashes for PySDD-0.2.11-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 4df2e6cdbebe01a982fb5c7bdee5edc7f58e6cb32d192679d93b15b04628f75a
MD5 5b4a2c28b9561a4bb59f8b8cecf60e43
BLAKE2b-256 e1a77f83a9f9e6814a10cb3130e6cf47cc139ba7c83643ca7335a9ef1685e1a9

See more details on using hashes here.

File details

Details for the file PySDD-0.2.11-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for PySDD-0.2.11-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 4520e5e95d815a61398e3189fb70e9faad8dfbe56fe256bf3a5f2675c9ea29bc
MD5 cf6214705c237268bde7719292d64280
BLAKE2b-256 85b323cfa9b7f118eadea9373e219c0a73881eea761f57d14912abb24a376441

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page