Skip to main content

A JAX-based research framework for writing differentiable numerical simulators with arbitrary discretizations

Project description

jaxdf - JAX-based Discretization Framework

Support License: LGPL v3 codecov CI

Overview | Example | Installation | Documentation | Support


Overview

Jaxdf is a package based on JAX that provides a coding framework for creating differentiable numerical simulators with arbitrary discretizations.

The primary objective of Jaxdf is to aid in the construction of numerical models for physical systems, like wave propagation, or the numerical resolution of partial differential equations, in a manner that is easily tailored to the user's research requirements. These models are pure functions that can be seamlessly integrated into arbitrary differentiable programs written in JAX. For instance, they can be employed as layers within neural networks, or utilized in constructing a physics loss function.


Example

The script below constructs the non-linear operator (∇2 + sin), applying a Fourier spectral discretization on a square 2D domain. It then utilizes this operator to define a loss function. The gradient of this loss function is calculated using JAX's Automatic Differentiation.

from jaxdf import operators as jops
from jaxdf import FourierSeries, operator
from jaxdf.geometry import Domain
from jax import numpy as jnp
from jax import jit, grad


# Defining operator
@operator
def custom_op(u, *, params=None):
  grad_u = jops.gradient(u)
  diag_jacobian = jops.diag_jacobian(grad_u)
  laplacian = jops.sum_over_dims(diag_jacobian)
  sin_u = jops.compose(u)(jnp.sin)
  return laplacian + sin_u

# Defining discretizations
domain = Domain((128, 128), (1., 1.))
parameters = jnp.ones((128,128,1))
u = FourierSeries(parameters, domain)

# Define a differentiable loss function
@jit
def loss(u):
  v = custom_op(u)
  return jnp.mean(jnp.abs(v.on_grid)**2)

gradient = grad(loss)(u) # gradient is a FourierSeries

Installation

Before proceeding with the installation of jaxdf, ensure that JAX is already installed on your system. If you intend to utilize jaxdf with NVidia GPU support, follow the instructions to install JAX accordingly.

To install jaxdf from PyPI, use the pip command:

pip install jaxdf

For development purposes, install jaxdf by either cloning the repository or downloading and extracting the compressed archive. Afterward, navigate to the root folder in a terminal, and execute the following command:

pip install --upgrade uv
uv sync

This will install the dependencies and the package itself (in editable mode).

Support

Support

If you encounter any issues with the code or wish to suggest new features, please feel free to open an issue. If you seek guidance, wish to discuss something, or simply want to say hi, don't hesitate to write a message in our Discord channel.


Contributing

Contributions are absolutely welcome! Most contributions start with an issue. Please don't hesitate to create issues in which you ask for features, give feedback on performances, or simply want to reach out.

To make a pull request, please look at the detailed Contributing guide for how to do it, but fundamentally keep in mind the following main guidelines:

  • If you add a new feature or fix a bug:
    • Make sure it is covered by tests
    • Add a line in the changelog using kacl-cli
  • If you changed something in the documentation, make sure that the documentation site can be correctly build using mkdocs serve


Citation

arXiv

An initial version of this package was presented at the Differentiable Programming workshop at NeurIPS 2021.

@article{stanziola2021jaxdf,
    author={Stanziola, Antonio and Arridge, Simon and Cox, Ben T. and Treeby, Bradley E.},
    title={A research framework for writing differentiable PDE discretizations in JAX},
    year={2021},
    journal={Differentiable Programming workshop at Neural Information Processing Systems 2021}
}

Acknowledgements

Related projects

  1. odl Operator Discretization Library (ODL) is a python library for fast prototyping focusing on (but not restricted to) inverse problems.
  2. deepXDE: a TensorFlow and PyTorch library for scientific machine learning.
  3. SciML: SciML is a NumFOCUS sponsored open source software organization created to unify the packages for scientific machine learning.

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

jaxdf-0.3.0.tar.gz (8.8 MB view details)

Uploaded Source

Built Distribution

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

jaxdf-0.3.0-py3-none-any.whl (28.3 kB view details)

Uploaded Python 3

File details

Details for the file jaxdf-0.3.0.tar.gz.

File metadata

  • Download URL: jaxdf-0.3.0.tar.gz
  • Upload date:
  • Size: 8.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for jaxdf-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ce377f4db535b5ca5329371d62e5572ed4bd1778591ef2476637d982363047c3
MD5 7fe64b255223531024329bb375353d40
BLAKE2b-256 9f23980e54c77a950bc5ba65038d0b958d988fe9c75c40b6adabeddbcdbd22fd

See more details on using hashes here.

File details

Details for the file jaxdf-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: jaxdf-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 28.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for jaxdf-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c1dfdee22e5e4cf091b0a26c523403d518631d42347a412ff05d353409b30b72
MD5 bb73863f5ae132b4d43a5f4dc44908fd
BLAKE2b-256 5762d2a45e7ba2035b503f6fed949029728bdf06d2dfd0b07acb4df6b0c0b785

See more details on using hashes here.

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