=====
PySDD
=====
Python wrapper package to interactively use `Sententical Decision Diagrams (SDD) <http://reasoning.cs.ucla.edu/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 <https://cython.readthedocs.io/en/latest/src/quickstart/install.html>`_)
* The Python development version that includes Python header files and static library (e.g. libpython3-dev, python-dev, ...)
------------
Installation
------------
.. code-block:: shell
$ 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``.
.. code-block:: python
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:
.. image:: https://people.cs.kuleuven.be/wannes.meert/pysdd/sdd.png
.. image:: 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 <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)
.. code-block:: shell
$ 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
-----------------------
.. code-block:: shell
$ 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 <https://dtai.cs.kuleuven.be/problog/>`_.
References:
* Wannes Meert, PySDD,
in `Recent Trends in Knowledge Compilation
<http://drops.dagstuhl.de/opus/volltexte/2018/8589/pdf/dagrep_v007_i009_p062_17381.pdf>`_,
Report from Dagstuhl Seminar 17381, Sep 2017.
Eds. A. Darwiche, P. Marquis, D. Suciu, S. Szeider.
Other languages:
* C: http://reasoning.cs.ucla.edu/sdd/
* Java: https://github.com/jessa/JSDD
-------
Contact
-------
* Wannes Meert, KU Leuven, https://people.cs.kuleuven.be/wannes.meert
* Arthur Choi, UCLA, http://web.cs.ucla.edu/~aychoi/
-------
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/wannesm/PySDD",
"name": "PySDD",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "sdd,knowledge compilation",
"author": "Wannes Meert, Arthur Choi",
"author_email": "wannes.meert@cs.kuleuven.be",
"download_url": "https://files.pythonhosted.org/packages/e2/eb/26991dfeb4a9e6ffb5f2c51673e492b407a10de066836eb302cedd528d76/PySDD-0.2.11.tar.gz",
"platform": null,
"description": "=====\nPySDD\n=====\n\nPython wrapper package to interactively use `Sententical Decision Diagrams (SDD) <http://reasoning.cs.ucla.edu/sdd/>`_.\n\nFull documentation available on http://pysdd.readthedocs.io.\n\n------------\nDependencies\n------------\n\n* Python >=3.6\n* Cython\n\nOptional:\n\n* cysignals\n* numpy\n\nMake sure to have the correct development tools installed:\n\n* C compiler (see `Installing Cython <https://cython.readthedocs.io/en/latest/src/quickstart/install.html>`_)\n* The Python development version that includes Python header files and static library (e.g. libpython3-dev, python-dev, ...)\n\n------------\nInstallation\n------------\n\n.. code-block:: shell\n\n $ pip install PySDD\n\n\n--------------\nPython package\n--------------\n\nThe wrapper can be used as a Python package and allows for interactive use.\n\nThe following example builds an SDD for the formula ``a\u2227b \u2228 b\u2227c \u2228 c\u2227d``.\n\n.. code-block:: python\n\n from pysdd.sdd import SddManager, Vtree, WmcManager\n vtree = Vtree(var_count=4, var_order=[2,1,4,3], vtree_type=\"balanced\")\n sdd = SddManager.from_vtree(vtree)\n a, b, c, d = sdd.vars\n\n # Build SDD for formula\n formula = (a & b) | (b & c) | (c & d)\n\n # Model Counting\n wmc = formula.wmc(log_mode=False)\n print(f\"Model Count: {wmc.propagate()}\")\n wmc.set_literal_weight(a, 0.5)\n print(f\"Weighted Model Count: {wmc.propagate()}\")\n\n # Visualize SDD and Vtree\n with open(\"output/sdd.dot\", \"w\") as out:\n print(formula.dot(), file=out)\n with open(\"output/vtree.dot\", \"w\") as out:\n print(vtree.dot(), file=out)\n\nThe SDD and Vtree are visualized using Graphviz DOT:\n\n.. image:: https://people.cs.kuleuven.be/wannes.meert/pysdd/sdd.png\n.. image:: https://people.cs.kuleuven.be/wannes.meert/pysdd/vtree.png\n\n\n\nMore examples are available in the ``examples`` directory.\nAn interactive Jupyter notebook is available in\n`notebooks/examples.ipynb <notebooks/examples.ipynb>`_\n\n\n----------------------\nCommand Line Interface\n----------------------\n\nA Python CLI application is installed if you use pip, ``pysdd``. Or it can be used\ndirectly from the source directory where it is called ``pysdd-cli.py``.\nThis script mimicks the original sdd binary and adds additional features (e.g. weighted model counting)\n\n.. code-block:: shell\n\n $ pysdd -h\n $ ./pysdd-cli.py -h\n usage: pysdd-cli.py [-h] [-c FILE | -d FILE | -s FILE] [-v FILE] [-W FILE]\n [-V FILE] [-R FILE] [-S FILE] [-m] [-t TYPE] [-r K] [-q]\n [-p] [--log_mode]\n\n Sentential Decision Diagram, Compiler\n\n optional arguments:\n -h, --help show this help message and exit\n -c FILE set input CNF file\n -d FILE set input DNF file\n -s FILE set input SDD file\n -v FILE set input VTREE file\n -W FILE set output VTREE file\n -V FILE set output VTREE (dot) file\n -R FILE set output SDD file\n -S FILE set output SDD (dot) file\n -m minimize the cardinality of compiled sdd\n -t TYPE set initial vtree type (left/right/vertical/balanced/random)\n -r K if K>0: invoke vtree search every K clauses. If K=0: disable\n vtree search. By default (no -r option), dynamic vtree search is\n enabled\n -q perform post-compilation vtree search\n -p verbose output\n --log_mode weights in log\n\n Weighted Model Counting is performed if the NNF file containts a line\n formatted as follows: \"c weights PW_1 NW_1 ... PW_n NW_n\".\n\n\n-----------------\nMemory management\n-----------------\n\nPython's memory management is not used for the internal datastructures.\nUse the SDD library's garbage collection commands (e.g. ref, deref) to\nperform memory management.\n\n\n-----------------------\nCompilation from source\n-----------------------\n\n.. code-block:: shell\n\n $ pip install git+https://github.com/wannesm/PySDD.git#egg=PySDD\n\nThe repository should contain all the required files and libraries (unless\nyou use Windows). If you want to compile from source, note that some c-source\nfiles from the SDD package have been updated to work with this wrapper and are\nincluded in this repository. Do not overwrite these new files with the original\nfiles.\n\n* Download the SDD package from http://reasoning.cs.ucla.edu/sdd/.\n* Install the SDD package in the PySDD package in directories\n ``pysdd/lib/sdd-2.0`` and ``pysdd/lib/sddlib-2.0`` without overwriting\n the already available files.\n* Run ``python3 setup.py build_ext --inplace`` or ``make build`` to compile the\n library in the current directory. If you want to install the library such\n that the library is available for your local installation or in your virtual\n environment, use ``python3 setup.py install``.\n\nFor some Linux platforms, it might be necessary to recompile the libsdd-2.0 code with\nthe gcc option ``-fPIC`` and replace the ``pysdd/lib/sdd-2.0/lib/Linux/libsdd.a``\nlibrary with your newly compiled version.\n\nThe Windows platform is not supported. There is some initial support but we cannot\noffer guarantees or detailed instructions (but are happy to accept pull requests).\n\n\n----------\nReferences\n----------\n\nThis package is inspired by the SDD wrapper used in the probabilistic\nprogramming language `ProbLog <https://dtai.cs.kuleuven.be/problog/>`_.\n\nReferences:\n\n* Wannes Meert, PySDD,\n in `Recent Trends in Knowledge Compilation\n <http://drops.dagstuhl.de/opus/volltexte/2018/8589/pdf/dagrep_v007_i009_p062_17381.pdf>`_,\n Report from Dagstuhl Seminar 17381, Sep 2017.\n Eds. A. Darwiche, P. Marquis, D. Suciu, S. Szeider.\n\nOther languages:\n\n* C: http://reasoning.cs.ucla.edu/sdd/\n* Java: https://github.com/jessa/JSDD\n\n\n-------\nContact\n-------\n\n* Wannes Meert, KU Leuven, https://people.cs.kuleuven.be/wannes.meert\n* Arthur Choi, UCLA, http://web.cs.ucla.edu/~aychoi/\n\n\n-------\nLicense\n-------\n\nPython SDD wrapper:\n\nCopyright 2017-2018, KU Leuven and Regents of the University of California.\nLicensed under the Apache License, Version 2.0.\n\n\nSDD package:\n\nCopyright 2013-2018, Regents of the University of California\nLicensed under the Apache License, Version 2.0.\n",
"bugtrack_url": null,
"license": "Apache 2.0",
"summary": "Sentential Decision Diagrams",
"version": "0.2.11",
"split_keywords": [
"sdd",
"knowledge compilation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "9fc09afac5d24007a70a12b58cab9d1efbf41e58d27d28188720af51f8b0ed1e",
"md5": "01bd157bd827d223010ac83f46a18094",
"sha256": "25a7c18a7a2eb033becd3a328c0d62c736e3bc9ec6233438f396322c2ca328cc"
},
"downloads": -1,
"filename": "PySDD-0.2.11-cp310-cp310-macosx_11_0_x86_64.whl",
"has_sig": false,
"md5_digest": "01bd157bd827d223010ac83f46a18094",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.6",
"size": 1446666,
"upload_time": "2023-01-27T23:01:14",
"upload_time_iso_8601": "2023-01-27T23:01:14.787328Z",
"url": "https://files.pythonhosted.org/packages/9f/c0/9afac5d24007a70a12b58cab9d1efbf41e58d27d28188720af51f8b0ed1e/PySDD-0.2.11-cp310-cp310-macosx_11_0_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "84621d20609aa9de542781b24ae4e19419067839f1010ce4359a484a803143a2",
"md5": "2f3eb1306c8981325da855a50f62e618",
"sha256": "3fd1ae873fc0d28ba178e9f7ea47e2e0bcb1c03c75dcd1069e9cd40baa891592"
},
"downloads": -1,
"filename": "PySDD-0.2.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "2f3eb1306c8981325da855a50f62e618",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.6",
"size": 2565297,
"upload_time": "2023-01-27T23:01:16",
"upload_time_iso_8601": "2023-01-27T23:01:16.699923Z",
"url": "https://files.pythonhosted.org/packages/84/62/1d20609aa9de542781b24ae4e19419067839f1010ce4359a484a803143a2/PySDD-0.2.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f093536261f6a333e855085d4e789cef3370554cc7b5079dd650448164b1071b",
"md5": "cbd533f07e1067d6a352cf49d44b1650",
"sha256": "ca9953810fef638b0d25d2db0eaea1ea9cba861efcd267ac717c0f11da7e82cb"
},
"downloads": -1,
"filename": "PySDD-0.2.11-cp310-cp310-win_amd64.whl",
"has_sig": false,
"md5_digest": "cbd533f07e1067d6a352cf49d44b1650",
"packagetype": "bdist_wheel",
"python_version": "cp310",
"requires_python": ">=3.6",
"size": 1513614,
"upload_time": "2023-01-27T23:01:18",
"upload_time_iso_8601": "2023-01-27T23:01:18.698239Z",
"url": "https://files.pythonhosted.org/packages/f0/93/536261f6a333e855085d4e789cef3370554cc7b5079dd650448164b1071b/PySDD-0.2.11-cp310-cp310-win_amd64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c1c21d65b3adc46ccfc7056dcb50bbc44b9fd8fa7da3f2aa5ec05c4e2fb44ed2",
"md5": "167b764a923827f6b2ee54ea96fd4a64",
"sha256": "040c8e401a644b45481a19141b9599ca82dcb60c03f0cb948ddd839016f1248d"
},
"downloads": -1,
"filename": "PySDD-0.2.11-cp38-cp38-macosx_10_15_x86_64.whl",
"has_sig": false,
"md5_digest": "167b764a923827f6b2ee54ea96fd4a64",
"packagetype": "bdist_wheel",
"python_version": "cp38",
"requires_python": ">=3.6",
"size": 1451235,
"upload_time": "2023-01-27T23:01:20",
"upload_time_iso_8601": "2023-01-27T23:01:20.469225Z",
"url": "https://files.pythonhosted.org/packages/c1/c2/1d65b3adc46ccfc7056dcb50bbc44b9fd8fa7da3f2aa5ec05c4e2fb44ed2/PySDD-0.2.11-cp38-cp38-macosx_10_15_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "98a5ae9bc67920a328be29ab8e5ee7a98dae9dee73c7c9a982458d50c90b0dac",
"md5": "8746a97008848489043ec300c4558077",
"sha256": "33ba2adca0844d0cb0462aa4960252585529a3a37cb2f45cc090ac364a805129"
},
"downloads": -1,
"filename": "PySDD-0.2.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "8746a97008848489043ec300c4558077",
"packagetype": "bdist_wheel",
"python_version": "cp38",
"requires_python": ">=3.6",
"size": 2611171,
"upload_time": "2023-01-27T23:01:21",
"upload_time_iso_8601": "2023-01-27T23:01:21.839462Z",
"url": "https://files.pythonhosted.org/packages/98/a5/ae9bc67920a328be29ab8e5ee7a98dae9dee73c7c9a982458d50c90b0dac/PySDD-0.2.11-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3ff779d3e67d2bcf0dccfc0c7621113ac4b319acff419c11f8d9b770c8434f5b",
"md5": "be82a073f019518350e37ee61be6417b",
"sha256": "7e8ad919777d51a6be4ad91835900cc9f27bf1cce17d11b9a41fa34c2177b404"
},
"downloads": -1,
"filename": "PySDD-0.2.11-cp39-cp39-macosx_11_0_x86_64.whl",
"has_sig": false,
"md5_digest": "be82a073f019518350e37ee61be6417b",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.6",
"size": 1453270,
"upload_time": "2023-01-27T23:01:23",
"upload_time_iso_8601": "2023-01-27T23:01:23.775567Z",
"url": "https://files.pythonhosted.org/packages/3f/f7/79d3e67d2bcf0dccfc0c7621113ac4b319acff419c11f8d9b770c8434f5b/PySDD-0.2.11-cp39-cp39-macosx_11_0_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "ec91c09be4f78a7b863820201abb504ecf693de1a3667eaf1c793cfd9a93b515",
"md5": "9da3168228dc23900068760775453ee7",
"sha256": "161a1204b9f3badda9c7bec30139affd7bcdafee56a8eacbb681c7bd69405fb0"
},
"downloads": -1,
"filename": "PySDD-0.2.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"has_sig": false,
"md5_digest": "9da3168228dc23900068760775453ee7",
"packagetype": "bdist_wheel",
"python_version": "cp39",
"requires_python": ">=3.6",
"size": 2585252,
"upload_time": "2023-01-27T23:01:25",
"upload_time_iso_8601": "2023-01-27T23:01:25.398820Z",
"url": "https://files.pythonhosted.org/packages/ec/91/c09be4f78a7b863820201abb504ecf693de1a3667eaf1c793cfd9a93b515/PySDD-0.2.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "e2eb26991dfeb4a9e6ffb5f2c51673e492b407a10de066836eb302cedd528d76",
"md5": "70fbfd99e91b9db027c6fd3335c964f0",
"sha256": "c1ab11c8e3ce98fb415bb233a87834bfb57c5c50c12a509e4cbf2e496117363d"
},
"downloads": -1,
"filename": "PySDD-0.2.11.tar.gz",
"has_sig": false,
"md5_digest": "70fbfd99e91b9db027c6fd3335c964f0",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 1110392,
"upload_time": "2023-01-27T23:01:27",
"upload_time_iso_8601": "2023-01-27T23:01:27.487696Z",
"url": "https://files.pythonhosted.org/packages/e2/eb/26991dfeb4a9e6ffb5f2c51673e492b407a10de066836eb302cedd528d76/PySDD-0.2.11.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-01-27 23:01:27",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "wannesm",
"github_project": "PySDD",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "cython",
"specs": []
},
{
"name": "numpy",
"specs": []
},
{
"name": "cysignals",
"specs": []
}
],
"lcname": "pysdd"
}