class pyADiff.adjoint.ADTypeA(value, record, dependencies=[], derivative=0.0)

Adjoint ADType.

This class overloads the basic numerical type of python. Instead of only an value it also stores a derivative, its dependencies and a record.

This class implements the numerical operators (+, -, .. ) as expected for a numerical type, but additionaly stores the operands (dependencies) and records the operation to the record.

Basic mathematical functions (sin, cos, exp, …) are implemented as member functions and also store the operand in the return ADTypeA and record the operation.

  • value (float or ADType) – The value of the overloaded numerical type.
  • record (ADRecord) – The record of all operations.
  • dependencies (list[tuple(ADTypeA, float or ADType)]) – List of the ADTypeAs this ADTypeA depends on and their partial derivatives.
  • deriative (float or ADType) – The derivative of the overloaded numerical type.

See also

Records all operations.
Implementation of basic mathematical functions for the ADType.


Calculates and accumulates the partial derivatives of its dependencies.


Dependencies of the ADTypeA

List of tuples(ADTypeA, float or ADType) which represent the dependencies of this ADTypeA.


Derivative of the overloaded numerical type.


Value of the overloaded numerical type.

class pyADiff.adjoint.ADRecord


Stores all operations of a computation in a list, preserving their order.

See also

The overloaded adjoint numerical type.


Backpropagates through all stored computations in reversed order.


Adds a variable to the record.

Parameters:v (ADTypeA) – Variable to record.

Resets the derivatives.

Resets the derivatives of all values to 0.

pyADiff.adjoint.dfdx(f, x_v)

Adjoint Differentiation Driver.

This computes the derivative of f with respect to x at the position x_v. The signature of f is assumed to be:

{scalar, list, array} = f({scalar, list, array})

This function converts the inputs x_v to their respective ADTypeA, runs the function f and simultaneously creates the record of all operations. Then it successively sets the derivtive of the outputs y=f(x) to one and backpropgates through the record. Then the derivative value can be collected from the inputs x.

Only one forward run of f is necessary, no matter the dimension of x. The backpropagation is performed once for each output y.

  • f (function_type) – The function to differentiate.
  • x_v (scalar, list, array) – The value where to evaluate the derivative.

See also

Wrapper for the comutation of the derivative via adjoint mode.