TransWikia.com

When and when not to use automatic differentiation

Computational Science Asked by tmph on April 22, 2021

I am just learning (more) about automatic differentiation (AD) and at this stage it kind of seems like black magic to me. The second paragraph of its Wikipedia article makes it sound too good to be true: it is extremely fast and is exact (no round off, no discretisation). I am left wondering why finite difference (FD) is so ubiquitous in scientific computing. Looking this up, I seem to only find tutorials on how to implement AD, the advantages of AD, and its applications in gradient-based optimisers. But what is an example of when not to use AD, and instead use FD? Surely there must many.

As just one example, in computational electromagnetics a FD approach is very standard; why can we not propagate Maxwell’s equations with AD (FDTD: why not ADTD?)? It is clearly not because the developers aren’t aware of it because the same people implement AD for inverse design purposes (why AD instead of FD for inverse design?). Naively, to me it seems like having an exact derivative should be more important when propagating Maxwell’s equations than when taking the derivative of an objective function.

One Answer

Given code that computes a function $f(x)$, automatic differentiation tools produce a code that can compute $f(x)$ and its derivatives at the same time. Solving a differential equation is an entirely different problem and AD doesn't solve differential equations (although AD tools are sometimes useful in connection with PDE constrained optimization.)

AD tools are quite good at computing derivatives and should be used more often. However, there are circumstances where they simply can't be used. The most common reason that AD can't be used is that the code you have is a "black-box" for which source code is not available. Some other codes are so large and complicated that AD tools simply fail to handle them.

Correct answer by Brian Borchers on April 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP