Skip to main content

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 a jaxpr into SymPy expressions
  • get_symbolic_jacobian / get_symbolic_hessian — symbolic derivatives + sparsity
  • sparse_jacobian_sym / sparse_hessian_sym — build sparse symbolic derivative functions
  • get_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

jax2sympy-0.0.2.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

jax2sympy-0.0.2-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

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

Hashes for jax2sympy-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c56adf95607c60a15513c9ce5a60b9a2e021cba042d4d84051b96e7532b5efc1
MD5 92385af2078993982804975736b6cc57
BLAKE2b-256 39c8bd385ff2db25eb7c51816405ebba0c834f5a1ffbe017609d21a26e009dd5

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax2sympy-0.0.2.tar.gz:

Publisher: publish.yml on johnviljoen/jax2sympy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for jax2sympy-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9c163cd2423444595e31b4e98681e419a3818c2e668775e80fbee7e6ef23c7ba
MD5 d7d29c645e2886bb20e7ba778626c1c1
BLAKE2b-256 aa68d463359997c0d7c8cd2a371aacaf6a89237ae8e8bbdd51dd53864cc3bd08

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax2sympy-0.0.2-py3-none-any.whl:

Publisher: publish.yml on johnviljoen/jax2sympy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page