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.1.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.1-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file jax2sympy-0.0.1.tar.gz.

File metadata

  • Download URL: jax2sympy-0.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 aff67779a11082c7605c0fc97347b67433cd89e22450b7ce37354460de2357d8
MD5 c6fe0cc29cd9dceb17ea3475626831b1
BLAKE2b-256 64a1024fc3464f5785f8de34370c216214ee3c8bd559ce898829a1dc317e935b

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax2sympy-0.0.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: jax2sympy-0.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1132d180d84cc0458d0166fb2c21109fc808d6d9d716bc19a5eea319b43cd1ed
MD5 b62812a3b75285ca97d7a5e24b138aaa
BLAKE2b-256 b387e6213081c4347b7438c073a3f3534270c469903076b5a836fea5c78f6d47

See more details on using hashes here.

Provenance

The following attestation bundles were made for jax2sympy-0.0.1-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