dd
Binary Decision Diagrams (BDDs) in pure Python and Cython wrappers of CUDD, Sylvan, and BuDDy
Science Score: 49.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 3 DOI reference(s) in README -
○Academic publication links
-
✓Committers with academic emails
2 of 8 committers (25.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (12.2%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Binary Decision Diagrams (BDDs) in pure Python and Cython wrappers of CUDD, Sylvan, and BuDDy
Basic Info
- Host: GitHub
- Owner: tulip-control
- License: other
- Language: Python
- Default Branch: main
- Homepage: https://pypi.org/project/dd
- Size: 1.43 MB
Statistics
- Stars: 203
- Watchers: 7
- Forks: 42
- Open Issues: 4
- Releases: 0
Topics
Metadata Files
README.md
About
A pure-Python (Python >= 3.11) package for manipulating:
- Binary decision diagrams (BDDs).
- Multi-valued decision diagrams (MDDs).
as well as Cython bindings to the C libraries:
- CUDD (also read the introduction, and note that the original link for CUDD is http://vlsi.colorado.edu/~fabio/CUDD/)
- Sylvan (multi-core parallelization)
- BuDDy
These bindings expose almost identical interfaces as the Python implementation. The intended workflow is:
- develop your algorithm in pure Python (easy to debug and introspect),
- use the bindings to benchmark and deploy
Your code remains the same.
Contains:
- All the standard functions defined, e.g., by Bryant.
- Dynamic variable reordering using Rudell's sifting algorithm.
- Reordering to obtain a given order.
- Parser of quantified Boolean expressions in either TLA+ or Promela syntax.
- Pre/Image computation (relational product).
- Renaming variables.
- Zero-omitted binary decision diagrams (ZDDs) in CUDD
- Conversion from BDDs to MDDs.
- Conversion functions to
networkxand DOT graphs. - BDDs have methods to
dumpandloadthem using JSON, orpickle. - BDDs dumped by CUDD's DDDMP can be loaded using fast iterative parser.
- Garbage collection that combines reference counting and tracing
If you prefer to work with integer variables instead of Booleans, and have
BDD computations occur underneath, then use the module
omega.symbolic.fol
from the omega package.
If you are interested in computing minimal covers (two-level logic minimization)
then use the module omega.symbolic.cover of the omega package.
The method omega.symbolic.fol.Context.to_expr converts BDDs to minimal
formulas in disjunctive normal form (DNF).
Documentation
The changelog is in
the file CHANGES.md.
Examples
The module dd.autoref wraps the pure-Python BDD implementation dd.bdd.
The API of dd.cudd is almost identical to dd.autoref.
You can skip details about dd.bdd, unless you want to implement recursive
BDD operations at a low level.
```python from dd.autoref import BDD
bdd = BDD() bdd.declare('x', 'y', 'z', 'w')
conjunction (in TLA+ syntax)
u = bdd.add_expr(r'x /\ y')
# symbols &, | are supported too
# note the "r" before the quote,
# which signifies a raw string and is
# needed to allow for the backslash
print(u.support)
substitute variables for variables (rename)
rename = dict(x='z', y='w') v = bdd.let(rename, u)
substitute constants for variables (cofactor)
values = dict(x=True, y=False) v = bdd.let(values, u)
substitute BDDs for variables (compose)
d = dict(x=bdd.add_expr(r'z \/ w')) v = bdd.let(d, u)
as Python operators
v = bdd.var('z') & bdd.var('w') v = ~ v
quantify universally ("forall")
u = bdd.add_expr(r'\A x, y: (x /\ y) => y')
quantify existentially ("exist")
u = bdd.add_expr(r'\E x, y: x \/ y')
less readable but faster alternative,
(faster because of not calling the parser;
this may matter only inside innermost loops)
u = bdd.var('x') | bdd.var('y') u = bdd.exist(['x', 'y'], u) assert u == bdd.true, u
inline BDD references
u = bdd.add_expr(rf'x /\ {v}')
satisfying assignments (models):
an assignment
d = bdd.pick(u, care_vars=['x', 'y'])
iterate over all assignments
for d in bdd.pick_iter(u): print(d)
how many assignments
n = bdd.count(u)
write to and load from JSON file
filename = 'bdd.json' bdd.dump(filename, roots=dict(res=u)) otherbdd = BDD() roots = otherbdd.load(filename) print(other_bdd.vars) ```
To run the same code with CUDD installed, change the first line to:
python
from dd.cudd import BDD
Most useful functionality is available via methods of the class BDD.
A few of the functions can prove useful too, among them to_nx().
Use the method BDD.dump to write a BDD to a pickle file, and
BDD.load to load it back. A CUDD dddmp file can be loaded using
the function dd.dddmp.load.
A Function object wraps each BDD node and decrements its reference count
when disposed by Python's garbage collector. Lower-level details are
discussed in the documentation.
For using ZDDs, change the first line to
python
from dd.cudd_zdd import ZDD as BDD
Installation
pure-Python
From the Python Package Index (PyPI) using the
package installer pip:
shell
pip install dd
or from the directory of source files:
shell
pip install .
For graph layout, install also graphviz.
The dd package requires Python 3.11 or later.
For Python 2.7, use dd == 0.5.7.
Cython bindings
To compile also the module dd.cudd (which interfaces to CUDD)
when installing from PyPI, run:
shell
pip install --upgrade wheel cython
export DD_FETCH=1 DD_CUDD=1
pip install dd -vvv --use-pep517 --no-build-isolation
(DD_FETCH=1 DD_CUDD=1 pip install dd also works,
when the source tarball includes cythonized code.)
To confirm that the installation succeeded:
shell
python -c 'import dd.cudd'
The environment variables
above mean:
- DD_FETCH=1: download CUDD v3.0.0 sources from the internet,
unpack the tarball (after checking its hash), and make CUDD.
- DD_CUDD=1: build the Cython module dd.cudd
More about environment variables that configure the
C extensions of dd is described in the file doc.md
Wheel files with compiled CUDD
Wheel files
are available from PyPI,
which contain the module dd.cudd,
with the CUDD library compiled and linked.
If you have a Linux system and Python version compatible with
one of the PyPI wheels,
then pip install dd will install also dd.cudd.
Licensing of the compiled modules dd.cudd and dd.cudd_zdd in the wheel
These notes apply to the compiled modules dd.cudd and dd.cudd_zdd that are
contained in the wheel file on
PyPI (namely the files dd/cudd.cpython-39-x86_64-linux-gnu.so and
dd/cudd_zdd.cpython-39-x86_64-linux-gnu.so in the *.whl file, which can
be obtained using unzip).
These notes do not apply to the source code of the modules
dd.cudd and dd.cudd_zdd.
The source distribution of dd on PyPI is distributed under a 3-clause BSD
license.
The following libraries and their headers were used when building the modules
dd.cudd and dd.cudd_zdd that are included in the wheel:
- Python: https://www.python.org/ftp/python/3.A.B/Python-3.A.B.tgz
(where
AandBthe numerals of the corresponding Python version used; for example10and2to signify Python 3.10.2). CPython releases are described at: https://www.python.org/downloads/ - CUDD.
The licenses of Python and CUDD are included in the wheel archive.
Cython does not add its license to C code that it generates.
GCC was used to compile the modules dd.cudd and dd.cudd_zdd in the wheel,
and the GCC runtime library exception
applies.
The modules dd.cudd and dd.cudd_zdd in the wheel dynamically link to the:
- Linux kernel (in particular
linux-vdso.so.1), which allows system calls (read the kernel's fileCOPYINGand the explicit syscall exception in the fileLICENSES/exceptions/Linux-syscall-note) - GNU C Library (glibc) (in particular
libpthread.so.0,libc.so.6,/lib64/ld-linux-x86-64.so.2), which uses the LGPLv2.1 that allows dynamic linking, and other licenses. These licenses are included in the wheel file and apply to the GNU C Library that is dynamically linked.
Tests
Use pytest. Run with:
shell
pushd tests/
pytest -v --continue-on-collection-errors .
popd
Tests of Cython modules that were not installed will fail. The code is covered well by tests.
License
BSD-3, read file LICENSE.
Owner
- Name: Temporal Logic Planning (TuLiP) toolbox
- Login: tulip-control
- Kind: organization
- Repositories: 7
- Profile: https://github.com/tulip-control
GitHub Events
Total
- Issues event: 9
- Watch event: 20
- Issue comment event: 17
- Pull request review event: 5
- Pull request review comment event: 4
- Pull request event: 3
- Fork event: 3
- Create event: 1
Last Year
- Issues event: 9
- Watch event: 20
- Issue comment event: 17
- Pull request review event: 5
- Pull request review comment event: 4
- Pull request event: 3
- Fork event: 3
- Create event: 1
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| Ioannis Filippidis | j****s@g****m | 1,331 |
| Scott C. Livingston | s****n@c****u | 13 |
| Mario Wenzel | m****i@g****m | 10 |
| CUDD | 2 | |
| lummax | l****g@g****m | 1 |
| Zdenek | 3****k | 1 |
| shaesaert | h****t@c****u | 1 |
| Blake C. Rawlings | b****w@g****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 90
- Total pull requests: 13
- Average time to close issues: 6 months
- Average time to close pull requests: 4 months
- Total issue authors: 45
- Total pull request authors: 10
- Average comments per issue: 3.06
- Average comments per pull request: 1.92
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 7
- Pull requests: 5
- Average time to close issues: about 2 months
- Average time to close pull requests: 4 days
- Issue authors: 7
- Pull request authors: 4
- Average comments per issue: 2.86
- Average comments per pull request: 1.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- johnyf (21)
- glarange (18)
- slivingston (4)
- moohtuh (3)
- rahulguptakota (2)
- mvcisback (2)
- SatarupaChak (2)
- doganulus (1)
- stephanietsuei (1)
- h3ssto (1)
- tooHotSpot (1)
- numshub (1)
- s8svtang (1)
- sskras (1)
- avinashvarna (1)
Pull Request Authors
- slivingston (2)
- zvasicek (2)
- maweki (2)
- SaiCharanMarrivada (2)
- johnyf (1)
- bcrwlngs (1)
- CazSaa (1)
- shaesaert (1)
- lummax (1)
- Alberth289346 (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 59,119 last-month
- Total docker downloads: 106
- Total dependent packages: 9
- Total dependent repositories: 36
- Total versions: 25
- Total maintainers: 3
pypi.org: dd
Binary decision diagrams implemented in pure Python, as well as Cython wrappers of CUDD, Sylvan, and BuDDy.
- Homepage: https://github.com/tulip-control/dd
- Documentation: https://github.com/tulip-control/dd/blob/main/doc.md
- License: BSD
-
Latest release: 0.6.0
published about 2 years ago
Rankings
Maintainers (3)
Dependencies
- cython ==0.29.24
- gitpython *
- grip *
- pytest >=4.6.11
- astutils *
- networkx_versions ,
- ply *
- psutil *
- pydot *
- setuptools *
- actions/checkout v2 composite
- actions/setup-python v2 composite