Skip to main content

Module nl_tape

Module nl_tape 

Source
Expand description

Flat-tape reverse-mode AD for .nl expression trees.

Replaces the FD-based Hessian path with a port of the tape AD used in ripopt::nl::autodiff. The tape is a Vec<TapeOp> where each op refers to its operands by tape-slot index; forward evaluation runs through the slice once filling a parallel Vec<f64> of values, and reverse-mode adjoints walk the same buffer backwards.

Sparse Hessians are computed by forward-over-reverse: for each variable j that the tape depends on, run a forward tangent sweep seeded with e_j, then a second-order reverse sweep that produces column j of the Hessian. The caller supplies a (row, col) -> nnz position map (lower triangle, row >= col), and contributions are accumulated in place — the outer loop in eval_h calls the same map for the objective and every active constraint, so every Lagrangian term lands in the right slot.

Common subexpressions are tape-emitted once: when the recursive builder hits Expr::Cse(rc) it keys on the Rc pointer identity, emitting the body the first time and returning the cached result-slot index on subsequent references. The forward pass then computes each CSE once and the reverse pass folds adjoints from every reference into a single slot — exact chain-rule behaviour.

Structs§

HybridTape
Summand
Tape
A flattened expression tape. The result of evaluation is the value at slot ops.len() - 1 (i.e. the last op).

Enums§

SummandOp
One slot in a per-summand local tape.
TapeOp
One operation in the flattened tape. Operand fields are tape-slot indices into the same tape; Var(i) references problem variable index i (read from the input x slice during forward).