Skip to content

XAD High-Performance Automatic Differentiation for Python and C++

XAD is a comprehensive open-source library for automatic differentiation for Python and C++, targeting production code at any scale.

Latest Release: v1.6.0
x0 = Real(1.3)
x1 = Real(5.2)
tape.registerInput(x0) 
tape.registerInput(x1)
tape.newRecording() 
y = func(x0, x1)
tape.registerOutput(y)
y.derivative = 1.0
tape.computeAdjoints();
print(f"dy/dx0={x0.derivative}")
print(f"dy/dx1={x1.derivative}")
Adouble x0 = 1.3;
Adouble x1 = 5.2;  
tape.registerInput(x0); 
tape.registerInput(x1);
tape.newRecording(); 
Adouble y = func(x0, x1);
tape.registerOutput(y);
derivative(y) = 1.0;
tape.computeAdjoints();
cout << "dy/dx0=" << derivative(x0) << "\n"
     << "dy/dx1=" << derivative(x1) << "\n";

Automatic Differentiation

Automatic differentiation (also called algorithmic differentiation) is a set of techniques for calculating partial derivatives of functions specified as computer programs. Since every program execution is always composed of a sequence of simple operations with known derivatives (arithmetics and mathematical functions like sin, exp, log, etc.), the chain rule can be applied repeatedly to calculate partial derivatives automatically. See automatic differentation mathematical background for more details.

Application areas

  • Machine Learning and Deep Learning: Training neural networks or other machine learning models.
  • Optimisation: Solving optimisation problems in engineering and finance.
  • Numerical Analysis: Enhancing numerical solution methods for differential equations.
  • Scientific Computing: Simulating physical systems and processes.
  • Risk Management and Quantitative Finance: Assessing and hedging risk in financial models.
  • Computer Graphics: Optimising rendering algorithms.
  • Robotics: Improving control and simulation of robotic systems.
  • Meteorology: Enhancing weather prediction models.
  • Biotechnology: Modeling biological processes and systems.

Key Features

Any Order, Mode, Precision

Calculate derivatives in forward and adjoint modes, for any order – both in single and double precision.

Production-Ready

Battle-tested in large-scale production code-bases, over 98% test coverage, and supporting a wide range of math functions.

Blindingly Fast

Optimised for maximum performance, e.g. via expression templates and efficient taping.

Checkpointing

Manage tape memory and achieve higher performance via checkpointing.

External Functions

Integrate functions from external libraries into the AD tape or manually optimise parts of the differentiated code.
image/svg+xml

Thread-safe tape

Safely use multiple tapes from multiple threads in parallel code.