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

Optional:

  • cysignals

  • numpy

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.literal(i) for i in range(1, 5)]

# 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.6.tar.gz (1.6 MB view details)

Uploaded Source

Built Distribution

PySDD-0.2.6-cp37-cp37m-macosx_10_14_x86_64.whl (1.6 MB view details)

Uploaded CPython 3.7m macOS 10.14+ x86-64

File details

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

File metadata

  • Download URL: PySDD-0.2.6.tar.gz
  • Upload date:
  • Size: 1.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.3

File hashes

Hashes for PySDD-0.2.6.tar.gz
Algorithm Hash digest
SHA256 31d7bc42dcea7cbe4850970669d8f6ba08a3be24f489519c20e526645f70e2d3
MD5 3aedc79ad034666a12ff6d6fe60ec30d
BLAKE2b-256 03c9ff5154a8db0fab46ae6e24a00faa237bae0add44eb678862b798fb1cfba7

See more details on using hashes here.

File details

Details for the file PySDD-0.2.6-cp37-cp37m-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: PySDD-0.2.6-cp37-cp37m-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: CPython 3.7m, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.3

File hashes

Hashes for PySDD-0.2.6-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 dbe9d29ba2ccd4b3ba5fbb1beaa4265bba5d84e7163f6a052b23d7ac74560b14
MD5 cc307f923b3ac29818618e2a502e2102
BLAKE2b-256 b3f0e3e315b8d76c0a659e1aac2024a53c0ec73f7d618e38d81b66909fb87aac

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