tddlog for Python
Exact probabilistic inference from Python.
tddlog computes exact probabilities for ProbLog programs, LPADs, Dice programs, Circulette netlists and Bayesian and Markov networks, by compiling them into tree decision diagrams. This package calls the same Rust implementation as the command line and Rust crate and the C library.
Install
tddlog is not on PyPI yet. pip builds it from the repository, with
Python 3.10 or later, Rust 1.88 or newer (rustup
installs it), a C++20 compiler (GCC 11 or newer or Clang 14 or newer)
and make; the command line's
install notes say what
to do when the default cargo or g++ is older. The build takes about
four minutes on eight cores. In a virtual environment:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install "git+https://github.com/Tractables/tddlog#subdirectory=bindings/python"
From a checkout, the license and the notices are copied in first, since
pyproject.toml cannot reference files above its own directory:
git clone --depth 1 https://github.com/Tractables/tddlog
cd tddlog
mkdir -p bindings/python/notices
cp LICENSE NOTICE THIRD-PARTY.md bindings/python/notices/
python -m pip install ./bindings/python
Getting started
import tddlog
solution = tddlog.solve("""
0.1::burglary.
0.2::earthquake.
0.7::hears_alarm(john).
0.4::hears_alarm(mary).
alarm :- burglary.
alarm :- earthquake.
calls(X) :- alarm, hears_alarm(X).
evidence(calls(john), true).
query(burglary).
query(earthquake).
query(calls(mary)).
""", evidence_probability=True)
for query, probability in solution.answers.items():
print(f"{query}: {probability:.6f}")
print(f"P(e) = {solution.evidence_probability:.6f}")
prints
burglary: 0.357143
earthquake: 0.714286
calls(mary): 0.400000
P(e) = 0.196000
solution.answers maps each query, as ProbLog prints it, to its
probability given the evidence, in the program's order; it is None
where the evidence is inconsistent. solve takes the command line's
options as keywords: vtree (--vtree), evidence_probability
(--evidence-probability) and queries (False for --no-queries).
format says what the text is, as the command line tells it by the
file's extension: "problog", the default (an LPAD where it holds
:- begin_lpad.), "dice", "circulette" (a .cql netlist), or a
network's, "bif", "hugin"
(.net), "xdsl" or "uai", with every variable queried. A network's
evidence is the text of its evidence file, an Ace .inst file or, for
a UAI network, a UAI .evid file:
network = open("examples/car.net").read()
observed = open("examples/car.inst").read()
solution = tddlog.solve(network, format="hugin", evidence=observed)
arguments are a ProbLog program's, an LPAD's or a Dice program's
arguments, the values the command line takes after the program's file: a
list of strings, each the text of a term that takes the places $1, $2,
... of the program, as in tddlog.solve(open("examples/chain.pl").read(), arguments=["10", "0.9", "4"]); in a Dice program a place stands for an
integer, and its argument is a natural number.
For a UAI network, evidence_probability is the partition
function given the evidence. A
program tddlog cannot answer raises tddlog.ParseError,
GroundingError or CompilationError, with the message the command line
prints. solve releases the interpreter lock, so threads can solve
several programs at once.
The API reference
documents each function and exception, bindings/python/examples/ holds
this program and one built from Python data
(python bindings/python/examples/alarm.py in a checkout), and the
guide describes the
language, with worked examples that open in the
playground.
Develop
From the checkout, after the copy above, build the extension in place and run its tests:
python3 -m venv .venv
. .venv/bin/activate
python -m pip install 'maturin>=1.9,<2' pytest
maturin develop --release --manifest-path bindings/python/Cargo.toml
python -m pytest bindings/python/tests
maturin build --release --manifest-path bindings/python/Cargo.toml
builds a wheel instead.
Acknowledgements
This material is based upon work supported by the Defense Advanced Research Projects Agency (DARPA) under Agreement No. HR0011269E224.
Metadata
Release files for tddlog 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tddlog-0.1.0.tar.gz | 1.8 MB | Without provenance | Details for tddlog-0.1.0.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| tddlog-0.1.0-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for tddlog-0.1.0-cp310-abi3-win_amd64.whl |
| tddlog-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for tddlog-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl |
| tddlog-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details for tddlog-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl |
| tddlog-0.1.0-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for tddlog-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
| tddlog-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details for tddlog-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl |
Total release size: 30.2 MB
Release files / tddlog-0.1.0.tar.gz
| Download URL | tddlog-0.1.0.tar.gz |
|---|---|
| Size | 1.8 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
260ee15af20a33a8ce97c6888d6122a1ce6bdee71f32ae4e0d82211790462acf
|
|
BLAKE2b-256 checksum How to use checksums |
3c6c95aa9fd5e665efca2f0cc69471376c71387ee741eddd25b6e60bb2436bbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / tddlog-0.1.0-cp310-abi3-win_amd64.whl
| Download URL | tddlog-0.1.0-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
6e541bb7b5b277e80e22a96f9a2eca64a524b8e121aeb4503ed2ba95f76747d8
|
|
BLAKE2b-256 checksum How to use checksums |
de9d962408496ee2bbe487444eeca45cb37d5f7bd7a41556145179f74651d973
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / tddlog-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | tddlog-0.1.0-cp310-abi3-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
4b4c1093fbce242b3235e373b93092d77aaaebc33369d03db387ad48f8c338ed
|
|
BLAKE2b-256 checksum How to use checksums |
2bdd539e9a538b08900ddb44e62a686d3d82af5150552b8a7df4fa04b87a2165
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / tddlog-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | tddlog-0.1.0-cp310-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
04c7cfc2891e79d89e6faffce308bd1b5b1ec3cf7c4b45b059d29b2b4d963abc
|
|
BLAKE2b-256 checksum How to use checksums |
5288e00a958ba3caf17ccead3e78931720623e99f8f95206724783e9e2a33f8c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / tddlog-0.1.0-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tddlog-0.1.0-cp310-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.2 MB |
| Tags | CPython 3.10 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
1294b6d5881c098d47f0d895af11f1688259e9743416c1f596b66d3a9346d218
|
|
BLAKE2b-256 checksum How to use checksums |
f58cac60f26aec73eebc1352eb796639482686d66ea745edbcf3e80b1aefdd86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Release files / tddlog-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | tddlog-0.1.0-cp310-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 5.9 MB |
| Tags | CPython 3.10 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
e90b7b4b9a1c0b980a7f1a76045111d4e57118d18c1dc9f54c1ee19e1e2d2b55
|
|
BLAKE2b-256 checksum How to use checksums |
a1db265a7e659384359c7c8acea7287aec25e0b4db0eef53a730b4ad44397dd6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Security for tddlog 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.