Comments (2)
The segmentation fault that causes the exit from the Python program (after increasing the recursion limit) is caused by the upper bound on the size of the call stack. The Python program can change the size of the call stack for new threads, and in this way avoid this error. An example of how to increase the call stack size, and handle long expressions using the module dd.autoref
, is the following (using the function threading.stack_size
):
"""How to configure CPython for long `dd` expressions."""
import faulthandler
import sys
import threading
import time
import dd.autoref as _bdd
N = 10**5
def runner():
"""Configure CPython, then run."""
sys.setrecursionlimit(10**3 * N)
faulthandler.enable()
threading.stack_size(N * 4096)
thread = threading.Thread(
target=test_long_expressions)
thread.start()
thread.join()
def test_long_expressions():
"""Create BDDs from two long expressions."""
bdd = _bdd.BDD()
bdd.declare('x')
expr = 'TRUE'
# requires increasing the recursion limit
u = add_long_expression(expr, bdd)
if u != bdd.true:
raise AssertionError(u)
print(
'success with first expression, '
f'result: {u!r}')
expr = 'x'
# requires both:
#
# - increasing the recursion limit
# - increasing the stack size
#
# (otherwise the CPython interpreter
# exits with a segmentation fault)
u = add_long_expression(expr, bdd)
if u != bdd.var('x'):
raise AssertionError(u)
print(
'success with second expression, '
f'result: {u!r}')
def add_long_expression(expr, bdd):
"""Add BDD to `bdd`, from `expr`."""
k = round(N / len(expr))
long_expr = rf'{expr} /\ ' * k + expr
print(
'attempting to add expression that '
f'contains {len(long_expr)} characters')
t_before = time.time()
u = bdd.add_expr(long_expr)
t_after = time.time()
dt = t_after - t_before
print(
'expression converted '
f'to BDD in {dt:.2f} seconds')
return u
if __name__ == '__main__':
runner()
from dd.
Thanks for the reply. This is a very elegant solution.
Meanwhile, I just divided the long expression into a set of shorter ones which actually works better in my case.
I think this can be closed now.
from dd.
Related Issues (20)
- Multi-state reliability with MDDs: problem statement HOT 9
- Example: Reachability Analysis HOT 2
- Understanding of BDD generated diagram HOT 2
- Quantifying multi-state reliability with MDDs HOT 1
- Question: Referencing children node in an MDD HOT 3
- Question: Recursive function for MDDs HOT 3
- use memory size prefixes consistently HOT 2
- install cudd using --fetch or using existing cudd build directory not working HOT 1
- Support for pure-Python ZDD implementation. HOT 2
- Question: MDD Method that returns the level of a node? HOT 1
- "bdd.let" does not work with substitutions with overlapping variables HOT 1
- using dd package properly HOT 1
- `cudd.to_expr` does not produce the correct result after reordering HOT 4
- Python 3.10 HOT 2
- AssertionError when using let HOT 2
- Question: Conversion function returning empty DiGraph
- REL: specify Python version using `Requires-Python`, not Trove classifiers for second numeric component HOT 1
- SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead HOT 5
- --install-option does not work anymore in requirements.txt HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dd.