
Raddy
An automatic differentiation system for geometry and simulation.
An attempt to port some portion of TinyAD to Rust.
Usage
First add to your Cargo.toml:
= "*"
Scalars
use var;
use ;
Vectors
use ;
use ;
use ;
Sparse
- First define your per-element (per-stencil) objective:
// 2d * 2nodes = 4dof
- Then, define your elements (indices). Here is an example where each element is DOFs of two nodes on each neo-hookean spring:
let springs = vec!;
let x0 = from_slice.to_owned;
let obj = SpringEnergy ;
- Finally, compute:
let computed: = obj.compute;
/*
pub struct ComputedObjective<const N: usize> {
pub value: f64,
pub grad: Col<f64>,
pub hess_trips: Vec<(usize, usize, f64)>,
}
*/
Please see src/examples and src/test for details.
Notes
Copyis not implemented forAd<N>types, since its cost is not negligible.
- This reminds you to (in most cases) use a borrow type
&Ad<N>to call methods on&Ad<N>; or to explicitly clone it if the cost is acceptable.
Progress
- Univariate
- Gradient
- Hessian
- Tests
- Multivariate
- Gradient
- Hessian
- Tests
- Norm
- Determinant
- Matmul
- Get nalgebra as well as compiler happy
- Implement
ComplexFieldfor&Ad<N>(NotAd<N>) (a huge task that may involve codegen/metaprogramming...) - Incrementally implement the trait in
ComplexFieldif some methods need them
- Implement
- Sparse interface
- Define sparse problem (generic on problem size)
- Compute sparse problem
- Test
- Mass spring: grad/hess
- Mass spring: results
- Neo Hookean
- Make an example: mass-spring system
- An option to allocate hessian on heap
-
f64&ScalarInterop (How to? Seems sort of impossible due to orphan rule) (We use the same sort of workaround asfaer)
Notes For Myself
- Test code makes use of Symars, which generates Rust code from SymPy expressions.
- When getting numerical bugs, First check the argument order of symars generated functions!!!