pylimid 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pylimid-0.1.0/.github/PR_TEMPLATE.md +21 -0
- pylimid-0.1.0/.github/workflows/ci.yml +52 -0
- pylimid-0.1.0/.github/workflows/release.yml +76 -0
- pylimid-0.1.0/.gitignore +108 -0
- pylimid-0.1.0/.pre-commit-config.yaml +24 -0
- pylimid-0.1.0/.python-version +1 -0
- pylimid-0.1.0/AGENTS.md +90 -0
- pylimid-0.1.0/CONTRIBUTING.md +69 -0
- pylimid-0.1.0/LICENSE.md +202 -0
- pylimid-0.1.0/PKG-INFO +131 -0
- pylimid-0.1.0/README.md +99 -0
- pylimid-0.1.0/TODO.md +19 -0
- pylimid-0.1.0/design/ADR/13_08_2026_typed_inference_results.md +43 -0
- pylimid-0.1.0/design/ADR/16_07_2026 - initial plan.md +89 -0
- pylimid-0.1.0/design/ADR/17_07_2026_mutability_design_decision.md +59 -0
- pylimid-0.1.0/design/ADR/23_07_2026_unified_inference_architecture.md +168 -0
- pylimid-0.1.0/design/ADR/25_08_2026_numpyro_only_engine.md +67 -0
- pylimid-0.1.0/design/ADR/25_08_2026_unified_posterior_result.md +43 -0
- pylimid-0.1.0/design/README.md +86 -0
- pylimid-0.1.0/design/documentation_plan.md +153 -0
- pylimid-0.1.0/design/graph/chance_node.md +145 -0
- pylimid-0.1.0/design/graph/decision_node.md +120 -0
- pylimid-0.1.0/design/graph/diagram.md +80 -0
- pylimid-0.1.0/design/graph/multiple_utility_nodes.md +64 -0
- pylimid-0.1.0/design/graph/utility_node.md +63 -0
- pylimid-0.1.0/design/inference/backend_numpyro.md +73 -0
- pylimid-0.1.0/design/inference/backward_induction.md +61 -0
- pylimid-0.1.0/design/inference/bucket_elim.md +52 -0
- pylimid-0.1.0/design/inference/exact_engines_plan.md +67 -0
- pylimid-0.1.0/design/inference/inference_strategy.md +29 -0
- pylimid-0.1.0/design/inference/solver_algorithms.md +84 -0
- pylimid-0.1.0/design/problems/automated_logistics_center.md +82 -0
- pylimid-0.1.0/design/problems/ride_hailing.md +62 -0
- pylimid-0.1.0/docs/README.md +45 -0
- pylimid-0.1.0/docs/_static/custom.css +10 -0
- pylimid-0.1.0/docs/_static/figures/logistics_center/logistics_center.jpg +0 -0
- pylimid-0.1.0/docs/_static/figures/oil_field/5_limid_oil.png +0 -0
- pylimid-0.1.0/docs/_static/figures/oil_field/oil_field_heatmap.jpg +0 -0
- pylimid-0.1.0/docs/_static/figures/oil_field/oil_field_image.jpg +0 -0
- pylimid-0.1.0/docs/_static/figures/oil_field/rock_porosity.jpg +0 -0
- pylimid-0.1.0/docs/_templates/autosummary/class.rst +33 -0
- pylimid-0.1.0/docs/api/graph.rst +20 -0
- pylimid-0.1.0/docs/api/index.rst +7 -0
- pylimid-0.1.0/docs/api/pylimid.rst +41 -0
- pylimid-0.1.0/docs/api/solvers.rst +16 -0
- pylimid-0.1.0/docs/conf.py +106 -0
- pylimid-0.1.0/docs/getting_started/installation.md +50 -0
- pylimid-0.1.0/docs/getting_started/quickstart.md +97 -0
- pylimid-0.1.0/docs/index.md +95 -0
- pylimid-0.1.0/docs/tutorials/bayesian_networks.md +236 -0
- pylimid-0.1.0/docs/tutorials/logistics_center.md +490 -0
- pylimid-0.1.0/docs/tutorials/newsvendor.md +205 -0
- pylimid-0.1.0/docs/tutorials/oil_field.md +259 -0
- pylimid-0.1.0/docs/user_guide/building_a_diagram.md +132 -0
- pylimid-0.1.0/docs/user_guide/chance_nodes.md +137 -0
- pylimid-0.1.0/docs/user_guide/decisions_and_information_sets.md +92 -0
- pylimid-0.1.0/docs/user_guide/inference.md +125 -0
- pylimid-0.1.0/docs/user_guide/rendering.md +78 -0
- pylimid-0.1.0/docs/user_guide/scope_and_limitations.md +35 -0
- pylimid-0.1.0/docs/user_guide/solving.md +108 -0
- pylimid-0.1.0/docs/user_guide/utilities.md +87 -0
- pylimid-0.1.0/pylimid/__init__.py +49 -0
- pylimid-0.1.0/pylimid/_version.py +24 -0
- pylimid-0.1.0/pylimid/graph/__init__.py +37 -0
- pylimid-0.1.0/pylimid/graph/chance_node.py +121 -0
- pylimid-0.1.0/pylimid/graph/decision_node.py +119 -0
- pylimid-0.1.0/pylimid/graph/diagram.py +545 -0
- pylimid-0.1.0/pylimid/graph/node.py +307 -0
- pylimid-0.1.0/pylimid/graph/render/__init__.py +10 -0
- pylimid-0.1.0/pylimid/graph/render/_common.py +183 -0
- pylimid-0.1.0/pylimid/graph/render/graphviz.py +118 -0
- pylimid-0.1.0/pylimid/graph/render/mermaid.py +95 -0
- pylimid-0.1.0/pylimid/graph/utility_node.py +113 -0
- pylimid-0.1.0/pylimid/graph/validation.py +59 -0
- pylimid-0.1.0/pylimid/inference/__init__.py +43 -0
- pylimid-0.1.0/pylimid/inference/engine.py +242 -0
- pylimid-0.1.0/pylimid/inference/numpyro/__init__.py +4 -0
- pylimid-0.1.0/pylimid/inference/numpyro/model.py +109 -0
- pylimid-0.1.0/pylimid/inference/numpyro/samplers.py +122 -0
- pylimid-0.1.0/pylimid/inference/numpyro/solvers/__init__.py +38 -0
- pylimid-0.1.0/pylimid/inference/numpyro/solvers/_policy.py +114 -0
- pylimid-0.1.0/pylimid/inference/numpyro/solvers/backward_induction.py +286 -0
- pylimid-0.1.0/pylimid/inference/numpyro/solvers/batched_scan.py +181 -0
- pylimid-0.1.0/pylimid/inference/numpyro/solvers/intervention_scan.py +168 -0
- pylimid-0.1.0/pylimid/inference/numpyro/solvers/regularity.py +150 -0
- pylimid-0.1.0/pylimid/inference/result.py +174 -0
- pylimid-0.1.0/pylimid/py.typed +0 -0
- pylimid-0.1.0/pyproject.toml +97 -0
- pylimid-0.1.0/ruff.toml +40 -0
- pylimid-0.1.0/tests/__init__.py +0 -0
- pylimid-0.1.0/tests/conftest.py +1 -0
- pylimid-0.1.0/tests/graph/__init__.py +0 -0
- pylimid-0.1.0/tests/graph/render/__init__.py +0 -0
- pylimid-0.1.0/tests/graph/render/test_common.py +84 -0
- pylimid-0.1.0/tests/graph/render/test_graphviz.py +196 -0
- pylimid-0.1.0/tests/graph/render/test_mermaid.py +175 -0
- pylimid-0.1.0/tests/graph/test_chance_node.py +282 -0
- pylimid-0.1.0/tests/graph/test_decision_node.py +88 -0
- pylimid-0.1.0/tests/graph/test_diagram.py +512 -0
- pylimid-0.1.0/tests/graph/test_node.py +126 -0
- pylimid-0.1.0/tests/graph/test_probe.py +139 -0
- pylimid-0.1.0/tests/graph/test_utility_node.py +115 -0
- pylimid-0.1.0/tests/inference/__init__.py +0 -0
- pylimid-0.1.0/tests/inference/numpyro/__init__.py +0 -0
- pylimid-0.1.0/tests/inference/numpyro/_bn_fixtures.py +256 -0
- pylimid-0.1.0/tests/inference/numpyro/_clg_fixtures.py +126 -0
- pylimid-0.1.0/tests/inference/numpyro/_limid_fixtures.py +486 -0
- pylimid-0.1.0/tests/inference/numpyro/solvers/__init__.py +0 -0
- pylimid-0.1.0/tests/inference/numpyro/solvers/test_backward_induction.py +164 -0
- pylimid-0.1.0/tests/inference/numpyro/solvers/test_batched_scan.py +48 -0
- pylimid-0.1.0/tests/inference/numpyro/solvers/test_intervention_scan.py +134 -0
- pylimid-0.1.0/tests/inference/numpyro/solvers/test_regularity.py +285 -0
- pylimid-0.1.0/tests/inference/numpyro/test_compare_pyagrum.py +80 -0
- pylimid-0.1.0/tests/inference/numpyro/test_compare_pyagrum_clg.py +67 -0
- pylimid-0.1.0/tests/inference/numpyro/test_compare_pyagrum_limid.py +76 -0
- pylimid-0.1.0/tests/inference/numpyro/test_numpyro.py +343 -0
- pylimid-0.1.0/tests/inference/test_infer.py +320 -0
- pylimid-0.1.0/tests/inference/test_solve.py +210 -0
- pylimid-0.1.0/tests/test_smoke.py +25 -0
- pylimid-0.1.0/ty.toml +44 -0
- pylimid-0.1.0/uv.lock +2032 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
General notes:
|
|
3
|
+
|
|
4
|
+
* Dont break lines at 80 characters, let lines flow and the viewer will adjust
|
|
5
|
+
-->
|
|
6
|
+
|
|
7
|
+
## Summary
|
|
8
|
+
|
|
9
|
+
<!-- What does this PR do? One or two sentences. -->
|
|
10
|
+
|
|
11
|
+
## What changed
|
|
12
|
+
|
|
13
|
+
<!-- Concrete changes: new files, moved files, renamed modules, API surface. -->
|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
<!-- Motivation: why is this change needed? Link to an ADR or issue if applicable. -->
|
|
18
|
+
|
|
19
|
+
## Testing
|
|
20
|
+
|
|
21
|
+
<!-- How was this verified? Test count, manual checks, cross-validation. -->
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
|
|
8
|
+
concurrency:
|
|
9
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
10
|
+
cancel-in-progress: true
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
pre-commit:
|
|
14
|
+
name: pre-commit
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
steps:
|
|
17
|
+
- uses: actions/checkout@v7
|
|
18
|
+
- uses: astral-sh/setup-uv@v7
|
|
19
|
+
with:
|
|
20
|
+
enable-cache: true
|
|
21
|
+
- run: uv sync --all-groups
|
|
22
|
+
- run: uv run pre-commit run --all-files --show-diff-on-failure
|
|
23
|
+
|
|
24
|
+
tests:
|
|
25
|
+
name: tests (${{ matrix.python-version }})
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
timeout-minutes: 30
|
|
28
|
+
strategy:
|
|
29
|
+
fail-fast: false
|
|
30
|
+
matrix:
|
|
31
|
+
python-version: ["3.12"]
|
|
32
|
+
env:
|
|
33
|
+
UV_PYTHON: ${{ matrix.python-version }}
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@v7
|
|
36
|
+
- uses: astral-sh/setup-uv@v7
|
|
37
|
+
with:
|
|
38
|
+
enable-cache: true
|
|
39
|
+
- run: uv sync --all-groups
|
|
40
|
+
- run: uv run pytest tests/
|
|
41
|
+
|
|
42
|
+
docs:
|
|
43
|
+
name: docs
|
|
44
|
+
runs-on: ubuntu-latest
|
|
45
|
+
timeout-minutes: 30
|
|
46
|
+
steps:
|
|
47
|
+
- uses: actions/checkout@v7
|
|
48
|
+
- uses: astral-sh/setup-uv@v7
|
|
49
|
+
with:
|
|
50
|
+
enable-cache: true
|
|
51
|
+
- run: uv sync --all-groups
|
|
52
|
+
- run: uv run sphinx-build -W docs docs/_build/html
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags: ["v*"]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
build:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v7
|
|
16
|
+
with:
|
|
17
|
+
fetch-depth: 0
|
|
18
|
+
- uses: astral-sh/setup-uv@v7
|
|
19
|
+
- run: uv build
|
|
20
|
+
- uses: actions/upload-artifact@v7
|
|
21
|
+
with:
|
|
22
|
+
name: dist
|
|
23
|
+
path: dist/
|
|
24
|
+
|
|
25
|
+
testpypi:
|
|
26
|
+
if: github.event_name == 'workflow_dispatch'
|
|
27
|
+
needs: build
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
environment:
|
|
30
|
+
name: testpypi
|
|
31
|
+
url: https://test.pypi.org/p/pylimid
|
|
32
|
+
permissions:
|
|
33
|
+
id-token: write
|
|
34
|
+
contents: read
|
|
35
|
+
attestations: write
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/download-artifact@v8
|
|
38
|
+
with:
|
|
39
|
+
name: dist
|
|
40
|
+
path: dist/
|
|
41
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
42
|
+
with:
|
|
43
|
+
repository-url: https://test.pypi.org/legacy/
|
|
44
|
+
|
|
45
|
+
pypi:
|
|
46
|
+
if: github.event_name == 'push'
|
|
47
|
+
needs: build
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
environment:
|
|
50
|
+
name: pypi
|
|
51
|
+
url: https://pypi.org/p/pylimid
|
|
52
|
+
permissions:
|
|
53
|
+
id-token: write
|
|
54
|
+
contents: read
|
|
55
|
+
attestations: write
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/download-artifact@v8
|
|
58
|
+
with:
|
|
59
|
+
name: dist
|
|
60
|
+
path: dist/
|
|
61
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
62
|
+
|
|
63
|
+
github-release:
|
|
64
|
+
if: github.event_name == 'push'
|
|
65
|
+
needs: pypi
|
|
66
|
+
runs-on: ubuntu-latest
|
|
67
|
+
permissions:
|
|
68
|
+
contents: write
|
|
69
|
+
steps:
|
|
70
|
+
- uses: actions/download-artifact@v8
|
|
71
|
+
with:
|
|
72
|
+
name: dist
|
|
73
|
+
path: dist/
|
|
74
|
+
- env:
|
|
75
|
+
GH_TOKEN: ${{ github.token }}
|
|
76
|
+
run: gh release create "${GITHUB_REF_NAME}" dist/* --repo "${GITHUB_REPOSITORY}" --generate-notes
|
pylimid-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
data/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
*.manifest
|
|
32
|
+
*.spec
|
|
33
|
+
|
|
34
|
+
# Installer logs
|
|
35
|
+
pip-log.txt
|
|
36
|
+
pip-delete-this-directory.txt
|
|
37
|
+
|
|
38
|
+
# Log files
|
|
39
|
+
*.log
|
|
40
|
+
*.log.[0-9]*
|
|
41
|
+
logs/
|
|
42
|
+
|
|
43
|
+
# Environments
|
|
44
|
+
.env
|
|
45
|
+
.env.local
|
|
46
|
+
.env.*.local
|
|
47
|
+
.venv
|
|
48
|
+
venv/
|
|
49
|
+
env/
|
|
50
|
+
ENV/
|
|
51
|
+
env.bak/
|
|
52
|
+
venv.bak/
|
|
53
|
+
|
|
54
|
+
# IDE settings
|
|
55
|
+
.idea/
|
|
56
|
+
*.idea
|
|
57
|
+
../.idea/
|
|
58
|
+
.vscode/
|
|
59
|
+
*.swp
|
|
60
|
+
*.swo
|
|
61
|
+
|
|
62
|
+
# macOS
|
|
63
|
+
.DS_Store
|
|
64
|
+
|
|
65
|
+
# Windows
|
|
66
|
+
Thumbs.db
|
|
67
|
+
|
|
68
|
+
# Unit test / coverage reports
|
|
69
|
+
htmlcov/
|
|
70
|
+
.tox/
|
|
71
|
+
.nox/
|
|
72
|
+
.coverage
|
|
73
|
+
.coverage.*
|
|
74
|
+
.cache
|
|
75
|
+
nosetests.xml
|
|
76
|
+
coverage.xml
|
|
77
|
+
*.cover
|
|
78
|
+
*.py,cover
|
|
79
|
+
.hypothesis/
|
|
80
|
+
.pytest_cache/
|
|
81
|
+
cover/
|
|
82
|
+
TEST*.xml
|
|
83
|
+
|
|
84
|
+
# Jupyter Notebook
|
|
85
|
+
.ipynb_checkpoints
|
|
86
|
+
|
|
87
|
+
# mypy
|
|
88
|
+
.mypy_cache/
|
|
89
|
+
|
|
90
|
+
# Project specific
|
|
91
|
+
.cursor/
|
|
92
|
+
pylimid/_version.py
|
|
93
|
+
|
|
94
|
+
# Sphinx
|
|
95
|
+
docs/_build/
|
|
96
|
+
docs/api/generated/
|
|
97
|
+
|
|
98
|
+
# Translations
|
|
99
|
+
*.mo
|
|
100
|
+
*.pot
|
|
101
|
+
|
|
102
|
+
# Applications
|
|
103
|
+
*.app
|
|
104
|
+
*.exe
|
|
105
|
+
*.war
|
|
106
|
+
|
|
107
|
+
# LLMs
|
|
108
|
+
.zcode/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
default_install_hook_types: [pre-commit]
|
|
2
|
+
|
|
3
|
+
repos:
|
|
4
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
5
|
+
rev: v0.16.0
|
|
6
|
+
hooks:
|
|
7
|
+
- id: ruff
|
|
8
|
+
args:
|
|
9
|
+
- --fix
|
|
10
|
+
- --config
|
|
11
|
+
- ruff.toml
|
|
12
|
+
- id: ruff-format
|
|
13
|
+
args:
|
|
14
|
+
- --config
|
|
15
|
+
- ruff.toml
|
|
16
|
+
|
|
17
|
+
- repo: local
|
|
18
|
+
hooks:
|
|
19
|
+
- id: ty-check
|
|
20
|
+
name: ty check
|
|
21
|
+
entry: uv run --frozen ty check
|
|
22
|
+
language: system
|
|
23
|
+
types: [python]
|
|
24
|
+
pass_filenames: false
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
pylimid-0.1.0/AGENTS.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# pylimid
|
|
2
|
+
|
|
3
|
+
## Build, lint, test
|
|
4
|
+
```bash
|
|
5
|
+
uv run ruff check . # lint
|
|
6
|
+
uv run ruff format --check . # format check
|
|
7
|
+
uv run ty check # type check
|
|
8
|
+
uv run pytest tests/ # run tests
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Code style
|
|
12
|
+
- Google-style docstrings for all public functions, methods, and classes.
|
|
13
|
+
- Cross-references to public names use single backticks: `Snapshot`, `InfluenceDiagram.validate`. The documentation site resolves them into links (Sphinx `default_role`). No explicit Sphinx roles (`:class:`, `:func:`).
|
|
14
|
+
- Literal code and values use double backticks: ``None``, ``num_samples=500``, ``jnp``.
|
|
15
|
+
|
|
16
|
+
Example:
|
|
17
|
+
```python
|
|
18
|
+
def add_edge(self, parent: str, child: str) -> None:
|
|
19
|
+
"""
|
|
20
|
+
Wire an edge parent -> child.
|
|
21
|
+
|
|
22
|
+
Both endpoints must already be in the diagram; see `InfluenceDiagram.add_node`.
|
|
23
|
+
|
|
24
|
+
Args:
|
|
25
|
+
parent: Name of the parent node.
|
|
26
|
+
child: Name of the child node.
|
|
27
|
+
|
|
28
|
+
Raises:
|
|
29
|
+
KeyError: If either endpoint is not in the diagram.
|
|
30
|
+
ValueError: If the edge would create a cycle or the child is a utility node.
|
|
31
|
+
"""
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Comments and docs in code
|
|
35
|
+
- Do not reference intermediate design notes, ADRs-in-progress, option letters (A/B/C), ticket numbers, or `design/*.md` files from code comments or docstrings. Those files are temporary and will confuse readers later.
|
|
36
|
+
- Docstrings describe what the code does and its inputs/outputs — not the history of the decision.
|
|
37
|
+
|
|
38
|
+
## Production API over testability
|
|
39
|
+
- Do not add parameters, hooks, or injection points "so tests can override." Production callers define the API; tests adapt (fixtures, monkeypatch) if needed. This does not forbid dependency injection that production itself needs.
|
|
40
|
+
- Do not keep unused helpers or constants only for tests.
|
|
41
|
+
|
|
42
|
+
## Defensive code
|
|
43
|
+
Don't add defensive code for cases that can't happen. If data is already cleaned upstream (by a SQL `WHERE`, a model output contract, a config enum, or an earlier step in this codebase), don't re-clean it in Python — let bad data fail loudly instead of silently coercing it. Silent fallbacks (`errors="coerce"`, `fillna`, `np.where(..., default)`, `dict.get(key, default)`) hide real problems; a loud `ValueError` (or `NotImplementedError` while scaffolding) surfaces them.
|
|
44
|
+
|
|
45
|
+
Do not wrap obvious failures in friendlier exceptions "just in case" (e.g. catching `KeyError` to re-raise `ValueError`). Prefer the natural failure.
|
|
46
|
+
|
|
47
|
+
Example — remove this:
|
|
48
|
+
```python
|
|
49
|
+
# `marginal()` already summed out every variable not in `target_order`,
|
|
50
|
+
# so the lookup below can never miss.
|
|
51
|
+
old_lookup = {v: assignment[target_order.index(v)] for v in target_order}
|
|
52
|
+
old_tuple = tuple(old_lookup.get(v, 0) for v in self.variables)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Just index the dict — the invariant makes the default unreachable, and if it ever breaks you want a loud `KeyError`, not silently wrong probabilities:
|
|
56
|
+
```python
|
|
57
|
+
old_tuple = tuple(old_lookup[v] for v in self.variables)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Writing Markdown files
|
|
61
|
+
`docs/` holds only the published Sphinx documentation, written for users. Development notes for contributors (decision records, design notes, plans) go in `design/`.
|
|
62
|
+
|
|
63
|
+
Dont break lines at 80 characters, let lines flow and the viewer will adjust
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
## Philosophy
|
|
67
|
+
Follow the Zen of Python:
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
Beautiful is better than ugly.
|
|
71
|
+
Explicit is better than implicit.
|
|
72
|
+
Simple is better than complex.
|
|
73
|
+
Complex is better than complicated.
|
|
74
|
+
Flat is better than nested.
|
|
75
|
+
Sparse is better than dense.
|
|
76
|
+
Readability counts.
|
|
77
|
+
Special cases aren't special enough to break the rules.
|
|
78
|
+
Although practicality beats purity.
|
|
79
|
+
Errors should never pass silently.
|
|
80
|
+
Unless explicitly silenced.
|
|
81
|
+
In the face of ambiguity, refuse the temptation to guess.
|
|
82
|
+
There should be one-- and preferably only one --obvious way to do it.
|
|
83
|
+
Although that way may not be obvious at first unless you're Dutch.
|
|
84
|
+
Now is better than never.
|
|
85
|
+
Although never is often better than *right* now.
|
|
86
|
+
If the implementation is hard to explain, it's a bad idea.
|
|
87
|
+
If the implementation is easy to explain, it may be a good idea.
|
|
88
|
+
Namespaces are one honking great idea -- let's do more of those!
|
|
89
|
+
```
|
|
90
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Contributing to pylimid
|
|
2
|
+
|
|
3
|
+
Thanks for your interest in improving pylimid. This guide covers the development setup, the checks a change has to pass, and the conventions the project follows.
|
|
4
|
+
|
|
5
|
+
## Development setup
|
|
6
|
+
|
|
7
|
+
pylimid requires Python 3.12 and [uv](https://docs.astral.sh/uv/).
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
git clone https://github.com/cynosural-ai/pylimid
|
|
11
|
+
cd pylimid
|
|
12
|
+
uv sync --all-groups
|
|
13
|
+
pre-commit install
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`uv sync --all-groups` installs the dev, test, and docs dependency groups. `pre-commit install` wires the lint and type-check hooks.
|
|
17
|
+
|
|
18
|
+
## Checks
|
|
19
|
+
|
|
20
|
+
Run these before opening a pull request:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
uv run ruff check . # lint
|
|
24
|
+
uv run ruff format --check . # formatting
|
|
25
|
+
uv run ty check # type check
|
|
26
|
+
uv run pytest tests/ # tests
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Ruff and ty also run on every commit through pre-commit.
|
|
30
|
+
|
|
31
|
+
## Repository layout
|
|
32
|
+
|
|
33
|
+
| Path | Contents |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `pylimid/graph/` | Node types, the mutable `InfluenceDiagram`, validation, and rendering |
|
|
36
|
+
| `pylimid/inference/` | The NumPyro engine, solvers, and result types |
|
|
37
|
+
| `tests/` | The pytest suite; fully discrete models are cross-checked against pyAgrum |
|
|
38
|
+
| `docs/` | The published Sphinx site (see `docs/README.md` for build details) |
|
|
39
|
+
| `design/` | Contributor-facing decision records and design notes; not published |
|
|
40
|
+
| `AGENTS.md` | Detailed code style and design conventions |
|
|
41
|
+
|
|
42
|
+
## Conventions
|
|
43
|
+
|
|
44
|
+
The full conventions live in [AGENTS.md](AGENTS.md); the highlights:
|
|
45
|
+
|
|
46
|
+
- Google-style docstrings for every public function, method, and class.
|
|
47
|
+
- Public API names in single backticks (`` `Snapshot` ``), literals in double backticks (`` ``None`` ``).
|
|
48
|
+
- No comments that reference design notes, ADRs, or ticket numbers; docstrings describe what the code does, not the history of the decision.
|
|
49
|
+
- Prefer a loud failure over a silent fallback, and do not defensively re-clean data an earlier step already guarantees.
|
|
50
|
+
- The production API comes first: do not add parameters, hooks, or injection points just so tests can override them.
|
|
51
|
+
|
|
52
|
+
## Documentation
|
|
53
|
+
|
|
54
|
+
Build the site with:
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
uv run sphinx-build -W docs docs/_build/html
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
The `-W` flag turns warnings into errors. Prose pages are Markdown; pages with executable snippets carry `file_format: mystnb` frontmatter and use `{code-cell}` fences. Add a new page to the appropriate `{toctree}` in `docs/index.md`. Development notes for contributors belong in `design/`, not `docs/`.
|
|
61
|
+
|
|
62
|
+
## Pull requests
|
|
63
|
+
|
|
64
|
+
- Keep each pull request focused on one change.
|
|
65
|
+
- Fill in the repository's pull request template: summary, what changed, why, and how it was tested.
|
|
66
|
+
- Add or update tests for behavior changes. For discrete models, pyAgrum provides the exact reference.
|
|
67
|
+
- Update the docs when the public API or behavior changes.
|
|
68
|
+
|
|
69
|
+
By contributing, you agree that your contributions are licensed under the Apache License 2.0.
|
pylimid-0.1.0/LICENSE.md
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|