Skip to main content

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}
}

Metadata

Release files for jax2sympy 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for jax2sympy 0.0.2
File Size Uploaded
jax2sympy-0.0.2.tar.gz 19.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for jax2sympy 0.0.2
File Interpreter ABI Platform
jax2sympy-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 40.3 kB

Release files / jax2sympy-0.0.2.tar.gz

Download URL jax2sympy-0.0.2.tar.gz
Size 19.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c56adf95607c60a15513c9ce5a60b9a2e021cba042d4d84051b96e7532b5efc1
BLAKE2b-256 checksum
How to use checksums
39c8bd385ff2db25eb7c51816405ebba0c834f5a1ffbe017609d21a26e009dd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 15, 2026.

Transparency log

Release files / jax2sympy-0.0.2-py3-none-any.whl

Download URL jax2sympy-0.0.2-py3-none-any.whl
Size 20.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9c163cd2423444595e31b4e98681e419a3818c2e668775e80fbee7e6ef23c7ba
BLAKE2b-256 checksum
How to use checksums
aa68d463359997c0d7c8cd2a371aacaf6a89237ae8e8bbdd51dd53864cc3bd08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 15, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page