libcirkit
a python framework to build, learn and reason about probabilistic circuits and tensor networks
Science Score: 54.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
✓Academic publication links
Links to: arxiv.org -
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.3%) to scientific vocabulary
Keywords
Repository
a python framework to build, learn and reason about probabilistic circuits and tensor networks
Basic Info
- Host: GitHub
- Owner: april-tools
- License: gpl-3.0
- Language: Python
- Default Branch: main
- Homepage: https://cirkit-docs.readthedocs.io
- Size: 31.7 MB
Statistics
- Stars: 118
- Watchers: 7
- Forks: 18
- Open Issues: 35
- Releases: 3
Topics
Metadata Files
README.md

What is Cirkit? :electric_plug:
cirkit is a framework for building, learning and reasoning about probabilistic machine learning models, such as circuits and tensor networks, which are tractable ( ⬆️ ) and expressive ( ➡️ ).
Main Features
- ⚡ Exact and Efficient Inference : Support for tractable operations that are automatically compiled to efficient computational graphs that run on the GPU.
- Compatible: Seamlessly integrate your circuit with deep learning models; run on any device compatible with PyTorch.
- Modular and Extensible: Support for user-defined layers and parameterizations that extend the symbolic language of cirkit.
- Templates for Common Cases : Templates for constructing circuits by mixing layers and structures with a few lines of code.
Supported Model Families and Inference
| Model Family | Queries | Notebook | | :-------------------------------------------------------: | ------------------ | ------------------------------------------------------------------------------------------------------------------ | | 📈 Monotonic Circuits | mar, con, sam, exp | Region Graphs | | 📷 PICs Circuits | mar, con, sam, exp | PICs | | 🆘 SoS Circuits | mar, con, exp | SoS |
Supported Queries
The supported queries are tabulated below.
| Abbreviation | Query | Math | Symbolic | PyTorch | | :-------: | :---------: | --------------------------------------------- | :-------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------: | | mar | marginal | $\int p(\mathbf{x}, \mathbf{z}) d\mathbf{z}$ | integrate | integrate query | | con | conditional | $p(\mathbf{x} \mid \mathbf{z})$ | integrate and evidence | integrate query | | sam | sample | $\mathbf{x} \sim p(\mathbf{x})$ | - | sampling query | | exp | expectation | $\mathbb{E}_{\mathbf{x} \sim p(\mathbf{x})}\left [ f(\mathbf{x}) \right ] = \int p(\mathbf{x})f(\mathbf{x}) d\mathbf{x}$ | multiply and integrate | - |
Symbolic vs PyTorch
Queries can be implemented either symbolically, i.e. by constructing a new circuit which implements the query [^1], or by directly applying a query to a compiled circuit in PyTorch. In the latter case, the query is evaluated using a forward pass of the existing circuit.
[^1]: Symbolic queries are especially useful when you want to combine the resulting circuit with other circuits.
Project Structure :openfilefolder:
.
├── cirkit Main Code
│ ├── backend Circuits to Numerical Operations (Currently via PyTorch backend)
│ ├── symbolic Circuits / Layers / Operators / Compilation
│ ├── templates APIs for easy use (e.g. region graphs, data modalities)
│ └── utils
├── docs
├── notebooks Start here: Examples
└── tests
How to Install the Library
cirkit currently requires Python 3.10 and PyTorch 2.3 or above versions.
Install the latest release version via pip.
shell
pip install libcirkit
For the latest development version, install from github after cloning this repository locally.
To install the required dependencies in development mode.
shell
pip install -U pip # update pip
pip install -e ".[dev]"
This will install not only the core dependencies of the library itself (e.g., PyTorch) but also additional dependencies useful for development (e.g., PyTest).
It also installs other development tools, such as Black, PyLint and MyPy.
Additional Requirements for Jupyter Notebooks
If you want to execute the Jupyter notebooks in the notebooks/ directory, then install the additional dependencies with:
shell
pip install ".[notebooks]"
Documentation 📘
For more details see the Documentation here.
Development 🛠️
Build Documentation Locally
Whenever you write documentation, you can check how it would look like by building HTML pages locally. To do so, install the dependencies for building documentation:
shell
pip install ".[docs]"
Then, run the following at the root level of the repository directory.
shell
mkdocs serve
After waiting a few seconds, you can then navigate the rendered documentation at the link http://127.0.0.1:8000/.
Automatic Code Formatting
We try to follow a consistent formatting across the library. If you want to automatically format your code, then you should run the following script.
shell
bash scripts/format.sh
Linting and Static Code Checks
Locate youself in the repository root. Then, run the following for executing the linters and other static code checkers.
shell
bash scripts/check.sh [--tool linting-tool] [file ...]
Optionally,
1. Specify --tool to select the linting tool to use. If no one is given, then all of them will be run, i.e., black, isort, pydocstyle, pylint, mypy.
2. Add files to lint part of the repo. If none is specified then, all tracked directiories will be checked.
Run Unit Tests and Check the Coverage
Locate youself in the repository root. Then, rn the following script.
shell
bash scripts/coverage.sh [--FORMAT] [pytest_arg ...]
Optionally,
1. Use a --FORMAT (e.g. --xml) flag for exporting converage to file.
2. Pass additional args to pytest (files to test etc.).
Papers :scroll:
If you want to learn more about the internals of cirkit, a good starting point is What is the Relationship between Tensor Factorizations and Circuits (and How Can We Exploit it)?.
Papers Implemented in Cirkit
| Papers | Links within Cirkit | |--------------------|------------------------| | 🆘 Subtractive Mixture Models via Squaring: Representation and Learning | SoS notebook | | 🆘 Sum of Squares Circuits | SoS notebook | | 📷 Probabilistic Integral Circuits | PICs notebook | | 📷 Scaling Continuous Latent Variable Models as Probabilistic Integral Circuits | PICs notebook | | What is the Relationship between Tensor Factorizations and Circuits (and How Can We Exploit it)? | See Region Graphs and Folding| | Random Sum-Product Networks: A Simple and Effective Approach to Probabilistic Deep Learning | See Random Binary Tree | | Einsum Networks: Fast and Scalable Learning of Tractable Probabilistic Circuits | See Optimizing the Circuit Layers |
Citation
[comment]: <> (The following bib file can be generated from the github page via the "Cite this repository" button. To update bib, simply update the CITATIONS.cff file by uploading current cff file to https://citation-file-format.github.io/ and modifying it )
If you use cirkit in your publications, please cite:
@software{The_APRIL_Lab_cirkit_2024,
author = {The APRIL Lab},
license = {GPL-3.0},
month = oct,
title = {{cirkit}},
url = {https://github.com/april-tools/cirkit},
version = {0.1},
year = {2024}
}
Owner
- Name: april-tools
- Login: april-tools
- Kind: organization
- Repositories: 6
- Profile: https://github.com/april-tools
Citation (CITATION.cff)
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: cirkit
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: The APRIL Lab
family-names:
repository-code: 'https://github.com/april-tools/cirkit'
abstract: >-
Cirkit is a machine learning library for building
probabilistic models which are efficient and expressive.
keywords:
- machine learning
- probabilistic circuits
- tensor factorizations
- sum product networks
license: GPL-3.0
commit: 5a025a9babef9434f8ddece628187eb5ba70a3f3
version: '0.1'
date-released: '2024-10-15'
GitHub Events
Total
- Create event: 30
- Release event: 5
- Issues event: 72
- Watch event: 84
- Delete event: 26
- Issue comment event: 77
- Push event: 131
- Pull request review comment event: 4
- Pull request review event: 7
- Pull request event: 90
- Fork event: 16
Last Year
- Create event: 30
- Release event: 5
- Issues event: 72
- Watch event: 84
- Delete event: 26
- Issue comment event: 77
- Push event: 131
- Pull request review comment event: 4
- Pull request review event: 7
- Pull request event: 90
- Fork event: 16
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 22
- Total pull requests: 24
- Average time to close issues: 5 months
- Average time to close pull requests: 13 days
- Total issue authors: 10
- Total pull request authors: 9
- Average comments per issue: 0.32
- Average comments per pull request: 0.42
- Merged pull requests: 9
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 20
- Pull requests: 24
- Average time to close issues: 2 months
- Average time to close pull requests: 13 days
- Issue authors: 10
- Pull request authors: 9
- Average comments per issue: 0.35
- Average comments per pull request: 0.42
- Merged pull requests: 9
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- loreloc (16)
- isurulucky (6)
- lkct (6)
- n28div (5)
- mlnpapez (3)
- LenaZellinger (1)
- DavideScassola (1)
- turnmanh (1)
- adrianjav (1)
- chenweixin107 (1)
- andreasgrv (1)
- gengala (1)
- stefanoteso (1)
Pull Request Authors
- loreloc (21)
- n28div (7)
- andreasgrv (7)
- adrianjav (4)
- isurulucky (2)
- gengala (2)
- GianpieroTulipani (1)
- turnmanh (1)
- IrwinChay (1)
- migueldecampos (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 57 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 3
- Total maintainers: 1
pypi.org: libcirkit
a python framework to build, learn and reason about probabilistic circuits and tensor networks
- Homepage: https://github.com/april-tools/cirkit
- Documentation: https://cirkit-docs.readthedocs.io
- License: GPLv3
-
Latest release: 0.2.1
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- actions/cache v4 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- actions/checkout v4 composite
- actions/setup-python v5 composite
- codecov/codecov-action v4 composite
- einops ~=0.8.0
- numpy >=1.23.0,<2.0.0
- scipy ~=1.14.0
- torch ~=2.3.0