To main content

Rapid prototyping of differentiable simulators

To research innovative computational methods and mature them to a stage suitable for commercial implementation or deployment it is imperative to develop and maintain efficient and flexible ecosystems that facilitate effective experimental programming, rapid prototyping, rigorous testing, and validation in realistic environments.

Contact persons

Differentiable simulators can seamlessly integrate with modern data-driven and optimization techniques to accelerate the pace of scientific discovery and engineering design. Not only do they produce simulation outputs, but can also compute gradients of these outputs with respect to the inputs. This is crucial for  optimization, sensitivity analysis, and uncertainty quantification, as it enables use of  gradient-based optimization and machine learning to efficiently explore the parameter space and make informed decisions.

What do we do?

We research how to construct computational ecosystems for rapid prototyping and differentiable simulators by developing several exemplar ecosystems: MRST and OPM Flow for flow in porous media, BattMo for electrochemical devices and processes, and Jutul for multiphysics applications.

This entails:

  1. Developing suitable software abstractions and modularity to hide specific details (i.e., by using a general unstructured format for all grids) and separating different contexts such as physical models, discretizations and discrete operators (see figure below), time-stepping and nonlinear solver, and linearization, assembly, and solution of linear systems.
  2. Using automatic differentiation (AD) to compute derivatives, gradients, and Jacobians. The idea is simple: you implement the discretized model equations in residual form, and the AD library computes the necessary derivatives to linerize the resulting system of nonlinear algebraic equations to obtain the Jacobian matrix required by the nonlinear solver. This is particularly advantageous if you wish to quickly introduce new functional dependencies or couple multiple submodels.
  3. Defining computational graphs to trace and manage functional dependencies reduces redundant computations and enables efficient use of compute cache and lazy evaluation. This, paired with automatic differentiation, facilitates use of generic functional interfaces, simplifying the integration of new parameter and variable dependencies. These concepts have been realized in slighlty different ways in MRST (and Jutul) and in BattMo.
  4. Using  adjoint methods to compute gradients of cost functions relative to model parameters by solving adjoint equations derived from the original PDE model to determine how changes in model input impact the cost function. This backward propagation through the computational graph is akin to backpropagation in machine learning, but adjoint methods are broader in scope and applicable to general PDE-based models in scientific and engineering.
discrete-operators.png
Illustration of the concept of abstract differentiation operators. These are constructed initially from the topology of the grid (mappings from each cell to its bounding faces and from each face to the connected cells) and can then be used subsequently in the code to hide details of the grid and write the discrete model equations in a form close to the continuous PDE model. 

Automatic differentiation

We have researched different AD approaches:

  • The data organization of the AD library in MRST revolves around variables and typically treats one variable/intermediate quantity at the time, updating its values and derivatives across all cells in the domain.  This enables vectorization and gives a more natural representation of physical quantities and equations in the code, mirroring the mathematical formulation of the PDEs. However, inevitably also results in redundant computations and excessive memory use. To counteract, we have researched more memory-optimized backends written in compiled languages.
  • The AD library in OPM Flow, in contrast, is organized around grid cells, and loosely speaking updates all values/derivatives associated with a cell before moving on to the next.  This offers better memory access  and cache utilization at the expense of a somewhat less intuitive code.
  • Jutul features a highly optimized automatic differentiation library that uses static, hard-coded stencils to ensure fast assembly of linearized systems. The software can also utilize AD functionalities from the Julia language.

Read more

Software

BattMo

BattMo

BattMo is an open source simulation code for continuum modelling of electrochemical devices written in Matlab and Julia

Jutul

Jutul

Experimental Julia framework for fully differentiable multiphysics simulators based on implicit finite-volume methods with automatic differentiation.

MRST - MATLAB Reservoir Simulation Toolbox

MRST - MATLAB Reservoir Simulation Toolbox

A free open-source community code for rapid prototyping of new methods for modelling and simulation of flow in porous media. Has a large user community from all over the world.

Open Porous Media (OPM)

Open Porous Media (OPM)

The Open Porous Media (OPM) initiative provides open-source software for simulation, upscaling and visualization of porous media processes, in particular subsurface reservoirs.