phyz-diff
Per-step Jacobians of the phyz equations of motion.
Three routines compute the same object — the Jacobians of one semi-implicit Euler step — by different means:
| Function | Method | Exact? |
|---|---|---|
finite_diff_jacobians |
central differences over the whole step | no |
semi_implicit_step_jacobians |
chain rule through the integrator, central differences on ABA | no |
symbolic::symbolic_step_jacobians |
symbolic differentiation of the dynamics | yes |
Only the symbolic path is derivative-exact. The other two are finite differences and carry the usual step-size versus round-off tradeoff.
analytical_step_jacobianswas a misnomer — its ABA block has always been finite differences. It is deprecated in favour ofsemi_implicit_step_jacobians.
For exact gradients of a whole trajectory with respect to inertia
parameters and contact-surface geometry, use the dual-number adjoint in
phyz's diff module instead.
Example
use ;
use ;
use ModelBuilder;
let model = new
.gravity
.dt
.add_revolute_body
.build;
let mut state = model.default_state;
state.q = 0.3;
let jac = semi_implicit_step_jacobians;
let fd = finite_diff_jacobians;
// dq'/dq, dq'/dv, dv'/dq, dv'/dv, dv'/dctrl
assert_eq!;
The rollout module lifts these to multi-step trajectories.
Part of phyz
phyz is an open-source differentiable
multi-physics simulation workspace in pure Rust. Each crate is independent —
adding this one does not pull in the rest.
Licensed under MIT.