causal-automata: GPU-Native Causal Discovery via Synchronous Cellular Automata in JAX
Classical constraint-based causal discovery (PC / Meek orientation rules) relies on sequential branching and dynamic conditioning sets that bottleneck on CPU. causal-automata reformulates structure learning as a synchronous, strictly acyclic dynamical system over an adjacency matrix (A_t) and a 1D topological potential field (E_t) ("Gravity"), compiling into a single XLA jax.lax.scan loop on GPU/TPU.
Convergence animation
Short clip of the elevation field (E_t) and adjacency (A_t) peeling off a flat (E\approx 0.5) plateau (corr_flat init) toward the ground-truth DAG (Phase-2 N=10 demo): roots hold high, V-well colliders sink.
- Downhill Acyclicity by Construction ((O(N^2)) projection): Edges only flow from higher elevation (E_i) to lower elevation (E_j) ((E_i > E_j)), guaranteeing a strict DAG without (O(N^3)) matrix-exponential penalties. (A full tick with dense pair scores and batched ((2+k)\times(2+k)) inversions still scales closer to (O(N^3)).)
- V-Wells on elevations: Shared neighbors of marginally independent pairs are pulled downward in (E) with a multiplicative decay (collider cue; avoids clipping into an even/odd SHD limit cycle); later birth / downhill projection prefer (i \to k \leftarrow j).
- Local-margin Gravity: Elevation drift toward parent/child means with a small margin for roots/leaves (no hard (1.0/0.0) anchors that saturated random inits).
Regenerate the animation assets locally (GIF + MP4; needs ffmpeg for the MP4):
python scripts/generate_hero_gif.py
Benchmarks (N=100)
Wall-clock vs accuracy: On the N=100 linear-Gaussian SEM (
seed=0,ticks=100), Bayesian CA finishes in ~2.9s on CPU JAX — about 180× faster than PC (gcastle, 528s) — while Maximum Accuracy Mode (--multihop) reaches Directed F1 0.696 / Skeleton F1 0.928. Reproduce with:python -m causal_automata.benchmark --n 100 --seed 0 --ticks 100
v0.3.5 — Undirected final gravity projection (U_surviving * downhill) and 2-node PC sepset screening so mid-tick elevation flips reverse edges instead of wiping them and backdoor forks are not misclassified as colliders. Builds on v0.3.4 V-well / anti-sink / progressive s_max / Fisher-z. See CHANGELOG.md. Maximum Accuracy Mode (--multihop) still reaches Directed F1 0.696 on N=100.
Default stack (Upgrade 2): k=3 if N≤50, k=5 if N>50, binary edges, 1-hop gravity. On N=100 (seed=0, static thresholds, ticks=100) that baseline hits Skeleton 0.937 / Directed 0.619 in about 2.8s.
Maximum Accuracy Mode — pass --multihop (Upgrade 4): 2-hop elevation gravity via A @ A lifts Directed F1 to 0.696 with essentially flat wall time.
| Algorithm | Skeleton F1 | Directed F1 | Wall Time (s) |
|---|---|---|---|
| PC (gcastle) | 0.968 | 0.813 | 528.631 |
| GOLEM (gcastle) | 0.577 | 0.403 | 251.182 |
| Bayesian CA (JAX, k=5, 1-hop) | 0.937 | 0.619 | ~2.9 |
Bayesian CA (JAX, k=5, --multihop) |
0.928 | 0.696 | ~2.9 |
PC / GOLEM wall times are Colab Tesla T4 (num_iter=20000). CA times are CPU JAX for the Upgrade-2 / Upgrade-4 A/B; at historical k=3 the same CA finished in 0.323s on T4 with Directed F1 0.483.
Opt-in flags (defaults stay fast & binary):
--multihop— Maximum Accuracy Mode (2-hop gravity, Directed F1 0.696 on this SEM).--fuzzy— continuousA ∈ [0, 1]soft birth/death (experimental; did not beat binary here).
Conditioning-set sweep (CA-only, 1-hop binary, same SEM):
| Algorithm | Skeleton F1 | Directed F1 | Wall Time (s) |
|---|---|---|---|
| Bayesian CA (JAX, k=3) | 0.812 | 0.483 | 2.314 |
| Bayesian CA (JAX, k=4) | 0.915 | 0.546 | 2.481 |
| Bayesian CA (JAX, k=5) | 0.937 | 0.619 | 2.871 |
| Bayesian CA (JAX, k=6) | 0.937 | 0.619 | 2.454 |
| Bayesian CA (JAX, k=7) | 0.937 | 0.619 | 3.049 |
| Bayesian CA (JAX, k=8) | 0.937 | 0.627 | 3.647 |
More benchmark variants:
# Maximum Accuracy Mode (Upgrade 4) — Directed F1 0.696 on the N=100 SEM
python -m causal_automata.benchmark --n 100 --ca-only --k 5 --multihop
python -m causal_automata.benchmark --n 100 --ca-only --k 5 --compare-multihop
python -m causal_automata.benchmark --n 100 --ca-only --k-sweep 5,6,7,8
python -m causal_automata.benchmark --smoke # device checks + GOLEM init only
30-Second Quickstart
pip install causal-automata
# With CPU JAX:
pip install "causal-automata[jax]"
# NVIDIA CUDA JAX:
pip install "causal-automata[cuda]"
Minimal JAX snippet (ticks / k are static for XLA):
import jax.numpy as jnp
from causal_automata import step, run, binarize, warmup
print(warmup()) # compile on a tiny problem
N = 10
A0 = jnp.triu(jnp.ones((N, N)), k=1) * 0.0 # or a random DAG init
E0 = jnp.linspace(1.0, 0.0, N)
Cov = jnp.eye(N) # replace with empirical covariance of your data
# One tick
A1, E1 = step(A0, E0, Cov, k=3)
# Full synchronous scan (JIT; ticks & k are static_argnames)
A_final, E_final = run(A0, E0, Cov, ticks=100, k=3)
A_bin = binarize(A_final)
Synthetic harness & CLI:
python -m causal_automata.bayesian_synth --n 10
python -m causal_automata.bayesian_synth --n 50 --backend jax
python -m causal_automata.bayesian_synth --n 100
Or with uv:
uv add "causal-automata[jax]"
How the 4 Dynamical Rules Work
State is a binary DAG adjacency (A), node elevations (E \in [0,1]), and a fixed empirical covariance (\mathrm{Cov}) from continuous observations. Each tick is a local cellular update (gravity → V-well → death → birth):
- Gravity — raw downhill projection, then local-margin elevation drift (roots sit just above children, leaves just below parents; isolates hold (E)). Optional
--multihopalso pulls toward 2-hop means from (A @ A). - V-Well — multiplicatively lowers elevations of shared neighbors of marginally independent pairs (collider cue on (E); edges re-orient via birth / downhill later).
- Death — prune weak edges using partial correlations conditioned on the top-
kunion neighbors ranked by absolute correlation (|R|) (heuristic CI — not an exhaustive (\min_Z) search). - Birth — add strong edges with the same partial-corr gate; orientation uses a deterministic elevation tie-break so nodes clipped at the same bound still get a direction. Optional
--fuzzykeeps continuous weights in ([0, 1]) and binarizes only after the final tick.
NumPy (bayesian.step) and JAX (jax_core.step / run) share this physics. The JAX port is @jax.jit-compiled; run(..., ticks=..., k=...) marks ticks and k as static so jax.lax.scan length and (2+k)×(2+k) partial-corr blocks stay compile-time constants. See JAX static arguments for functools.partial patterns that avoid ConcretizationTypeError.
Full documentation (theory, physics, API, CLI): https://causal-automata.readthedocs.io/en/latest/
Background & Origin
causal-automata evolved from graphnet-automata, a sister project exploring the application of 1D cellular automata rules to dynamic network graphs. While graphnet-automata focuses on generalized structural evolution and terminal-based visualization, this repository specializes those concepts into a high-performance, JAX-accelerated engine specifically designed for causal discovery and DAG generation.
Package layout
causal-automata/
├── causal_automata/
│ ├── __init__.py
│ ├── bayesian.py # NumPy Bayesian CA step
│ ├── bayesian_synth.py # Synthetic linear-DAG harness
│ ├── jax_core.py # JAX @jit step / run
│ └── benchmark.py # vs gCastle PC / GOLEM
├── scripts/
│ └── generate_hero_gif.py # README convergence GIF + MP4
├── assets/
│ ├── elevation_convergence.gif
│ └── elevation_convergence.mp4
├── docs/ # Sphinx / Read the Docs
├── tests/
├── .readthedocs.yaml
├── pyproject.toml
├── README.md
└── NOTICE
Citation
If you use causal-automata in research, please cite:
@software{yamagiwa2026causalautomata,
author = {Yamagiwa, Masakazu},
title = {causal-automata: GPU-Native Causal Discovery via Synchronous Cellular Automata in JAX},
year = {2026},
version = {0.3.5},
url = {https://github.com/kazuyamagiwa/causal-automata},
license = {Apache-2.0}
}
Contributing
Issues and pull requests are welcome. Please run the synthetic / unit suite before opening a PR:
pip install -e ".[jax,dev]"
pytest -q
python -m causal_automata.bayesian_synth --n 10 --backend jax
License / notice
See NOTICE. Copyright 2026 Masakazu Yamagiwa.
Metadata
Release files for causal-automata 0.3.5
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 |
|---|---|---|---|---|
| causal_automata-0.3.5.tar.gz | 52.3 kB | Without provenance | Details for causal_automata-0.3.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| causal_automata-0.3.5-py3-none-any.whl | Python 3 | none | any | Details for causal_automata-0.3.5-py3-none-any.whl |
Total release size: 94.1 kB
Release files / causal_automata-0.3.5.tar.gz
| Download URL | causal_automata-0.3.5.tar.gz |
|---|---|
| Size | 52.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
715614e6f2af086b1a4c9ddedbf0a8c3cead37b8242b0424e1c72594e39dfb81
|
|
BLAKE2b-256 checksum How to use checksums |
27bd002369a282a00cb062c20c5d2738f4a25c33ed3b7e382a03bb5403206d5b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / causal_automata-0.3.5-py3-none-any.whl
| Download URL | causal_automata-0.3.5-py3-none-any.whl |
|---|---|
| Size | 41.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46a48e557c4c350f35694c859d829e262684c98a0a93e082631e8495b5c0476a
|
|
BLAKE2b-256 checksum How to use checksums |
afaced9c3b301ea213a2375ab416e3bb3ae38913fe9ea18b41f446bba0acb926
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for causal-automata 0.3.5
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.