Practical overview
When it fits
Use SPFlow when a Python workflow needs probabilistic circuits that can be constructed from modules, learned from data, and queried for inference.
Who it is for
- Python developers building probabilistic models
- Practitioners who need to learn circuit structures or distribution parameters from data
- Researchers or developers evaluating probabilistic circuits for inference tasks
Documented uses
- Compose probabilistic circuits from distribution leaves and sum or product modules.
- Learn circuit structure and fit distribution parameters using gradient descent or expectation-maximization.
- Evaluate log-likelihoods and generate samples from a constructed circuit.
- Run supported inference queries, including range queries with interval-based evidence.
Requirements & limits
- Requires Python 3.10 or later and PyTorch 2.0 or later.
- Graphviz is optional and is used for circuit visualization.
- The layered composition approach is documented as more compact and better suited to scaling than manually composing nodes.
- The included algebraic DSL is example-oriented and distinct from the core module API.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install SPFlow and construct a small circuit
Install the library and create a two-variable probabilistic circuit using its documented node-based example.
Before you start
- Python 3.10 or later with pip or uv
- PyTorch 2.0 or later; the installation guide says it is installed automatically with SPFlow
Steps
Install SPFlow with the command below.
pip install spflowImport PyTorch and the Sum, Product, and Normal modules.
Create Normal leaf nodes for variables with scopes 0 and 1, combine them with Product nodes, and assemble the products with a Sum node.
Pass data to the circuit's
log_likelihoodmethod or use itssamplemethod.
Expected outcome
A constructed probabilistic circuit that can evaluate log-likelihoods or generate samples.
Guide limitations
- The documented example demonstrates construction and queries; it does not provide a complete model-training workflow.
- Graphviz is optional and only needed for the documented visualization step.
Build a circuit from the example DSL
Turn an algebraic expression for a small circuit into an SPFlow module and evaluate it on data.
Before you start
- Python 3.10 or later
- PyTorch 2.0 or later
- SPFlow installed
Steps
Import
Normalfromspflow.modules.leavesanddslfromspflow.dsl.Within a
dsl()context, write a mixture expression combining Normal leaves with multiplication and addition.Call
.build()on the expression to obtain an SPFlow module.Pass a PyTorch tensor to
log_likelihood.
Expected outcome
An SPFlow module built from an algebraic circuit expression, with log-likelihood output for supplied data.
Guide limitations
- The documentation describes this DSL as example-oriented and intended for small circuits; the core
spflow.modulesAPI is separate.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 13 November 2026

