quivers 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.
- quivers-0.1.0/.claude/settings.local.json +17 -0
- quivers-0.1.0/.github/workflows/ci.yml +42 -0
- quivers-0.1.0/.github/workflows/docs.yml +38 -0
- quivers-0.1.0/.gitignore +39 -0
- quivers-0.1.0/CHANGELOG.md +67 -0
- quivers-0.1.0/CONTRIBUTING.md +270 -0
- quivers-0.1.0/LICENSE +21 -0
- quivers-0.1.0/PKG-INFO +187 -0
- quivers-0.1.0/README.md +153 -0
- quivers-0.1.0/docs/api/categorical/adjunctions.md +5 -0
- quivers-0.1.0/docs/api/categorical/base_change.md +5 -0
- quivers-0.1.0/docs/api/categorical/functors.md +5 -0
- quivers-0.1.0/docs/api/categorical/monoidal.md +5 -0
- quivers-0.1.0/docs/api/categorical/natural_transformations.md +5 -0
- quivers-0.1.0/docs/api/categorical/traced.md +5 -0
- quivers-0.1.0/docs/api/continuous/boundaries.md +5 -0
- quivers-0.1.0/docs/api/continuous/families.md +5 -0
- quivers-0.1.0/docs/api/continuous/flows.md +5 -0
- quivers-0.1.0/docs/api/continuous/morphisms.md +5 -0
- quivers-0.1.0/docs/api/continuous/programs.md +5 -0
- quivers-0.1.0/docs/api/continuous/spaces.md +5 -0
- quivers-0.1.0/docs/api/core/extra_quantales.md +5 -0
- quivers-0.1.0/docs/api/core/morphisms.md +5 -0
- quivers-0.1.0/docs/api/core/objects.md +5 -0
- quivers-0.1.0/docs/api/core/quantales.md +5 -0
- quivers-0.1.0/docs/api/core/tensor_ops.md +5 -0
- quivers-0.1.0/docs/api/core/util.md +5 -0
- quivers-0.1.0/docs/api/dsl/ast_nodes.md +5 -0
- quivers-0.1.0/docs/api/dsl/compiler.md +5 -0
- quivers-0.1.0/docs/api/dsl/lexer.md +5 -0
- quivers-0.1.0/docs/api/dsl/parser.md +5 -0
- quivers-0.1.0/docs/api/dsl/tokens.md +5 -0
- quivers-0.1.0/docs/api/enriched/day_convolution.md +5 -0
- quivers-0.1.0/docs/api/enriched/ends_coends.md +5 -0
- quivers-0.1.0/docs/api/enriched/kan_extensions.md +5 -0
- quivers-0.1.0/docs/api/enriched/optics.md +5 -0
- quivers-0.1.0/docs/api/enriched/profunctors.md +5 -0
- quivers-0.1.0/docs/api/enriched/weighted_limits.md +5 -0
- quivers-0.1.0/docs/api/enriched/yoneda.md +5 -0
- quivers-0.1.0/docs/api/index.md +93 -0
- quivers-0.1.0/docs/api/inference/conditioning.md +5 -0
- quivers-0.1.0/docs/api/inference/elbo.md +5 -0
- quivers-0.1.0/docs/api/inference/guide.md +5 -0
- quivers-0.1.0/docs/api/inference/predictive.md +5 -0
- quivers-0.1.0/docs/api/inference/svi.md +5 -0
- quivers-0.1.0/docs/api/inference/trace.md +5 -0
- quivers-0.1.0/docs/api/monadic/algebras.md +5 -0
- quivers-0.1.0/docs/api/monadic/comonads.md +5 -0
- quivers-0.1.0/docs/api/monadic/distributive_laws.md +5 -0
- quivers-0.1.0/docs/api/monadic/monads.md +5 -0
- quivers-0.1.0/docs/api/program.md +5 -0
- quivers-0.1.0/docs/api/stochastic/biclosed.md +42 -0
- quivers-0.1.0/docs/api/stochastic/categories.md +7 -0
- quivers-0.1.0/docs/api/stochastic/families.md +5 -0
- quivers-0.1.0/docs/api/stochastic/giry.md +5 -0
- quivers-0.1.0/docs/api/stochastic/inside.md +5 -0
- quivers-0.1.0/docs/api/stochastic/morphisms.md +5 -0
- quivers-0.1.0/docs/api/stochastic/parsers.md +13 -0
- quivers-0.1.0/docs/api/stochastic/quantale.md +5 -0
- quivers-0.1.0/docs/api/stochastic/queries.md +5 -0
- quivers-0.1.0/docs/api/stochastic/rules.md +11 -0
- quivers-0.1.0/docs/api/stochastic/semiring.md +5 -0
- quivers-0.1.0/docs/api/stochastic/transforms.md +5 -0
- quivers-0.1.0/docs/css/custom.css +90 -0
- quivers-0.1.0/docs/css/pygments.css +85 -0
- quivers-0.1.0/docs/developer/changelog.md +67 -0
- quivers-0.1.0/docs/developer/contributing.md +291 -0
- quivers-0.1.0/docs/examples/bayesian-regression.md +71 -0
- quivers-0.1.0/docs/examples/bidirectional-rnn.md +69 -0
- quivers-0.1.0/docs/examples/ccg.md +53 -0
- quivers-0.1.0/docs/examples/continuous-hmm.md +92 -0
- quivers-0.1.0/docs/examples/custom-rules.md +98 -0
- quivers-0.1.0/docs/examples/elman-rnn.md +64 -0
- quivers-0.1.0/docs/examples/gru.md +77 -0
- quivers-0.1.0/docs/examples/hmm.md +51 -0
- quivers-0.1.0/docs/examples/index.md +509 -0
- quivers-0.1.0/docs/examples/lstm.md +95 -0
- quivers-0.1.0/docs/examples/mixture-model.md +115 -0
- quivers-0.1.0/docs/examples/multimodal-tlg.md +60 -0
- quivers-0.1.0/docs/examples/pcfg.md +70 -0
- quivers-0.1.0/docs/examples/transformer.md +92 -0
- quivers-0.1.0/docs/examples/type-logical.md +56 -0
- quivers-0.1.0/docs/examples/vae.md +67 -0
- quivers-0.1.0/docs/examples/vanilla-rnn.md +70 -0
- quivers-0.1.0/docs/getting-started/architecture.md +158 -0
- quivers-0.1.0/docs/getting-started/installation.md +55 -0
- quivers-0.1.0/docs/getting-started/quickstart.md +229 -0
- quivers-0.1.0/docs/guides/categorical.md +207 -0
- quivers-0.1.0/docs/guides/continuous.md +332 -0
- quivers-0.1.0/docs/guides/core.md +201 -0
- quivers-0.1.0/docs/guides/dsl.md +944 -0
- quivers-0.1.0/docs/guides/enriched.md +281 -0
- quivers-0.1.0/docs/guides/index.md +33 -0
- quivers-0.1.0/docs/guides/inference.md +326 -0
- quivers-0.1.0/docs/guides/monadic.md +244 -0
- quivers-0.1.0/docs/guides/morphisms.md +201 -0
- quivers-0.1.0/docs/guides/programs.md +273 -0
- quivers-0.1.0/docs/guides/stochastic.md +241 -0
- quivers-0.1.0/docs/hooks/register_qvr_lexer.py +209 -0
- quivers-0.1.0/docs/index.md +55 -0
- quivers-0.1.0/docs/js/disable-hljs.js +14 -0
- quivers-0.1.0/docs/overrides/.gitkeep +0 -0
- quivers-0.1.0/docs/tutorials/first-quiver.md +208 -0
- quivers-0.1.0/docs/tutorials/fuzzy-factorization.md +163 -0
- quivers-0.1.0/docs/tutorials/index.md +37 -0
- quivers-0.1.0/docs/tutorials/probabilistic-programs.md +278 -0
- quivers-0.1.0/docs/tutorials/stochastic-relations.md +258 -0
- quivers-0.1.0/docs/tutorials/variational-inference.md +335 -0
- quivers-0.1.0/editors/vscode-qvr/language-configuration.json +39 -0
- quivers-0.1.0/editors/vscode-qvr/package.json +39 -0
- quivers-0.1.0/editors/vscode-qvr/syntaxes/qvr.tmLanguage.json +115 -0
- quivers-0.1.0/mkdocs.yml +172 -0
- quivers-0.1.0/pyproject.toml +65 -0
- quivers-0.1.0/src/quivers/__init__.py +486 -0
- quivers-0.1.0/src/quivers/categorical/__init__.py +69 -0
- quivers-0.1.0/src/quivers/categorical/adjunctions.py +309 -0
- quivers-0.1.0/src/quivers/categorical/base_change.py +150 -0
- quivers-0.1.0/src/quivers/categorical/functors.py +268 -0
- quivers-0.1.0/src/quivers/categorical/monoidal.py +344 -0
- quivers-0.1.0/src/quivers/categorical/natural_transformations.py +139 -0
- quivers-0.1.0/src/quivers/categorical/traced.py +456 -0
- quivers-0.1.0/src/quivers/continuous/__init__.py +182 -0
- quivers-0.1.0/src/quivers/continuous/boundaries.py +270 -0
- quivers-0.1.0/src/quivers/continuous/families.py +1352 -0
- quivers-0.1.0/src/quivers/continuous/flows.py +389 -0
- quivers-0.1.0/src/quivers/continuous/inline.py +1147 -0
- quivers-0.1.0/src/quivers/continuous/morphisms.py +845 -0
- quivers-0.1.0/src/quivers/continuous/programs.py +667 -0
- quivers-0.1.0/src/quivers/continuous/scan.py +338 -0
- quivers-0.1.0/src/quivers/continuous/spaces.py +329 -0
- quivers-0.1.0/src/quivers/core/__init__.py +97 -0
- quivers-0.1.0/src/quivers/core/_util.py +45 -0
- quivers-0.1.0/src/quivers/core/extra_quantales.py +269 -0
- quivers-0.1.0/src/quivers/core/morphisms.py +743 -0
- quivers-0.1.0/src/quivers/core/objects.py +374 -0
- quivers-0.1.0/src/quivers/core/quantales.py +393 -0
- quivers-0.1.0/src/quivers/core/tensor_ops.py +238 -0
- quivers-0.1.0/src/quivers/dsl/__init__.py +199 -0
- quivers-0.1.0/src/quivers/dsl/ast_nodes.py +1060 -0
- quivers-0.1.0/src/quivers/dsl/compiler.py +1829 -0
- quivers-0.1.0/src/quivers/dsl/examples/bayesian_regression.qvr +41 -0
- quivers-0.1.0/src/quivers/dsl/examples/bidirectional_rnn.qvr +65 -0
- quivers-0.1.0/src/quivers/dsl/examples/ccg.qvr +50 -0
- quivers-0.1.0/src/quivers/dsl/examples/continuous_hmm.qvr +84 -0
- quivers-0.1.0/src/quivers/dsl/examples/custom_rules.qvr +51 -0
- quivers-0.1.0/src/quivers/dsl/examples/elman_rnn.qvr +58 -0
- quivers-0.1.0/src/quivers/dsl/examples/gru.qvr +84 -0
- quivers-0.1.0/src/quivers/dsl/examples/hmm.qvr +74 -0
- quivers-0.1.0/src/quivers/dsl/examples/lstm.qvr +100 -0
- quivers-0.1.0/src/quivers/dsl/examples/mixture_model.qvr +81 -0
- quivers-0.1.0/src/quivers/dsl/examples/multimodal_tlg.qvr +46 -0
- quivers-0.1.0/src/quivers/dsl/examples/pcfg.qvr +53 -0
- quivers-0.1.0/src/quivers/dsl/examples/transformer.qvr +57 -0
- quivers-0.1.0/src/quivers/dsl/examples/type_logical.qvr +52 -0
- quivers-0.1.0/src/quivers/dsl/examples/vae.qvr +70 -0
- quivers-0.1.0/src/quivers/dsl/examples/vanilla_rnn.qvr +60 -0
- quivers-0.1.0/src/quivers/dsl/lexer.py +314 -0
- quivers-0.1.0/src/quivers/dsl/parser.py +1704 -0
- quivers-0.1.0/src/quivers/dsl/pygments_lexer.py +206 -0
- quivers-0.1.0/src/quivers/dsl/tokens.py +138 -0
- quivers-0.1.0/src/quivers/enriched/__init__.py +112 -0
- quivers-0.1.0/src/quivers/enriched/day_convolution.py +237 -0
- quivers-0.1.0/src/quivers/enriched/ends_coends.py +167 -0
- quivers-0.1.0/src/quivers/enriched/kan_extensions.py +313 -0
- quivers-0.1.0/src/quivers/enriched/optics.py +573 -0
- quivers-0.1.0/src/quivers/enriched/profunctors.py +159 -0
- quivers-0.1.0/src/quivers/enriched/weighted_limits.py +469 -0
- quivers-0.1.0/src/quivers/enriched/yoneda.py +319 -0
- quivers-0.1.0/src/quivers/giry.py +7 -0
- quivers-0.1.0/src/quivers/inference/__init__.py +40 -0
- quivers-0.1.0/src/quivers/inference/conditioning.py +80 -0
- quivers-0.1.0/src/quivers/inference/elbo.py +77 -0
- quivers-0.1.0/src/quivers/inference/guide.py +337 -0
- quivers-0.1.0/src/quivers/inference/predictive.py +91 -0
- quivers-0.1.0/src/quivers/inference/svi.py +67 -0
- quivers-0.1.0/src/quivers/inference/trace.py +263 -0
- quivers-0.1.0/src/quivers/monadic/__init__.py +51 -0
- quivers-0.1.0/src/quivers/monadic/algebras.py +420 -0
- quivers-0.1.0/src/quivers/monadic/comonads.py +504 -0
- quivers-0.1.0/src/quivers/monadic/distributive_laws.py +146 -0
- quivers-0.1.0/src/quivers/monadic/monads.py +355 -0
- quivers-0.1.0/src/quivers/program.py +264 -0
- quivers-0.1.0/src/quivers/stochastic/__init__.py +258 -0
- quivers-0.1.0/src/quivers/stochastic/_rule_system.py +258 -0
- quivers-0.1.0/src/quivers/stochastic/categories.py +561 -0
- quivers-0.1.0/src/quivers/stochastic/ccg.py +119 -0
- quivers-0.1.0/src/quivers/stochastic/deduction.py +223 -0
- quivers-0.1.0/src/quivers/stochastic/families.py +314 -0
- quivers-0.1.0/src/quivers/stochastic/giry.py +151 -0
- quivers-0.1.0/src/quivers/stochastic/inside.py +282 -0
- quivers-0.1.0/src/quivers/stochastic/lambek.py +155 -0
- quivers-0.1.0/src/quivers/stochastic/morphisms.py +116 -0
- quivers-0.1.0/src/quivers/stochastic/parsers.py +319 -0
- quivers-0.1.0/src/quivers/stochastic/quantale.py +109 -0
- quivers-0.1.0/src/quivers/stochastic/queries.py +115 -0
- quivers-0.1.0/src/quivers/stochastic/rules.py +195 -0
- quivers-0.1.0/src/quivers/stochastic/schema.py +975 -0
- quivers-0.1.0/src/quivers/stochastic/semiring.py +237 -0
- quivers-0.1.0/src/quivers/stochastic/span.py +449 -0
- quivers-0.1.0/src/quivers/stochastic/transforms.py +350 -0
- quivers-0.1.0/tests/test_adjunctions.py +82 -0
- quivers-0.1.0/tests/test_algebras.py +110 -0
- quivers-0.1.0/tests/test_base_change.py +85 -0
- quivers-0.1.0/tests/test_comonads.py +119 -0
- quivers-0.1.0/tests/test_componentwise_lift.py +164 -0
- quivers-0.1.0/tests/test_continuous.py +1300 -0
- quivers-0.1.0/tests/test_day_convolution.py +72 -0
- quivers-0.1.0/tests/test_distributive_laws.py +55 -0
- quivers-0.1.0/tests/test_dsl.py +5057 -0
- quivers-0.1.0/tests/test_ends_coends.py +101 -0
- quivers-0.1.0/tests/test_extra_quantales.py +216 -0
- quivers-0.1.0/tests/test_functors.py +178 -0
- quivers-0.1.0/tests/test_identity.py +108 -0
- quivers-0.1.0/tests/test_inference.py +849 -0
- quivers-0.1.0/tests/test_kan_extensions.py +154 -0
- quivers-0.1.0/tests/test_monads.py +150 -0
- quivers-0.1.0/tests/test_monoidal.py +121 -0
- quivers-0.1.0/tests/test_morphisms.py +380 -0
- quivers-0.1.0/tests/test_natural_transformations.py +88 -0
- quivers-0.1.0/tests/test_objects.py +156 -0
- quivers-0.1.0/tests/test_optics.py +183 -0
- quivers-0.1.0/tests/test_profunctors.py +69 -0
- quivers-0.1.0/tests/test_program.py +188 -0
- quivers-0.1.0/tests/test_quantales.py +205 -0
- quivers-0.1.0/tests/test_stochastic.py +765 -0
- quivers-0.1.0/tests/test_tensor_ops.py +259 -0
- quivers-0.1.0/tests/test_traced.py +135 -0
- quivers-0.1.0/tests/test_weighted_limits.py +103 -0
- quivers-0.1.0/tests/test_yoneda.py +71 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"permissions": {
|
|
3
|
+
"allow": [
|
|
4
|
+
"Bash(git add:*)",
|
|
5
|
+
"Bash(source /Users/awhite48/Projects/quivers/.venv/bin/activate)",
|
|
6
|
+
"Bash(ruff check:*)",
|
|
7
|
+
"Bash(python -m pytest tests/ -x -q)",
|
|
8
|
+
"Bash(source .venv/bin/activate)",
|
|
9
|
+
"Bash(for f:*)",
|
|
10
|
+
"Bash(do echo:*)",
|
|
11
|
+
"Bash(pyright /Users/awhite48/Projects/quivers/src/quivers/stochastic/$f)",
|
|
12
|
+
"Bash(done)",
|
|
13
|
+
"Bash(python3 -c \":*)",
|
|
14
|
+
"Bash(ruff format:*)"
|
|
15
|
+
]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [main]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
lint:
|
|
11
|
+
runs-on: ubuntu-latest
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v4
|
|
14
|
+
- uses: actions/setup-python@v5
|
|
15
|
+
with:
|
|
16
|
+
python-version: "3.13"
|
|
17
|
+
- run: pip install ruff
|
|
18
|
+
- run: ruff check src/ tests/
|
|
19
|
+
- run: ruff format --check src/ tests/
|
|
20
|
+
|
|
21
|
+
typecheck:
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
25
|
+
- uses: actions/setup-python@v5
|
|
26
|
+
with:
|
|
27
|
+
python-version: "3.13"
|
|
28
|
+
- run: pip install -e ".[dev]"
|
|
29
|
+
- run: pyright src/quivers
|
|
30
|
+
|
|
31
|
+
test:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
strategy:
|
|
34
|
+
matrix:
|
|
35
|
+
python-version: ["3.13"]
|
|
36
|
+
steps:
|
|
37
|
+
- uses: actions/checkout@v4
|
|
38
|
+
- uses: actions/setup-python@v5
|
|
39
|
+
with:
|
|
40
|
+
python-version: ${{ matrix.python-version }}
|
|
41
|
+
- run: pip install -e ".[dev]"
|
|
42
|
+
- run: python -m pytest tests/ -x -q
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
name: Deploy Docs
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
permissions:
|
|
8
|
+
contents: read
|
|
9
|
+
pages: write
|
|
10
|
+
id-token: write
|
|
11
|
+
|
|
12
|
+
concurrency:
|
|
13
|
+
group: pages
|
|
14
|
+
cancel-in-progress: true
|
|
15
|
+
|
|
16
|
+
jobs:
|
|
17
|
+
build:
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- uses: actions/setup-python@v5
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.12"
|
|
24
|
+
- run: pip install -e ".[docs]"
|
|
25
|
+
- run: mkdocs build --strict
|
|
26
|
+
- uses: actions/upload-pages-artifact@v3
|
|
27
|
+
with:
|
|
28
|
+
path: site/
|
|
29
|
+
|
|
30
|
+
deploy:
|
|
31
|
+
needs: build
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
environment:
|
|
34
|
+
name: github-pages
|
|
35
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
36
|
+
steps:
|
|
37
|
+
- id: deployment
|
|
38
|
+
uses: actions/deploy-pages@v4
|
quivers-0.1.0/.gitignore
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
dist/
|
|
8
|
+
build/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
*.egg
|
|
11
|
+
|
|
12
|
+
# Virtual environments
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
|
|
17
|
+
# Testing
|
|
18
|
+
.pytest_cache/
|
|
19
|
+
pytest-cache-files-*/
|
|
20
|
+
.coverage
|
|
21
|
+
htmlcov/
|
|
22
|
+
|
|
23
|
+
# Type checking / linting
|
|
24
|
+
.mypy_cache/
|
|
25
|
+
.ruff_cache/
|
|
26
|
+
|
|
27
|
+
# Documentation build
|
|
28
|
+
site/
|
|
29
|
+
|
|
30
|
+
# IDE
|
|
31
|
+
.idea/
|
|
32
|
+
.vscode/
|
|
33
|
+
*.swp
|
|
34
|
+
*.swo
|
|
35
|
+
*~
|
|
36
|
+
|
|
37
|
+
# OS
|
|
38
|
+
.DS_Store
|
|
39
|
+
Thumbs.db
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the quivers library are documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/), and this project adheres to [Semantic Versioning](https://semver.org/).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-03-26
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
|
|
13
|
+
#### Core Categorical Algebra
|
|
14
|
+
|
|
15
|
+
- Fundamental category types and morphisms
|
|
16
|
+
- Object declarations and morphism composition
|
|
17
|
+
- Support for latent and observed morphisms
|
|
18
|
+
- Basic categorical operations and abstractions
|
|
19
|
+
|
|
20
|
+
#### Stochastic Morphisms
|
|
21
|
+
|
|
22
|
+
- Stochastic morphism declarations and semantics
|
|
23
|
+
- Integration with probability theory
|
|
24
|
+
- Support for morphism composition in stochastic settings
|
|
25
|
+
|
|
26
|
+
#### Continuous Distributions (30+ Families)
|
|
27
|
+
|
|
28
|
+
- Normal distribution and variants (LogitNormal, TruncatedNormal)
|
|
29
|
+
- Beta, Dirichlet for probability simplices
|
|
30
|
+
- Exponential family: Exponential, Gamma, Chi2
|
|
31
|
+
- Heavy-tailed: Cauchy, StudentT, Pareto
|
|
32
|
+
- Bounded: Uniform, Kumaraswamy
|
|
33
|
+
- Half-variants: HalfCauchy, HalfNormal
|
|
34
|
+
- Transformed: LogNormal, Gumbel, Laplace, Weibull
|
|
35
|
+
- Multivariate: MultivariateNormal, LowRankMVN, Wishart
|
|
36
|
+
- Bernoulli variants: Bernoulli, ContinuousBernoulli, RelaxedBernoulli
|
|
37
|
+
- Advanced: RelaxedOneHotCategorical, FisherSnedecor
|
|
38
|
+
- Normalized flows: Flow
|
|
39
|
+
- Categorical and discrete approximations
|
|
40
|
+
|
|
41
|
+
#### Monadic Programs
|
|
42
|
+
|
|
43
|
+
- Draw statements for sampling from morphisms
|
|
44
|
+
- Observe statements for conditioning and likelihood
|
|
45
|
+
- Return statements with optional labeled outputs
|
|
46
|
+
- Variable binding and destructuring in patterns
|
|
47
|
+
- Program parameters and composition
|
|
48
|
+
|
|
49
|
+
#### QVR DSL
|
|
50
|
+
|
|
51
|
+
- Complete lexer with token recognition for all language constructs
|
|
52
|
+
- Recursive descent parser with full grammar support
|
|
53
|
+
- Abstract syntax tree (AST) node definitions
|
|
54
|
+
- Program block execution with proper scoping
|
|
55
|
+
- Let bindings for expression computation
|
|
56
|
+
- Built-in let functions: sigmoid, exp, log, abs, softplus
|
|
57
|
+
- Comment support (#)
|
|
58
|
+
- Type expressions: products (*), coproducts (+)
|
|
59
|
+
- Expression operators: composition (>>), tensor product (@), marginalization
|
|
60
|
+
- Indentation-aware program body parsing
|
|
61
|
+
- Specialized handling for draw/observe arguments
|
|
62
|
+
|
|
63
|
+
#### Variational Inference Layer
|
|
64
|
+
|
|
65
|
+
- Inference interface for probabilistic programs
|
|
66
|
+
- Support for approximate posterior computation
|
|
67
|
+
- Integration with continuous distribution families
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
# Contributing to Quivers
|
|
2
|
+
|
|
3
|
+
This guide covers setting up a development environment, understanding the project structure, and contributing code to the quivers library.
|
|
4
|
+
|
|
5
|
+
## Development Environment Setup
|
|
6
|
+
|
|
7
|
+
### Prerequisites
|
|
8
|
+
|
|
9
|
+
- Python 3.12 or later
|
|
10
|
+
- pip or conda
|
|
11
|
+
- git
|
|
12
|
+
|
|
13
|
+
### Installation
|
|
14
|
+
|
|
15
|
+
Clone the repository and install in development mode:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
git clone https://github.com/FACTSlab/quivers
|
|
19
|
+
cd quivers
|
|
20
|
+
pip install -e ".[dev]"
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
This installs the package in editable mode along with development dependencies.
|
|
24
|
+
|
|
25
|
+
### Running Tests
|
|
26
|
+
|
|
27
|
+
Run the full test suite:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
python -m pytest tests/ -x
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The `-x` flag stops at the first failure, which is useful for iterative development. For more options:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
python -m pytest tests/ -v # verbose
|
|
37
|
+
python -m pytest tests/ -k test_name # run specific tests
|
|
38
|
+
python -m pytest tests/path/to/test_file.py # run specific file
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Project Structure
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
quivers/
|
|
45
|
+
├── docs/ # Documentation
|
|
46
|
+
│ ├── api/ # API reference
|
|
47
|
+
│ ├── developer/ # Developer documentation
|
|
48
|
+
│ ├── getting-started/ # User guides
|
|
49
|
+
│ ├── guides/ # Long-form guides
|
|
50
|
+
│ └── tutorials/ # Tutorials
|
|
51
|
+
├── src/quivers/ # Main package
|
|
52
|
+
│ ├── __init__.py
|
|
53
|
+
│ ├── categorical/ # Categorical algebra
|
|
54
|
+
│ ├── continuous/ # Continuous distributions (30+ families)
|
|
55
|
+
│ ├── core/ # Core types and utilities
|
|
56
|
+
│ ├── dsl/ # QVR DSL (lexer, parser, compiler)
|
|
57
|
+
│ ├── enriched/ # Enriched categories
|
|
58
|
+
│ ├── inference/ # Variational inference
|
|
59
|
+
│ ├── monadic/ # Monadic programs (draw, observe, return)
|
|
60
|
+
│ └── stochastic/ # Stochastic morphisms
|
|
61
|
+
├── tests/ # Test suite (mirrors src structure)
|
|
62
|
+
├── pyproject.toml # Package metadata
|
|
63
|
+
└── mkdocs.yml # Documentation config
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Code Style Conventions
|
|
67
|
+
|
|
68
|
+
### Type Hints
|
|
69
|
+
|
|
70
|
+
Include type hints in all function signatures. Use modern Python 3.12+ syntax:
|
|
71
|
+
|
|
72
|
+
- Use `dict[K, V]` not `Dict[K, V]`
|
|
73
|
+
- Use `list[T]` not `List[T]`
|
|
74
|
+
- Use `X | None` not `Optional[X]`
|
|
75
|
+
- Use `tuple[T, ...]` for variable-length tuples
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
def process_data(values: list[float], multiplier: float = 1.0) -> dict[str, float]:
|
|
79
|
+
"""Process numeric data."""
|
|
80
|
+
return {str(i): v * multiplier for i, v in enumerate(values)}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Do not use type hints in function bodies or variable assignments unless necessary for clarity in complex code sections.
|
|
84
|
+
|
|
85
|
+
### Docstrings
|
|
86
|
+
|
|
87
|
+
Use numpy-style docstrings for all public modules, classes, and functions:
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
def calculate_entropy(probabilities: list[float]) -> float:
|
|
91
|
+
"""Calculate Shannon entropy of a probability distribution.
|
|
92
|
+
|
|
93
|
+
Parameters
|
|
94
|
+
----------
|
|
95
|
+
probabilities : list[float]
|
|
96
|
+
Probabilities that sum to 1.0.
|
|
97
|
+
|
|
98
|
+
Returns
|
|
99
|
+
-------
|
|
100
|
+
float
|
|
101
|
+
Shannon entropy in nats.
|
|
102
|
+
|
|
103
|
+
Raises
|
|
104
|
+
------
|
|
105
|
+
ValueError
|
|
106
|
+
If probabilities do not sum to approximately 1.0.
|
|
107
|
+
|
|
108
|
+
Examples
|
|
109
|
+
--------
|
|
110
|
+
>>> entropy([0.5, 0.5])
|
|
111
|
+
0.6931471805599453
|
|
112
|
+
"""
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
### Comments
|
|
116
|
+
|
|
117
|
+
Use lowercase inline comments to clarify non-obvious logic:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
# compute sufficient statistics for exponential family
|
|
121
|
+
sufficient_stats = compute_stats(data)
|
|
122
|
+
|
|
123
|
+
# handle edge case where prior is uniform
|
|
124
|
+
if prior_strength == 0:
|
|
125
|
+
posterior = likelihood
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Avoid stating the obvious. Comments should explain "why," not "what."
|
|
129
|
+
|
|
130
|
+
### Python Version and Modern Features
|
|
131
|
+
|
|
132
|
+
Maintain compatibility with Python 3.12 and later. Use modern features:
|
|
133
|
+
|
|
134
|
+
- Type union syntax: `X | None` instead of `Union[X, None]`
|
|
135
|
+
- Positional-only parameters: `def func(a, /, b)`
|
|
136
|
+
|
|
137
|
+
## The DSL Pipeline
|
|
138
|
+
|
|
139
|
+
The QVR DSL processes `.qvr` files through these stages:
|
|
140
|
+
|
|
141
|
+
### 1. Tokenization (tokens.py)
|
|
142
|
+
|
|
143
|
+
The lexer breaks source text into tokens. Each token carries type, value, line, and column:
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
class TokenType(Enum):
|
|
147
|
+
QUANTALE = auto()
|
|
148
|
+
OBJECT = auto()
|
|
149
|
+
PROGRAM = auto()
|
|
150
|
+
DRAW = auto()
|
|
151
|
+
OBSERVE = auto()
|
|
152
|
+
...
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Keywords like `program`, `draw`, `observe`, `return` map to specific token types. Operators (`->`, `>>`, `@`, `~`) and punctuation are also tokenized.
|
|
156
|
+
|
|
157
|
+
### 2. Parsing (parser.py)
|
|
158
|
+
|
|
159
|
+
The recursive descent parser transforms the token stream into an Abstract Syntax Tree (AST). The grammar is documented in the module docstring:
|
|
160
|
+
|
|
161
|
+
- **Statements**: quantale, object, morphism, space, continuous, stochastic, discretize, embed, program, let, output declarations
|
|
162
|
+
- **Programs**: blocks with draw/observe steps and return statements
|
|
163
|
+
- **Expressions**: identity, composition (>>), tensor product (@), marginalization
|
|
164
|
+
- **Types**: products (*), coproducts (+)
|
|
165
|
+
|
|
166
|
+
### 3. AST Nodes (ast_nodes.py)
|
|
167
|
+
|
|
168
|
+
Each syntax construct maps to a dataclass:
|
|
169
|
+
|
|
170
|
+
```python
|
|
171
|
+
@dataclass
|
|
172
|
+
class ProgramDecl(Statement):
|
|
173
|
+
name: str
|
|
174
|
+
params: tuple[str, ...] | None
|
|
175
|
+
domain: TypeExpr
|
|
176
|
+
codomain: TypeExpr
|
|
177
|
+
draws: tuple[DrawStep | LetStep, ...]
|
|
178
|
+
return_vars: tuple[str, ...]
|
|
179
|
+
return_labels: tuple[str, ...] | None
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### 4. Compilation (compiler.py)
|
|
183
|
+
|
|
184
|
+
The compiler walks the AST and builds executable programs:
|
|
185
|
+
|
|
186
|
+
- Builds up a scope mapping variable names to values
|
|
187
|
+
- Executes draw steps by sampling from morphism distributions
|
|
188
|
+
- Executes observe steps by conditioning
|
|
189
|
+
- Processes let steps to bind computed expressions
|
|
190
|
+
- Returns final values according to the return statement
|
|
191
|
+
|
|
192
|
+
## Adding a New Distribution Family
|
|
193
|
+
|
|
194
|
+
To add a new continuous distribution family:
|
|
195
|
+
|
|
196
|
+
### 1. Define the Distribution Class
|
|
197
|
+
|
|
198
|
+
Create a new class in `src/quivers/continuous/families.py` or a new module:
|
|
199
|
+
|
|
200
|
+
```python
|
|
201
|
+
from dataclasses import dataclass
|
|
202
|
+
import torch
|
|
203
|
+
|
|
204
|
+
@dataclass(frozen=True)
|
|
205
|
+
class MyDistribution:
|
|
206
|
+
"""My custom probability distribution.
|
|
207
|
+
|
|
208
|
+
Parameters
|
|
209
|
+
----------
|
|
210
|
+
param1 : float
|
|
211
|
+
First parameter.
|
|
212
|
+
param2 : float
|
|
213
|
+
Second parameter.
|
|
214
|
+
"""
|
|
215
|
+
param1: float
|
|
216
|
+
param2: float
|
|
217
|
+
|
|
218
|
+
def sample(self, size: int) -> torch.Tensor:
|
|
219
|
+
"""Draw samples from this distribution."""
|
|
220
|
+
pass
|
|
221
|
+
|
|
222
|
+
def log_prob(self, value: torch.Tensor) -> torch.Tensor:
|
|
223
|
+
"""Compute log probability density."""
|
|
224
|
+
pass
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
### 2. Register in the DSL
|
|
228
|
+
|
|
229
|
+
Add the distribution to the DSL's family registry so it can be used in `.qvr` files.
|
|
230
|
+
|
|
231
|
+
### 3. Add Tests
|
|
232
|
+
|
|
233
|
+
Create test cases in `tests/continuous/`:
|
|
234
|
+
|
|
235
|
+
```python
|
|
236
|
+
def test_mydistribution_sample_shape():
|
|
237
|
+
dist = MyDistribution(param1=1.0, param2=2.0)
|
|
238
|
+
samples = dist.sample(1000)
|
|
239
|
+
assert samples.shape == (1000,)
|
|
240
|
+
|
|
241
|
+
def test_mydistribution_log_prob():
|
|
242
|
+
dist = MyDistribution(param1=1.0, param2=2.0)
|
|
243
|
+
value = torch.tensor([0.5])
|
|
244
|
+
log_prob = dist.log_prob(value)
|
|
245
|
+
assert log_prob.shape == ()
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 4. Update Documentation
|
|
249
|
+
|
|
250
|
+
Add the distribution to the API reference with usage examples and parameter descriptions.
|
|
251
|
+
|
|
252
|
+
## Testing Philosophy
|
|
253
|
+
|
|
254
|
+
- Write tests for all public APIs
|
|
255
|
+
- Test both happy paths and edge cases
|
|
256
|
+
- Use pytest fixtures for common setup
|
|
257
|
+
- Organize tests to mirror the source tree structure
|
|
258
|
+
- Aim for clear, descriptive test names: `test_<function>_<condition>_<expected>`
|
|
259
|
+
|
|
260
|
+
## Git Workflow
|
|
261
|
+
|
|
262
|
+
1. Create a feature branch: `git checkout -b feature/description`
|
|
263
|
+
2. Make focused commits with clear messages
|
|
264
|
+
3. Push to your fork and open a pull request
|
|
265
|
+
4. Ensure all tests pass before requesting review
|
|
266
|
+
5. Respond to feedback and update as needed
|
|
267
|
+
|
|
268
|
+
## Questions and Issues
|
|
269
|
+
|
|
270
|
+
Open an issue on the [GitHub repository](https://github.com/FACTSlab/quivers) for bugs, feature requests, or questions.
|
quivers-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aaron Steven White
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
quivers-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: quivers
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Computational category theory as differentiable tensor programs
|
|
5
|
+
Project-URL: Homepage, https://github.com/FACTSlab/quivers
|
|
6
|
+
Project-URL: Repository, https://github.com/FACTSlab/quivers
|
|
7
|
+
Project-URL: Documentation, https://FACTSlab.github.io/quivers
|
|
8
|
+
Project-URL: Changelog, https://github.com/FACTSlab/quivers/blob/main/CHANGELOG.md
|
|
9
|
+
Author: Aaron Steven White
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: category-theory,enriched-categories,probabilistic-programming,pytorch,quantale,tensor
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Scientific/Engineering :: Mathematics
|
|
21
|
+
Requires-Python: >=3.13
|
|
22
|
+
Requires-Dist: torch>=2.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pyright; extra == 'dev'
|
|
25
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest>=7.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
28
|
+
Provides-Extra: docs
|
|
29
|
+
Requires-Dist: mkdocs; extra == 'docs'
|
|
30
|
+
Requires-Dist: mkdocs-cinder; extra == 'docs'
|
|
31
|
+
Requires-Dist: mkdocstrings[python]; extra == 'docs'
|
|
32
|
+
Requires-Dist: pymdown-extensions; extra == 'docs'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# Quivers
|
|
36
|
+
|
|
37
|
+
[](https://github.com/FACTSlab/quivers/actions/workflows/ci.yml)
|
|
38
|
+
[](https://FACTSlab.github.io/quivers)
|
|
39
|
+
[](https://pypi.org/project/quivers/)
|
|
40
|
+
[](https://www.python.org/downloads/)
|
|
41
|
+
[](LICENSE)
|
|
42
|
+
|
|
43
|
+
Computational category theory as differentiable tensor programs.
|
|
44
|
+
|
|
45
|
+
**Quivers** is a Python library for building categorical and probabilistic models as differentiable PyTorch programs. It represents morphisms between finite sets as tensors valued in a quantale (a lattice with a monoidal product), then extends this to stochastic morphisms (Markov kernels), continuous distribution families, monadic probabilistic programs, and variational inference. A built-in functional DSL compiles `.qvr` specifications into trainable `nn.Module` instances.
|
|
46
|
+
|
|
47
|
+
## Features
|
|
48
|
+
|
|
49
|
+
- **Core categorical algebra**: finite sets, product/coproduct constructions, and free monoids as objects; quantales (Boolean, product fuzzy, Łukasiewicz, Gödel, tropical) as enrichment algebras; $\mathcal{V}$-enriched relations as parametrized tensors with composition via quantale operations.
|
|
50
|
+
- **Categorical structures**: functors, natural transformations, adjunctions, monoidal categories, traced monoidal categories, base change between quantales.
|
|
51
|
+
- **Enriched category theory**: ends, coends, Kan extensions, weighted limits/colimits, profunctors, Yoneda embedding, Day convolution, optics (lenses, prisms, adapters, grates).
|
|
52
|
+
- **Monadic constructs**: monads, comonads, Kleisli/coKleisli categories, algebras, coalgebras, Eilenberg-Moore categories, distributive laws.
|
|
53
|
+
- **Stochastic morphisms**: the FinStoch category of Markov kernels; discretized distribution families (normal, logit-normal, beta, truncated normal); conditioning, mixing, and normalization transforms; the Giry monad; query functions (prob, marginal_prob, expectation).
|
|
54
|
+
- **Continuous morphisms**: 30+ parameterized conditional distribution families; continuous spaces (Euclidean, simplex, unit interval, positive reals); sampled composition; normalizing flows; discrete-continuous boundaries (discretize/embed).
|
|
55
|
+
- **Monadic programs**: probabilistic programs with draw, observe, and return statements; ancestral sampling; log-joint computation; hybrid discrete-continuous random variables.
|
|
56
|
+
- **QVR DSL**: a `.qvr` file format with lexer, recursive descent parser, AST, and compiler; supports object/morphism declarations, program blocks, let bindings, type expressions, and grammar-based parsers (PCFG, CCG, Lambek, multimodal type-logical).
|
|
57
|
+
- **Variational inference**: execution traces, conditioning, automatic variational guides (normal, delta), ELBO computation, stochastic variational inference (SVI), posterior predictive sampling.
|
|
58
|
+
|
|
59
|
+
## Installation
|
|
60
|
+
|
|
61
|
+
```bash
|
|
62
|
+
pip install quivers
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Or install from source:
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
git clone https://github.com/FACTSlab/quivers
|
|
69
|
+
cd quivers
|
|
70
|
+
pip install -e .
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
For development (includes pytest, ruff, pyright):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install -e ".[dev]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
### Discrete morphisms and composition
|
|
82
|
+
|
|
83
|
+
Define finite sets, create learnable and observed morphisms, and compose them:
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
from quivers import FinSet, morphism, observed, Program
|
|
87
|
+
import torch
|
|
88
|
+
|
|
89
|
+
X = FinSet("X", 3)
|
|
90
|
+
Y = FinSet("Y", 4)
|
|
91
|
+
Z = FinSet("Z", 2)
|
|
92
|
+
|
|
93
|
+
f = morphism(X, Y) # learnable (sigmoid over raw params)
|
|
94
|
+
g = observed(Y, Z, torch.rand(4, 2)) # fixed tensor
|
|
95
|
+
|
|
96
|
+
h = f >> g # V-enriched composition: X -> Z
|
|
97
|
+
program = Program(h)
|
|
98
|
+
output = program() # shape (3, 2), values in [0, 1]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Composition uses the product fuzzy quantale by default: AND is multiplication, OR is noisy-OR ($1 - \prod(1 - x_i)$). The result is a differentiable tensor, trainable via `program.parameters()`.
|
|
102
|
+
|
|
103
|
+
### Stochastic morphisms
|
|
104
|
+
|
|
105
|
+
Work with Markov kernels in the FinStoch category:
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from quivers import FinSet, stochastic, condition, prob
|
|
109
|
+
|
|
110
|
+
S = FinSet("S", 3)
|
|
111
|
+
O = FinSet("O", 5)
|
|
112
|
+
|
|
113
|
+
transition = stochastic(S, S) # learnable row-stochastic matrix
|
|
114
|
+
emission = stochastic(S, O) # learnable row-stochastic matrix
|
|
115
|
+
|
|
116
|
+
# condition on an observation
|
|
117
|
+
conditioned = condition(emission, obs_index=2)
|
|
118
|
+
|
|
119
|
+
# query probabilities
|
|
120
|
+
p = prob(transition, domain_idx=0, codomain_idx=1)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### The QVR DSL
|
|
124
|
+
|
|
125
|
+
Write probabilistic programs in `.qvr` syntax and compile to `nn.Module`:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from quivers.dsl import loads
|
|
129
|
+
|
|
130
|
+
source = """
|
|
131
|
+
object Predictor : 1
|
|
132
|
+
object Response : 1
|
|
133
|
+
|
|
134
|
+
program regression : Predictor -> Response
|
|
135
|
+
sigma <- HalfCauchy(2.0)
|
|
136
|
+
beta_0 <- Normal(0.0, 5.0)
|
|
137
|
+
beta_1 <- Normal(0.0, 2.0)
|
|
138
|
+
x <- Normal(0.0, 1.0)
|
|
139
|
+
let mu = beta_0 + beta_1 * x
|
|
140
|
+
observe y ~ Normal(mu, sigma)
|
|
141
|
+
return y
|
|
142
|
+
|
|
143
|
+
output regression
|
|
144
|
+
"""
|
|
145
|
+
|
|
146
|
+
model = loads(source)
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Project Structure
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
src/quivers/
|
|
153
|
+
├── core/ # objects, quantales, morphisms, tensor ops
|
|
154
|
+
├── categorical/ # functors, natural transformations, adjunctions, monoidal, traced
|
|
155
|
+
├── monadic/ # monads, comonads, algebras, distributive laws
|
|
156
|
+
├── enriched/ # ends/coends, Kan extensions, profunctors, Yoneda, Day, optics
|
|
157
|
+
├── stochastic/ # Markov kernels, Giry monad, grammar parsers, chart algorithms
|
|
158
|
+
├── continuous/ # distribution families, spaces, flows, monadic programs
|
|
159
|
+
├── dsl/ # lexer, parser, AST, compiler for .qvr files
|
|
160
|
+
├── inference/ # traces, conditioning, guides, ELBO, SVI, predictive
|
|
161
|
+
├── program.py # Program: wraps morphisms as nn.Module
|
|
162
|
+
└── giry.py # GiryMonad, FinStoch
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Documentation
|
|
166
|
+
|
|
167
|
+
Full documentation: [https://FACTSlab.github.io/quivers](https://FACTSlab.github.io/quivers)
|
|
168
|
+
|
|
169
|
+
- [Installation](https://FACTSlab.github.io/quivers/getting-started/installation/)
|
|
170
|
+
- [Quickstart](https://FACTSlab.github.io/quivers/getting-started/quickstart/)
|
|
171
|
+
- [Conceptual Guides](https://FACTSlab.github.io/quivers/guides/)
|
|
172
|
+
- [Tutorials](https://FACTSlab.github.io/quivers/tutorials/)
|
|
173
|
+
- [Examples Gallery](https://FACTSlab.github.io/quivers/examples/)
|
|
174
|
+
- [API Reference](https://FACTSlab.github.io/quivers/api/)
|
|
175
|
+
|
|
176
|
+
## Requirements
|
|
177
|
+
|
|
178
|
+
- Python 3.13+
|
|
179
|
+
- PyTorch 2.0+
|
|
180
|
+
|
|
181
|
+
## Contributing
|
|
182
|
+
|
|
183
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, code style conventions, and the git workflow.
|
|
184
|
+
|
|
185
|
+
## License
|
|
186
|
+
|
|
187
|
+
MIT. See [LICENSE](LICENSE) for details.
|