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. This package calls the same Rust implementation as the command line.
Install
pip install tddlog
Wheels cover CPython 3.10 and later on Linux and macOS (x86-64 and ARM64) and Windows x86-64. Elsewhere pip builds from source (Build from source, below).
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.answersmaps each query to its probability given the evidence, in the program's order. It isNonewhere the evidence is inconsistent.formatsays what the text is:"problog"(the default, LPADs included),"dice","circulette", or a network's"bif","hugin","xdsl"or"uai".evidenceis the text of a network's evidence file (Ace's.instor UAI's.evid).argumentsis a list of strings that take the program's places$1,$2, ...vtree,evidence_probabilityandqueriesare the command line's--vtree,--evidence-probabilityand--no-queries.- An error raises
tddlog.ParseError,GroundingErrororCompilationError, with the command line's message. solvereleases the interpreter lock, so threads can solve several programs at once.
A network with evidence, in a checkout of the repository:
network = open("examples/car.net").read()
observed = open("examples/car.inst").read()
solution = tddlog.solve(network, format="hugin", evidence=observed)
The API reference
documents each function and exception, and bindings/python/examples/
holds this program and one built from Python data. The
guide describes the
language, and its worked examples open in the
playground. The
website has the benchmark results.
Build from source
pip builds the package from the repository, for a commit after the
release. This needs Python 3.10 or later, Rust 1.88 or newer
(rustup installs it), a C++20 compiler and make.
The guide's
getting started
says what to do if the build fails.
python3 -m venv .venv
. .venv/bin/activate
python -m pip install "git+https://github.com/Tractables/tddlog#subdirectory=bindings/python"
From a checkout, copy the license and the notices in first:
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
To work on the binding, build the extension in place and run its tests:
python -m pip install 'maturin>=1.9,<2' pytest
maturin develop --release --manifest-path bindings/python/Cargo.toml
python -m pytest bindings/python/tests
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.1
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.1.tar.gz | 1.1 MB | Without provenance | Details for tddlog-0.1.1.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| tddlog-0.1.1-cp310-abi3-win_amd64.whl | CPython 3.10 | abi3 | Windows x86-64 | Details for tddlog-0.1.1-cp310-abi3-win_amd64.whl |
| tddlog-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ x86-64 | Details for tddlog-0.1.1-cp310-abi3-manylinux_2_28_x86_64.whl |
| tddlog-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl | CPython 3.10 | abi3 | Linux glibc 2.28+ ARM64 | Details for tddlog-0.1.1-cp310-abi3-manylinux_2_28_aarch64.whl |
| tddlog-0.1.1-cp310-abi3-macosx_11_0_arm64.whl | CPython 3.10 | abi3 | macOS 11.0+ ARM64 | Details for tddlog-0.1.1-cp310-abi3-macosx_11_0_arm64.whl |
| tddlog-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl | CPython 3.10 | abi3 | macOS 10.12+ x86-64 | Details for tddlog-0.1.1-cp310-abi3-macosx_10_12_x86_64.whl |
Total release size: 29.6 MB
Release files / tddlog-0.1.1.tar.gz
| Download URL | tddlog-0.1.1.tar.gz |
|---|---|
| Size | 1.1 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
716e36de565c2d1471955efa2d9c5d7b46b4f131f896ccf2db34ca84b9c20683
|
|
BLAKE2b-256 checksum How to use checksums |
3710c34f03b51c359aac3c63ba89f9f1f1057efd8fa868b5e149542f4405b938
|
| 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.1-cp310-abi3-win_amd64.whl
| Download URL | tddlog-0.1.1-cp310-abi3-win_amd64.whl |
|---|---|
| Size | 6.2 MB |
| Tags | CPython 3.10 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
52d2ac2684891a8426604d10df587416eed1d2b75801750791b3921558448da3
|
|
BLAKE2b-256 checksum How to use checksums |
e0cb563514eebb74a00cec1db77de71622d7caa756129a969fb17610c3361354
|
| 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.1-cp310-abi3-manylinux_2_28_x86_64.whl
| Download URL | tddlog-0.1.1-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 |
df69ce74997fee56b12a44e8a70c2973eb2fe5122693c35741c7d140f63003a2
|
|
BLAKE2b-256 checksum How to use checksums |
18aeb0a8eafbb588f65fbba0e9edd3310ac22ad18b79daa09882cece9dd3817e
|
| 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.1-cp310-abi3-manylinux_2_28_aarch64.whl
| Download URL | tddlog-0.1.1-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 |
19a7f099084a518e1652735413453af20dd6f54eabed2d55c1b863c60946b1d0
|
|
BLAKE2b-256 checksum How to use checksums |
5200fed6217ae9afb1170ff8bf811526d17616735dc5ee26b15a9e52f4299c94
|
| 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.1-cp310-abi3-macosx_11_0_arm64.whl
| Download URL | tddlog-0.1.1-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 |
b30a35b0be84c789735e3e274b6ff4f552a921774de61fa61600c73387c7244d
|
|
BLAKE2b-256 checksum How to use checksums |
79428f8cc153a2463c512af9477b7f4c2b442f1eae9d858bd996f37e477ce611
|
| 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.1-cp310-abi3-macosx_10_12_x86_64.whl
| Download URL | tddlog-0.1.1-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 |
f48f216b03ee7e114b7df849544dcbbe44745126b6716f532dfbc405ffa77e25
|
|
BLAKE2b-256 checksum How to use checksums |
949ed215040338af834bfe186e0f8f9403d7e4dc6b677a1fec8a3b843622a133
|
| 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.1
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.