Expand description
§echidna
A high-performance automatic differentiation (AD) library for Rust.
echidna provides forward-mode, reverse-mode, bytecode-graph-mode, and Taylor-mode automatic differentiation. Write standard Rust numeric code and get exact derivatives automatically – no symbolic rewriting, no numerical finite differences.
§Examples
Compute the gradient of f(x, y) = x^2 + y^2:
let g = echidna::grad(|x: &[echidna::Reverse<f64>]| {
x[0] * x[0] + x[1] * x[1]
}, &[3.0, 4.0]);
assert!((g[0] - 6.0).abs() < 1e-10);
assert!((g[1] - 8.0).abs() < 1e-10);Forward-mode with Dual<f64>:
use echidna::{Dual, Float};
let x = Dual::new(2.0_f64, 1.0); // seed derivative = 1
let y = x.sin() + x * x;
assert!((y.eps - (2.0_f64.cos() + 4.0)).abs() < 1e-10);§AD Modes
| Mode | Type | Best for | Description |
|---|---|---|---|
| Forward | Dual<F> | Few inputs, many outputs | Propagates tangent vectors (JVP) |
| Reverse | Reverse<F> | Many inputs, few outputs | Adept-style two-stack tape, Copy, 12 bytes for f64 |
| Bytecode tape | BytecodeTape + BReverse<F> | Record-once evaluate-many | Graph mode enabling Hessians, sparse derivatives, GPU acceleration, checkpointing. Requires bytecode feature. |
| Taylor | Taylor<F, K> | Higher-order derivatives | Univariate Taylor propagation. Requires taylor feature. |
| Batched forward | DualVec<F, N> | Vectorised Jacobians/Hessians | N tangent directions simultaneously |
§Feature Flags
| Feature | Default | Description |
|---|---|---|
simba | yes | simba / approx trait integration |
bytecode | no | BytecodeTape graph-mode AD |
parallel | no | Rayon parallel evaluation (implies bytecode) |
taylor | no | Taylor-mode AD (Taylor<F, K>, TaylorDyn<F>) |
laurent | no | Laurent series for singularity analysis (implies taylor) |
stde | no | Stochastic Taylor Derivative Estimators (implies bytecode + taylor) |
diffop | no | Arbitrary differential operator evaluation via jet coefficients (implies bytecode + taylor) |
serde | no | Serialization support via serde |
faer | no | faer linear algebra integration (implies bytecode) |
nalgebra | no | nalgebra linear algebra integration (implies bytecode) |
ndarray | no | ndarray integration (implies bytecode) |
gpu-wgpu | no | GPU acceleration via wgpu (implies bytecode) |
gpu-cuda | no | GPU acceleration via CUDA (implies bytecode) |
§Core Types
Always available:
Dual<F>– forward-mode dual numberReverse<F>– reverse-mode AD variableDualVec<F, N>– batched forward-mode (N tangent directions)Scalar– trait for writing AD-generic codeFloat– trait for underlying floating-point types- Type aliases:
Dual64,Dual32,DualVec64,DualVec32,Reverse64,Reverse32
With bytecode:
BytecodeTape– recorded computation graphBReverse<F>– reverse-mode variable for bytecode evaluationCustomOp/CustomOpHandle– user-defined tape operations- Type aliases:
BReverse64,BReverse32
With taylor:
Taylor<F, K>– fixed-order Taylor coefficientsTaylorDyn<F>– dynamic-order Taylor coefficients- Type aliases:
Taylor64,Taylor32,TaylorDyn64,TaylorDyn32
With laurent:
Laurent<F, K>– Laurent series with negative-order terms
§Getting Started
- Gradients: use
grad()– it manages the reverse-mode tape automatically. - Jacobians: use
jacobian()(forward mode) orsparse_jacobian()(sparse, requiresbytecode). - Hessians: use
hessian()orsparse_hessian()(requiresbytecode). - AD-generic code: write functions as
fn foo<T: Scalar>(x: T) -> Tand they work with any AD type. - Tape reuse (performance): use
record()to build aBytecodeTape, then call methods on it for repeated evaluation (requiresbytecode).
Re-exports§
pub use api::grad;pub use api::jacobian;pub use api::jvp;pub use api::vjp;pub use dual::Dual;pub use dual_vec::DualVec;pub use float::Float;pub use reverse::Reverse;pub use scalar::Scalar;pub use api::composed_hvp;bytecodepub use api::hessian;bytecodepub use api::hessian_vec;bytecodepub use api::hvp;bytecodepub use api::record;bytecodepub use api::record_multi;bytecodepub use api::sparse_hessian;bytecodepub use api::sparse_hessian_vec;bytecodepub use api::sparse_jacobian;bytecodepub use breverse::BReverse;bytecodepub use bytecode_tape::BytecodeTape;bytecodepub use bytecode_tape::CustomOp;bytecodepub use bytecode_tape::CustomOpHandle;bytecodepub use checkpoint::grad_checkpointed;bytecodepub use checkpoint::grad_checkpointed_disk;bytecodepub use checkpoint::grad_checkpointed_online;bytecodepub use checkpoint::grad_checkpointed_with_hints;bytecodepub use nonsmooth::ClarkeError;bytecodepub use nonsmooth::KinkEntry;bytecodepub use nonsmooth::NonsmoothInfo;bytecodepub use sparse::CsrPattern;bytecodepub use sparse::JacobianSparsityPattern;bytecodepub use sparse::SparsityPattern;bytecodepub use laurent::Laurent;laurentpub use taylor::Taylor;taylorpub use taylor_dyn::TaylorArena;taylorpub use taylor_dyn::TaylorDyn;taylorpub use taylor_dyn::TaylorDynGuard;taylor
Modules§
- api
- Closure-based API for automatic differentiation.
- breverse
bytecode - Bytecode-tape reverse-mode AD variable.
- bytecode_
tape bytecode - Bytecode tape for re-evaluable reverse-mode AD.
- checkpoint
bytecode - Compositional gradient checkpointing for iterative computations.
- cross_
country bytecode - Cross-country elimination for Jacobian computation.
- diffop
diffop - Arbitrary differential operator evaluation via jet coefficients.
- dual
- Forward-mode dual numbers for automatic differentiation.
- dual_
vec - Batched forward-mode dual numbers with
Ntangent lanes. - faer_
support faer - faer adapters for echidna’s bytecode tape AD.
- float
- The
Floattrait marking raw floating-point types usable as AD bases. - gpu
gpu-wgpuorgpu-cuda - GPU acceleration for batched tape evaluation.
- laurent
laurent - Const-generic Laurent coefficient type:
Laurent<F, K>. - nalgebra_
support nalgebra - nalgebra adapters for echidna’s bytecode tape AD.
- ndarray_
support ndarray - ndarray adapters for echidna’s bytecode tape AD.
- nonsmooth
bytecode - Nonsmooth extensions: branch tracking, kink detection, and Clarke subdifferential.
- opcode
bytecode - Bytecode opcodes for the bytecode tape.
- reverse
- Reverse-mode automatic differentiation via an Adept-style tape.
- scalar
- The
Scalartrait for writing AD-generic numeric code. - sparse
bytecode - Sparse derivative computation via structural sparsity detection and graph coloring.
- stde
stde - Stochastic Taylor Derivative Estimators (STDE).
- tape
- Adept-style two-stack tape for reverse-mode AD.
- taylor
taylor - Const-generic Taylor coefficient type:
Taylor<F, K>. - taylor_
dyn taylor - Dynamic (arena-based) Taylor coefficient type:
TaylorDyn<F>. - taylor_
ops taylor - Shared Taylor coefficient propagation functions.
Type Aliases§
- BReverse32
bytecode - Type alias for bytecode-tape reverse-mode variables over
f32. - BReverse64
bytecode - Type alias for bytecode-tape reverse-mode variables over
f64. - Dual32
- Type alias for forward-mode dual numbers over
f32. - Dual64
- Type alias for forward-mode dual numbers over
f64. - Dual
Vec32 - Type alias for batched forward-mode dual numbers over
f32. - Dual
Vec64 - Type alias for batched forward-mode dual numbers over
f64. - Reverse32
- Type alias for reverse-mode variables over
f32. - Reverse64
- Type alias for reverse-mode variables over
f64. - Taylor32
taylor - Type alias for Taylor coefficients over
f32with K coefficients. - Taylor64
taylor - Type alias for Taylor coefficients over
f64with K coefficients. - Taylor
Dyn32 taylor - Type alias for dynamic Taylor coefficients over
f32. - Taylor
Dyn64 taylor - Type alias for dynamic Taylor coefficients over
f64.