Skip to main content

Fold-BDD

Library for folding (or reducing) over a Reduced Ordered Binary Decision Diagram.

Build Status codecov PyPI version License: MIT

Table of Contents

Installation

If you just need to use fold_bdd, you can just run:

$ pip install fold-bdd

For developers, note that this project uses the poetry python package/dependency management tool. Please familarize yourself with it and then run:

$ poetry install

Usage

The fold-bdd library supports two types of folds:

  1. Folding over the DAG of a BDD starting at the root and then recursively merging the low and high branches until the True/False leaves. This is simply a compressed variant of a post-order traversal.

  2. Folding over a path in the DAG, starting at the root and moving the the corresponding leaf (left fold).

In both cases, local context such as the levels of the parent and child nodes are passed in.

As input, each of these take in a bdd, from the dd library and function for accumulating or merging.

The following example illustrates how to use fold_bdd to count the number of solutions to a predicate using post_order and evaluate a path using fold_path.

Create ROBDD

# Create BDD.
from dd.cudd import BDD

manager = BDD()
manager.declare('x', 'y')
manager.reorder({'x': 1, 'y': 0})
manger.configure(reordering=False)

bexpr = manager.add_expr('x | y')

Post-Order Examples

from fold_bdd import post_order

Count Number of Nodes in BDD

def merge1(ctx, low=None, high=None):
    return 1 if low is None else low + high

def dag_size(bexpr):
    return post_order(bexpr, merge1)

assert bexpr.dag_size == dag_size(bexpr)

Fold Path Examples

Count nodes along path.

def merge(ctx, val, acc):
    return acc + 1

def count_nodes(bexpr, vals):
    return fold_path(merge, bexpr, vals, initial=0)

assert count_nodes(bexpr, (False, False)) == 3
assert count_nodes(bexpr, (True, False)) == 2

Context Object Attributes

The Context object contains exposes attributes

  • node: Hashable # Reference to Node in ROBDD.
  • node_val: Union[str, bool] # Node name or leaf value.
  • negated: bool # Is the edge to prev node negated.
  • first_lvl: int # Level of first decision in ROBDD.
  • max_lvl: int # How many decision variables are there.
  • curr_lvl: int # Which decision is this.
  • low_lvl: Optional[int] # Which decision does the False edge point to. None if leaf.
  • high_lvl: Optional[int] # Which decision does the True edge point to. None if leaf.
  • is_leaf: bool # Is the current node a leaf.
  • skipped: int # How many decisions were skipped on edge to this node.

Metadata

Release files for fold-bdd 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fold-bdd 0.6.0
File Size Uploaded
fold-bdd-0.6.0.tar.gz 5.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fold-bdd 0.6.0
File Interpreter ABI Platform
fold_bdd-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 11.6 kB

Release files / fold-bdd-0.6.0.tar.gz

Download URL fold-bdd-0.6.0.tar.gz
Size 5.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7a550c234c93f212746785ed24cb5a99232b2dd6ea15a9554a3aed24d653e4a0
BLAKE2b-256 checksum
How to use checksums
7bfb1079a7b745a5ca5259e52364be849e18a9fbbf12586d97e3adfb03f6e68d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.2 CPython/3.8.1 Linux/5.5.0-1-MANJARO

Release files / fold_bdd-0.6.0-py3-none-any.whl

Download URL fold_bdd-0.6.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
759420c46e35f21eea594971c2c13f9c5474185058c97435150e685350cc751c
BLAKE2b-256 checksum
How to use checksums
27e3401a7c2ecbe2789343450030cb664defa49fd7ccb57009c925adc3b023fe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.0.2 CPython/3.8.1 Linux/5.5.0-1-MANJARO

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page