Expand description
Differentiation utilities for phyz: Jacobians of the equations of motion.
Three routines compute the same object — the Jacobians of one semi-implicit Euler step — by different means, trading accuracy against cost:
| 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 (ABA block is FD) |
symbolic::symbolic_step_jacobians | symbolic differentiation of the dynamics | yes |
Only the symbolic path is derivative-exact. The other two are finite
differences and inherit the usual step-size/round-off tradeoff. For exact
parameter and contact-surface gradients over a whole trajectory, see the
dual-number adjoint in phyz::diff instead.
§Example
use phyz_diff::semi_implicit_step_jacobians;
use phyz_math::{GRAVITY, Mat3, SpatialInertia, SpatialTransform, Vec3};
use phyz_model::ModelBuilder;
let model = ModelBuilder::new()
.gravity(Vec3::new(0.0, -GRAVITY, 0.0))
.dt(0.002)
.add_revolute_body(
"pendulum",
-1,
SpatialTransform::identity(),
SpatialInertia::new(
1.0,
Vec3::new(0.0, -0.5, 0.0),
Mat3::from_diagonal(&Vec3::new(0.083, 0.0, 0.083)),
),
)
.build();
let mut state = model.default_state();
state.q[0] = 0.3;
let jac = semi_implicit_step_jacobians(&model, &state);
assert_eq!(jac.dvnext_dq.nrows(), model.nv);Re-exports§
pub use rollout::AdjointGradients;pub use rollout::AdjointRollout;pub use rollout::CollisionMesh;pub use rollout::ContactSetup;pub use rollout::FinalStateObjective;pub use rollout::GroundContact;pub use rollout::N_INERTIA_PARAMS;pub use rollout::adjoint_rollout_gradient;pub use rollout::inertia_params;pub use rollout::rollout_objective;pub use contact_adjoint::ConvexAdjointError;pub use contact_adjoint::ConvexAdjointGradients;pub use contact_adjoint::ConvexContactRollout;pub use contact_adjoint::convex_adjoint_gradient;pub use contact_adjoint::convex_rollout_objective;
Modules§
- contact_
adjoint - Trajectory adjoint through the convex contact solve — the same contact model the forward simulator runs.
- multidual
- Vector-mode forward AD: one pass through the dynamics,
Nderivatives out. - rollout
- Differentiable rollouts: exact parameter and contact-surface adjoints.
- symbolic
- Symbolic Jacobian computation via tang-expr.
Structs§
- Step
Jacobians - Jacobians of a single simulation step.
Functions§
- analytical_
step_ jacobians Deprecated - Deprecated alias for
semi_implicit_step_jacobians. - finite_
diff_ jacobians - Compute step Jacobians via finite differences.
- semi_
implicit_ step_ jacobians - Compute step Jacobians for semi-implicit Euler by chain rule through the integrator.