Skip to main content

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

Project description

jaxdf - JAX-based Discretization Framework

License: LGPL v3 codecov Continous Integration

Overview | Example | Installation | Documentation


Overview

jaxdf is a JAX-based package defining a coding framework for writing differentiable numerical simulators with arbitrary discretizations.

The intended use is to build numerical models of physical systems, such as wave propagation, or the numerical solution of partial differential equations, that are easy to customize to the user's research needs. Such models are pure functions that can be included into arbitray differentiable programs written in JAX: for example, they can be used as layers of neural networks, or to build a physics loss function.


Example

The following script builds the non-linear operator (∇2 + sin), using a Fourier spectral discretization on a square 2D domain, and uses it to define a loss function whose gradient is evaluated using JAX 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):
  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 installing jaxdf, make sure that you have installed JAX. Follow the instruction to install JAX with NVidia GPU support if you want to use jaxdf on the GPUs.

You can install jaxdf from PyPI using pip:

pip install jaxdf

For development, install jaxdf by cloning the repository or downloading and extracting the compressed archive. Then navigate in the root folder in a terminal, and run

pip install -r .requirements/requirements.txt
pip install -e .

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


Citation

arXiv

This package will be 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.2.2.tar.gz (21.4 kB view hashes)

Uploaded Source

Built Distribution

jaxdf-0.2.2-py3-none-any.whl (28.3 kB view hashes)

Uploaded Python 3

Supported by

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