causasv
Fast causal Asymmetric Shapley Values for Rust and Python.
causasv computes Asymmetric Shapley Values (ASV) over a causal DAG and value
function supplied by the caller. ASV averages marginal contributions over
topological orderings, so a cause is never introduced after its descendants.
causasv does not learn causal graphs, train models, or infer causality from
data. Use it when the graph is already available and its assumptions can be
defended outside this library.
Install
Python wheels are published for Linux x86_64, macOS universal2, and Windows x86_64:
pip install causasv
Rust:
[dependencies]
causasv = "0.8"
The Rust crate requires Rust 1.85 or newer. Python requires 3.9 or newer.
ASV in one formula
For a DAG G, let Π(G) be its topological orderings and pre(i, π) the
features before i in ordering π:
φᵢ = 1 / |Π(G)| · Σπ∈Π(G) [v(pre(i,π) ∪ {i}) - v(pre(i,π))]
Standard Shapley values average over every permutation. ASV uses only permutations allowed by the supplied DAG. They agree for additive value functions and can differ when feature interactions depend on order. See the SHAP comparison for a worked example.
Rust quick start
use causasv::{AsvExplainer, Dag, SamplingConfig};
fn main() -> Result<(), causasv::CausasvError> {
let mut dag = Dag::new();
let education = dag.add_node("education");
let income = dag.add_node("income");
let risk = dag.add_node("risk_score");
dag.add_edge(education, income)?;
dag.add_edge(income, risk)?;
let result = AsvExplainer::new(dag).auto(
|coalition| Ok(coalition.len() as f64),
SamplingConfig::new(10_000).with_seed(42),
)?;
println!("{:?}", result.values);
Ok(())
}
auto() uses an exact method when feasible and falls back to seeded
importance sampling. Use auto_quality() when approximate paths also need
standard errors and convergence metadata.
Python quick start
explain_quality() is the recommended Python entry point. It tries exact
methods first and otherwise returns an adaptive estimate with uncertainty
diagnostics.
from causasv import ASVExplainer, CausalDAG, explain_quality
dag = CausalDAG.from_edges([
("education", "income"),
("income", "risk_score"),
])
result = explain_quality(
ASVExplainer(dag),
value_fn=lambda features: my_model_score(features),
seed=42,
ci=0.95,
)
print(result["values"])
print(result["selected_method"])
print(result["stderr"])
print(result["ci_low"], result["ci_high"])
The callback receives a sorted list[str] containing the features in the
coalition. For an expensive model, pass value_fn_batch instead of
value_fn to evaluate many coalitions per Python call.
Choosing a method
Prefer auto() or auto_quality() unless a test or benchmark requires a
specific algorithm.
| Method | Use | Bound |
|---|---|---|
exact |
brute-force reference oracle | practical around n <= 8 |
exact_tree |
exact rooted-tree DP | shape-budgeted; bitmask limit n <= 64 |
exact_dag |
exact dense order-ideal DP | n <= 20 |
exact_dag_sparse |
exact sparse order-ideal DP | default n <= 28; configurable up to 63 |
uniform_sparse |
equal-probability topological sampling | n <= 63 |
approx |
importance-sampling estimate | no node-count limit |
Exact feasibility depends on graph structure, state count, and memory—not only on node count. The canonical limits and dispatch rules are in Correctness.
For approximate results:
- keep a seed when reproducibility matters
- inspect
stderr, confidence intervals, convergence, and fallback metadata - inspect
ess_ratiofor importance-sampling paths - rerun across seeds when feature ranking is consequential
explain_safe() automates the main checks. explain_stability() reports
cross-seed rank stability.
Included capabilities
- DAG validation, topological sorting, and order enumeration
- brute-force, rooted-tree, dense-DAG, and sparse-DAG exact ASV
- fixed-sample, adaptive, uniform sparse, parallel, and batched approximation
- deterministic seeds, ESS, standard errors, confidence intervals, and fallback diagnostics
- Rust and Python APIs
- CPDAG representation and consistent DAG extension
- d-convex and strong d-convex graph reduction
- optional Python helpers for tabular models and DAG sensitivity
Graph reduction operates on a caller-supplied graph. It does not perform causal discovery or effect estimation. Its assumptions and clean-room implementation record are documented in Strong d-convex hulls.
Documentation
- Correctness and method limits
- Criterion benchmark results
- Canonical Python benchmark corpus
- ASV and SHAP comparison
- Strong d-convex hull assumptions
- quietset instability integration
- Rust API
Measurements are evidence for the named version, hardware, graph, and value function only. They are not general performance or attribution-quality claims.
Current limits
- The graph and value function must be supplied by the caller.
exact_treecan reject a modest-sized but highly branching tree when its estimated combinatorial cost exceedsExactTreeConfig.- Dense and sparse exact methods use bitmask representations and therefore have fixed node limits. Importance-sampling methods use a large-coalition backend above 64 nodes.
- CPDAG validation checks structure and consistent extendability; it does not prove that every directed edge is compelled in a genuine equivalence class.
- The graph-reduction guarantee depends on distributional and graph assumptions that the library cannot verify.
Status
Experimental — v0.8.9. Public APIs may change before v1.0.
The brute-force implementation remains the correctness oracle for optimized methods on small graphs. See CHANGELOG.md for released and unreleased changes.
Build the Python extension
python -m venv .venv
source .venv/bin/activate
pip install maturin pytest
cd py
maturin develop --features python
python -m pytest
Citation
Project citation metadata is in CITATION.cff. The ASV design is inspired by Beyond Shapley: Efficient Computation of Asymmetric Shapley Values.
The graph-reduction module independently implements mathematical definitions from Deng, Sun, Li, and Liu, “Estimate Collapsibility of Causal Effects in Completed Partial DAGs via Strong d-Convex Hulls,” arXiv:2606.08941 (2026). See the citation and scope record.
License
Licensed under either Apache-2.0 or MIT, at your option.
Metadata
Release files for causasv 0.8.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| causasv-0.8.9.tar.gz | 236.1 kB | Details |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| causasv-0.8.9-cp314-cp314-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl | CPython 3.14 | CPython 3.14 | macOS 10.12+ x86-64, macOS 11.0+ ARM64, macOS 10.12+ universal2 (ARM64, x86-64) | Details |
| causasv-0.8.9-cp312-cp312-win_amd64.whl | CPython 3.12 | CPython 3.12 | Windows x86-64 | Details |
| causasv-0.8.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl | CPython 3.9 | CPython 3.9 | Linux glibc 2.17+ x86-64 | Details |
Total release size: 2.7 MB
Release files / causasv-0.8.9.tar.gz
| Download URL | causasv-0.8.9.tar.gz |
|---|---|
| Size | 236.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3d11806e7713293376756c225356b16d367d89780bbea94800868d2c2660edf
|
|
BLAKE2b-256 checksum How to use checksums |
c9934a54cbf374531720b3da8871c26db6f3a501f6769aaf9e8b013a30ae4bf7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.
Transparency logRelease files / causasv-0.8.9-cp314-cp314-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
| Download URL | causasv-0.8.9-cp314-cp314-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.14 macOS 10.12+ universal2 (ARM64, x86-64) macOS 10.12+ x86-64 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
a07f7ceda0b4c661d900c9ba9a4524cdc96147ae608a1de7e1e8c3f0008a5fdb
|
|
BLAKE2b-256 checksum How to use checksums |
fcf3bb0fc0dfe9793599b113d6681f6c9d871ca3b34cc55f9bd6a9ecc6255f15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.
Transparency logRelease files / causasv-0.8.9-cp312-cp312-win_amd64.whl
| Download URL | causasv-0.8.9-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 494.3 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
313a0dfb6bb22148bbe61ab1e8c50a8b61e1e93c881e9db2b735c8221ee3e6c2
|
|
BLAKE2b-256 checksum How to use checksums |
087881d90fec6b0c83048c2d4a935d4ab368fc4cd177b6b67a9c5a3b9d147980
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.
Transparency logRelease files / causasv-0.8.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | causasv-0.8.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 718.2 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
bd677e4d68acf21a467ba2c6b81d3070ca99b2e961e7c27beeaecc7c684a623d
|
|
BLAKE2b-256 checksum How to use checksums |
c05cd8be93361e9b2460e9383c54d9430e8d9a91e25831ee61d5b701680b2ba2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 3, 2026.
Transparency log