Code Monkey home page Code Monkey logo

jaxdf's Introduction

jaxdf - JAX-based Discretization Framework

License: LGPL v3 codecov Continous Integration Documentation

Overview | Example | Installation | Documentation

⚠️ This library is still in development. Breaking changes may occur.


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. The output is given over the whole collocation grid.

from jaxdf import operators as jops
from jaxdf.core import 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(mod_diag_jacobian)
    sin_u = jops.elementwise(jnp.sin)(u)
    return laplacian + sin_u

# Defining discretizations
domain = Domain((256, 256), (1., 1.))
fourier_discr = FourierSeries(domain)
u_fourier_params, u = fourier_discr.empty_field(name='u')

# Discretizing operators: getting pure functions and parameters
result = custom_op(u=u)
op_on_grid = result.get_field_on_grid(0)
global_params = result.get_global_params() # This contains the Fourier filters

# Compile and use the pure function
result_on_grid = jit(op_on_grid)(
    global_params,
    {"u": u_fourier_params}
)

# Define a differentiable loss function
def loss(u_params):
    op_output = jit(op_on_grid)(global_params, {"u": u_params})
    return jnp.mean(jnp.abs(op_output)**2)

gradient = grad(loss)(u_fourier_params)

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.

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.txt
pip install .

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

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.

jaxdf's People

Contributors

astanziola avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.