Translate jaxpr graphs into elementwise SymPy expressions for symbolic analysis.
Project description
Jax2SymPy
This repo translates jaxpr graphs into a SymPy elementwise expressions. This allows for symbolic analysis of the system.
My use case is finding sparsity pattern of jacobians and hessians of vector valued functions through symbolic differentiation, find example code under sparsity.py.
I built this repo as part of a project to GPU-batch solve many IPOPT optimizations in jaxipm.
Installation
pip:
pip install jax2sympy
uv:
uv pip install jax2sympy
Using a uv-managed project instead? Just
uv add jax2sympy.
Usage
Get the symbolic Jacobian of a JAX function together with its sparsity pattern:
import jax.numpy as jnp
from jax2sympy import get_symbolic_jacobian
def f(x):
return jnp.array([x[0] * x[1], jnp.sin(x[2]), x[0] + x[2]])
x = jnp.ones(3)
# sym_jac_val: SymPy expressions for the non-zero Jacobian entries
# sym_jac_coo: (nnz, 2) array of [output_index, input_index] coordinates
sym_jac_val, sym_jac_coo, input_symbols, const_symbols = get_symbolic_jacobian(f, x)
print(sym_jac_coo) # sparsity pattern
print(sym_jac_val) # symbolic derivatives
get_symbolic_hessian returns the analogous result for second derivatives, with
(nnz, 3) coordinates of [output_index, i, j].
Public API
jaxpr_to_sympy_expressions— translate ajaxprinto SymPy expressionsget_symbolic_jacobian/get_symbolic_hessian— symbolic derivatives + sparsitysparse_jacobian_sym/sparse_hessian_sym— build sparse symbolic derivative functionsget_sparsity_pattern,sparse_jacobian,sparse_hessian,get_dense— numeric sparsity utilities
Citation
@article{viljoen2026scaling,
title={Scaling Nonlinear Optimization: Many Problems One GPU},
author={Viljoen, John and Haffner, Johanna and Tomizuka, Masayoshi and Mehr, Negar},
journal={arXiv preprint arXiv:2606.26341},
year={2026}
}
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 jax2sympy-0.0.2.tar.gz.
File metadata
- Download URL: jax2sympy-0.0.2.tar.gz
- Upload date:
- Size: 19.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c56adf95607c60a15513c9ce5a60b9a2e021cba042d4d84051b96e7532b5efc1
|
|
| MD5 |
92385af2078993982804975736b6cc57
|
|
| BLAKE2b-256 |
39c8bd385ff2db25eb7c51816405ebba0c834f5a1ffbe017609d21a26e009dd5
|
Provenance
The following attestation bundles were made for jax2sympy-0.0.2.tar.gz:
Publisher:
publish.yml on johnviljoen/jax2sympy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jax2sympy-0.0.2.tar.gz -
Subject digest:
c56adf95607c60a15513c9ce5a60b9a2e021cba042d4d84051b96e7532b5efc1 - Sigstore transparency entry: 2175747522
- Sigstore integration time:
-
Permalink:
johnviljoen/jax2sympy@2cb6a6568716b26af0abd542a941f87ae0580e25 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/johnviljoen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2cb6a6568716b26af0abd542a941f87ae0580e25 -
Trigger Event:
push
-
Statement type:
File details
Details for the file jax2sympy-0.0.2-py3-none-any.whl.
File metadata
- Download URL: jax2sympy-0.0.2-py3-none-any.whl
- Upload date:
- Size: 20.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c163cd2423444595e31b4e98681e419a3818c2e668775e80fbee7e6ef23c7ba
|
|
| MD5 |
d7d29c645e2886bb20e7ba778626c1c1
|
|
| BLAKE2b-256 |
aa68d463359997c0d7c8cd2a371aacaf6a89237ae8e8bbdd51dd53864cc3bd08
|
Provenance
The following attestation bundles were made for jax2sympy-0.0.2-py3-none-any.whl:
Publisher:
publish.yml on johnviljoen/jax2sympy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
jax2sympy-0.0.2-py3-none-any.whl -
Subject digest:
9c163cd2423444595e31b4e98681e419a3818c2e668775e80fbee7e6ef23c7ba - Sigstore transparency entry: 2175747550
- Sigstore integration time:
-
Permalink:
johnviljoen/jax2sympy@2cb6a6568716b26af0abd542a941f87ae0580e25 -
Branch / Tag:
refs/tags/v0.0.2 - Owner: https://github.com/johnviljoen
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2cb6a6568716b26af0abd542a941f87ae0580e25 -
Trigger Event:
push
-
Statement type: