pynucastro.autodiff.derivative_pair module

pynucastro.autodiff.derivative_pair module#

Two independent forward-mode derivative components, stored without arrays.

A DerivativePair is the derivative payload of a Dual, not a value/derivative pair itself. For independent variables x and y, seed x with Dual(x, DerivativePair(1.0, 0.0)) and y with Dual(y, DerivativePair(0.0, 1.0)). The result’s deriv.d1 and deriv.d2 then hold derivatives with respect to x and y. Dual implements the chain and product rules; this class adds, subtracts, and scales their derivative components independently.

The arithmetic is written twice to support Python and Numba. Python uses the class’s special methods (such as __add__). Numba represents instances as native namedtuples and needs explicit @overload registrations for these operations instead of relying on the Python methods. Functions prefixed with _ol_ receive Numba argument types during compilation and return an implementation that operates on values at runtime. They are not called by users. Keep their formulas consistent with the Python methods.

class pynucastro.autodiff.derivative_pair.DerivativePair(d1, d2)[source]#

Store derivatives with respect to two independent variables.

Parameters:
  • d1 (float) – Derivative with respect to the first variable.

  • d2 (float) – Derivative with respect to the second variable.

pynucastro.autodiff.derivative_pair.zero_derivative(deriv)[source]#

Return a zero seed of the same kind as deriv.