=====
PySDD
=====
Python wrapper package to interactively use `Sentential Decision Diagrams (SDD) <http://reasoning.cs.ucla.edu/sdd/>`_.
Full documentation available on http://pysdd.readthedocs.io.
------------
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
-----------------------
To install from source, 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, ...)
The build process will download Cython and numpy in an isolated environment.
Then run:
.. code-block:: shell
$ pip install build
$ python -m build
To install the main branch:
.. code-block:: shell
$ pip install git+https://github.com/wannesm/PySDD.git#egg=PySDD
----------
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 & Arthur Choi, 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-2024, 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": null,
"name": "PySDD",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "sdd, knowledge compilation",
"author": "Arthur Choi",
"author_email": "Wannes Meert <wannes.meert@cs.kuleuven.be>",
"download_url": "https://files.pythonhosted.org/packages/61/00/fe110708af8299328a39fa19a334f49666740333473d39c884ca5d943ab2/pysdd-1.0.0.tar.gz",
"platform": null,
"description": "=====\nPySDD\n=====\n\nPython wrapper package to interactively use `Sentential Decision Diagrams (SDD) <http://reasoning.cs.ucla.edu/sdd/>`_.\n\nFull documentation available on http://pysdd.readthedocs.io.\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\nTo install from source, make 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\nThe build process will download Cython and numpy in an isolated environment.\n\nThen run:\n\n.. code-block:: shell\n\n $ pip install build\n $ python -m build\n\n\nTo install the main branch:\n\n.. code-block:: shell\n\n $ pip install git+https://github.com/wannesm/PySDD.git#egg=PySDD\n\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 & Arthur Choi, 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-2024, 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": "Copyright 2018, KU Leuven and Regents of the University of California Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ",
"summary": "Sentential Decision Diagrams",
"version": "1.0.0",
"project_urls": {
"Documentation": "https://pysdd.readthedocs.io/en/latest/",
"Homepage": "https://github.com/wannesm/PySDD"
},
"split_keywords": [
"sdd",
" knowledge compilation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "6100fe110708af8299328a39fa19a334f49666740333473d39c884ca5d943ab2",
"md5": "ad82d4dcc0ede49e9e139ec20ac66507",
"sha256": "4a36392287fd5d5e55fb2a9c9cded0f123bbe59a45a3f38c2da8a139be8f7b95"
},
"downloads": -1,
"filename": "pysdd-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "ad82d4dcc0ede49e9e139ec20ac66507",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 116291,
"upload_time": "2024-10-29T16:39:34",
"upload_time_iso_8601": "2024-10-29T16:39:34.439734Z",
"url": "https://files.pythonhosted.org/packages/61/00/fe110708af8299328a39fa19a334f49666740333473d39c884ca5d943ab2/pysdd-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-29 16:39:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "wannesm",
"github_project": "PySDD",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "pysdd"
}