To main content

Differentiable simulation and sensitivity analysis

How do simulation results change when model parameters, input data or control variables are adjusted? We develop differentiable simulators and efficient methods for sensitivity analysis. By combining automatic differentiation, adjoint methods and numerical modelling, we enable simulators to support model calibration, optimization and integration with machine learning.

Contact persons

What we can help you with

A simulator predicts how a system behaves under specified conditions. In many applications, we also need to understand how the results change when those conditions are adjusted. Which parameters have the greatest influence? How should the model be fitted to measurements? What changes to design or operation could improve performance?

We develop methods and software that compute these relationships efficiently, including for large, nonlinear and time-dependent models. We can help you:

  • Compute sensitivities with respect to model parameters, initial and boundary conditions, and control variables.
  • Develop and integrate automatic differentiation and adjoint methods into simulation tools.
  • Enable simulators to support gradient-based model calibration and optimisation.
  • Connect physics-based simulators with data-driven models and machine learning.
  • Verify gradient computations and investigate how numerical choices affect the results.

Contact our Applied Computational Science research group if you need sensitivities from an existing simulator or want to develop new tools for analysis, calibration and optimisation.

From simulation results to sensitivities

A sensitivity describes how a quantity of interest responds to a small change in a parameter. That quantity might be stored energy, produced volume, battery capacity or the mismatch between simulated and measured data.

A straightforward approach is to change one parameter at a time and rerun the simulation. This can be useful for verification and smaller problems, but becomes expensive when the model has many parameters. Numerical noise and the choice of perturbation size can also make finite-difference sensitivities difficult to compute accurately.

We develop methods that directly exploit the model equations and computational dependencies. This makes it possible to compute gradients for problems with very large numbers of parameters without running a separate simulation for each parameter.

Automatic differentiation of model equations

Automatic differentiation computes derivatives by applying the chain rule to the operations in a computer program. It differs from both symbolic differentiation and finite-difference approximations. When model equations are implemented using operations supported by the framework, their derivatives can be computed alongside the function values.

We have extensive experience developing and using automatic differentiation for discretised physical models. This includes computing Jacobian matrices for nonlinear solvers and derivatives with respect to parameters and other model quantities.

Efficiency depends on how the computations are organised. We exploit sparsity, local couplings and known computational patterns to reduce memory use and computational cost. Several of these techniques are described in our book chapter on optimised automatic differentiation and efficient solvers. Our aim is to combine flexible model descriptions with the performance required for large simulations.

Adjoint methods for the full simulation

Differentiating the model equations is not the same as computing how the final result of a simulation depends on its inputs. For time-dependent problems, sensitivities must account for how changes propagate throughout the simulation.

We develop discrete adjoint methods that compute gradients of objective functions by solving an associated problem backwards through the time steps. This is particularly efficient when there are many parameters and only a few objective functions. The computational cost then does not grow in proportion to the number of parameters, as it normally does when running separate perturbation simulations.

For implicit simulators, sensitivities can be computed from the converged discrete equations. This avoids differentiating through every iteration used to obtain the solution. We work on the interplay between automatic differentiation, adjoint equations, linear solvers, and the storage or reconstruction of simulation states.

Enabling calibration, optimisation and machine learning

In model calibration, gradients indicate how parameters can be adjusted to reduce the mismatch between simulations and observations. In optimisation, they describe how an objective responds to changes in design or operation. Sensitivities can also help reveal which parameters are informed by the observations and where different parameters have similar effects.

Differentiable simulators also make it possible to train models that incorporate physical equations directly into the computation. We work with both trainable physics-based models and combinations of simulators and neural networks. Gradients connect the physical and data-driven components of the model.

Local sensitivities describe behaviour near a particular point in parameter space. They can support uncertainty analysis, but do not on their own provide a complete account of uncertainty or of model behaviour under large parameter changes.

Reliability and numerical choices

A computed gradient must correspond to the model and objective function we intend to investigate. Solver tolerances, time stepping, changes in operating conditions and nonsmooth model functions can affect both gradient accuracy and interpretation.

We investigate these effects and verify sensitivities using directional derivative checks and comparisons with perturbation calculations. For adaptive algorithms and discrete switches, it is important to establish which choices remain fixed during differentiation and which dependencies are included.

This requires an understanding of the physics, numerical methods and implementation. Our expertise covers the full process, from formulating discrete models to computing gradients efficiently and using them in subsequent analyses.

Experience across simulation tools

We have developed automatic differentiation and adjoint methods through many years of work on scientific software. Our experience includes MRST for flow in porous media, Jutul and JutulDarcy for differentiable multiphysics and flow simulation, and BattMo for electrochemical modelling.

This work spans flexible research frameworks and computational methods for demanding industrial models. It provides a foundation for assessing how differentiability can be introduced into existing software and which parts of a simulator need to be adapted to support efficient, reliable sensitivity computations.

Selected publications

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.