Automatic Sparse Differentiation in JAX
Project description
asdex
Automatic Sparse Differentiation in JAX.
asdex (pronounced Aztecs) exploits sparsity structure to efficiently materialize Jacobians and Hessians.
It implements a custom Jaxpr interpreter
that uses abstract interpretation
to detect sparsity patterns from the computation graph,
then uses graph coloring to minimize the number of AD passes needed.
Installation
pip install asdex
Or with uv:
uv add asdex
Example
import asdex
import jax
import numpy as np
def f(x):
return (x[1:] - x[:-1]) ** 2
jac_fn = jax.jit(asdex.jacobian(f, input_shape=50))
# ColoredPattern(49×50, nnz=98, sparsity=96.0%, JVP, 2 colors)
# 2 JVPs (instead of 49 VJPs or 50 JVPs)
# ⎡⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎤ ⎡⣿⎤
# ⎢⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥ → ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⠀⠀⎥ ⎢⣿⎥
# ⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⢦⡀⎥ ⎢⣿⎥
# ⎣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⎦ ⎣⠉⎦
for x in inputs:
J = jac_fn(x)
Instead of 49 VJPs or 50 JVPs,
asdex computes the full sparse Jacobian with just 2 JVPs.
Documentation
- Getting Started: step-by-step tutorial
- How-To Guides: task-oriented recipes
- Explanation: how and why it works
- API Reference: full API documentation
Acknowledgements
This package is built with Claude Code based on previous work by Adrian Hill, Guillaume Dalle, and Alexis Montoison in the Julia programming language:
- An Illustrated Guide to Automatic Sparse Differentiation, A. Hill, G. Dalle, A. Montoison (2025)
- Sparser, Better, Faster, Stronger: Efficient Automatic Differentiation for Sparse Jacobians and Hessians, A. Hill & G. Dalle (2025)
- Revisiting Sparse Matrix Coloring and Bicoloring, A. Montoison, G. Dalle, A. Gebremedhin (2025)
- SparseConnectivityTracer.jl, A. Hill, G. Dalle
- SparseMatrixColorings.jl, G. Dalle, A. Montoison
- sparsediffax, G. Dalle
These works in turn stand on the shoulders of giants, notably Andreas Griewank, Andrea Walther, and Assefaw Gebremedhin.
The asdex logo was designed by @overripemango.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asdex-0.2.0.tar.gz.
File metadata
- Download URL: asdex-0.2.0.tar.gz
- Upload date:
- Size: 389.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
98a8c9cf6c22ed7d53ce25e16dd1f919f6712b567fbe1a2ab1e9a8218467c38f
|
|
| MD5 |
723e193695465ce077fe3f1451984569
|
|
| BLAKE2b-256 |
027d20c6cd8fac077569fdc2d87371ca1d22905539812fabf0b6c3a4795eedc6
|
File details
Details for the file asdex-0.2.0-py3-none-any.whl.
File metadata
- Download URL: asdex-0.2.0-py3-none-any.whl
- Upload date:
- Size: 94.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff6b01ddf345e45bf7d82b2686e31ee27caba4f2d9d90a8d7e2a1767f3216240
|
|
| MD5 |
6995e925dbb742a12bc650b4763a9e94
|
|
| BLAKE2b-256 |
64f7d4002b932b71e925c6bc2f3a561fdb8c069e71ca41772dc8a77b57ce8dcb
|