Differentiable parameter bindings
The scene owns a flat physical parameter vector P.
Before world.init(scene), attach an integer attribute named diff/<name>
beside the floating-point <name> attribute it controls. Each nonnegative
entry is a zero-based index into P. Initialization broadcasts that physical
value into the corresponding component. Use -1 for a component that keeps
its ordinary scene value. The physical parameter count, attribute sizes and
index assignments stay fixed for the lifetime of the initialized world.
For end-to-end examples, see the PyTorch tutorial
and the native features guide.
For example, a vertex's diff/velocity = [-1, 0, -1] binds its initial
y velocity to P[0]. Giving another vertex the same index shares the
physical velocity and adds both vertices' contributions to its gradient.
For independently optimized velocities assign distinct indices. Use a scalar
integer for a scalar attribute, a three-entry integer vector for a 3-vector,
and an integer matrix of the same shape for a matrix attribute. These indices
address physical inputs. The integer indices returned by a frame's DoF
selector address simulation outputs in a separate coordinate system.
Supported inputs
The native adjoint needs a derivative implementation for the selected field
and constitution. The table lists the parameter families covered by the
CUDA trajectory tests. Adding a matching diff/ attribute establishes a
value binding. Derivative support also depends on the model, the attribute
collection (such as vertices or edges), and whether the field belongs to the
current or rest geometry.
When differentiable simulation is enabled, CUDA rejects a selected
unsupported binding during world.init(scene). The error names the
diff/ attribute and its location. For example, a selected
diff/thickness now raises an error rather than returning zero. A
well-formed binding with all indices set to -1 selects nothing. An
identical index row copied from the current geometry to the rest geometry,
or vice versa, is allowed when one side has the intended derivative.
An explicitly selected rest vertex position is always checked as a
reference-geometry input, even if it shares the current-position binding.
Each distinct selected field must be supported even if several fields share
one physical parameter index. A supported binding may still return zero
when the selected output is insensitive to it.
| Quantity | Attribute collection and binding | Interpretation |
|---|---|---|
| FEM initial position | Current vertices, diff/position (3) |
Input vertex coordinates. The mesh transform maps them to the initial world-space position. Select free motion components. |
| Explicit FEM vertex mass | Current vertices, diff/mass |
Bind the explicit mass attribute. Selected values must be finite and positive. A fixed physical force contributes acceleration inversely proportional to mass; gravity alone gives no mass gradient for free motion. |
| Initial velocity | Current FEM vertices, diff/velocity (3), or current affine body instances, diff/velocity (4 × 4) |
In the affine matrix, entries [0:3, 3] control translational velocity and the upper-left block controls the affine velocity. Keep the bottom row unselected. |
| Affine body initial pose | Current instances, diff/transform (4 × 4) |
Select entries of the first three rows of a free body's transform. Translation is in column 3. |
| Rest shape | Rest vertices, diff/position (3) |
Reference coordinates for SNK1 and ARAP tetrahedra, supported membranes and elastic shell hinges, Hookean line meshes with optional Kirchhoff bending, and closed affine-body volume boundaries. These enter rest geometry and derived quantities such as mass. |
| Tetrahedral material | Current tetrahedra, diff/lambda, diff/mu, or diff/kappa |
Native StableNeoHookean uses finite Lamé coefficients with \(\lambda>0\) and \(\mu\geq0\). FEM ARAP uses finite nonnegative kappa. |
| Membrane material | Current triangles, diff/lambda, diff/mu |
LinearElasticShell and NeoHookeanShell. Require finite coefficients with \(\mu>0\) and \(\lambda+\mu>0\). |
| Directional cloth material | Current triangles, diff/lambda, diff/mu, diff/stretch_stiffness_b, diff/strain_rate |
For StrainLimitingBaraffWitkinShell, these are first-direction stretch, shear, optional second-direction stretch, and cubic strain-extension coefficient. Values are finite and nonnegative. Without a separate stretch_stiffness_b value, both stretch directions use lambda. |
| Bending stiffness | Current edges, diff/bending_stiffness |
Stiffness used by DiscreteShellBending. |
| Plastic shell hinges | Current edges, diff/bending_stiffness, diff/bending_hardening_modulus, and diff/bending_yield_threshold (strain) or diff/bending_yield_stress (stress) |
The yield binding sets the initial value. The adjoint differentiates the plastic angle and yield state across frames, including dependence on supported membrane rest geometry. |
| Line elasticity | Current edges, diff/kappa |
HookeanSpring axial stiffness. |
| Rod bending stiffness | Current vertices, diff/bending_stiffness |
KirchhoffRodBending stiffness at the middle vertex of a bending stencil. |
| Affine shape stiffness | Current instances, diff/kappa |
The shape-energy coefficient of OrthoPotential and affine ARAP. This is not a contact stiffness. |
| Contact coefficients | scene.contact_tabular().contact_models(), diff/friction_rate, diff/resistance |
Scalar indices per contact-model row. Resistance acts through the forward stiffness clamp described below. |
| Joint targets and efforts | Joint geometry edges, diff/aim_angle, diff/external_torque (revolute), diff/aim_distance, diff/external_force (prismatic) |
Bind the value supplied by the corresponding driving or effort constitution. The joint's activation and passive-control settings still apply. |
| Joint strengths | Fixed/spherical joint vertices or revolute/prismatic joint edges, diff/strength_ratio; revolute/prismatic edges also accept diff/driving/strength_ratio and diff/limit/strength |
Differentiate the native attachment, driving, or limit energy. Limit gradients use the recorded angle branch and the active part of the limit penalty. |
| Joint interval bounds | Revolute/prismatic joint edges, diff/limit/lower, diff/limit/upper |
Bind the authored angle or distance bounds. The shifted interval must have finite positive width. Changing either endpoint changes the penalty's width, including on the opposite active side. The joint anchors and axes are not design inputs here. |
| Affine soft transform | Current instances, diff/aim_transform (4 × 4), diff/strength_ratio (2) |
Optimize target transform entries in the first three rows, or the translation and linear-motion strengths of an active SoftTransformConstraint. Frame overrides apply only to the target transform. |
| FEM soft position | Current vertices, diff/aim_position (3), diff/strength_ratio |
World-space target and dimensionless strength of SoftPositionConstraint. |
| Applied load | Current FEM vertices, diff/external_force (3), or affine instances, diff/external_force (12) |
Per-vertex forces or generalized affine body loads. The first three affine entries are translation forces. Only active loads contribute in each frame. |
Current and rest positions have different effects. To vary an initial
FEM position while keeping its reference shape fixed, copy the rest geometry
before adding diff/position to the current mesh and register both with
object.geometries().create(mesh, rest). To vary reference shape only, put
the binding on the rest mesh. To move both with one physical input, bind
the intended component on each mesh to the same index. A rest coordinate
may be differentiable on a fixed support. A current-position binding must
respect fixed vertices and world-axis fixed_dofs, including the direction
induced by the mesh transform.
With a FEM SoftPositionConstraint, a rest-shape change affects both the
inertial force and the mass-scaled position constraint when vertex masses
are derived from rest area or volume. An explicit vertex mass is constant
under the same rest-shape change.
For prescribed FEM soft-position animation, the backward solve uses each
frame's active vertices, target positions and strengths. Load and soft-target
callbacks may prescribe the active set or unbound values. Do not overwrite
the values sourced from P inside a callback; the callback itself is not
differentiated.
Keep reference elements nondegenerate and preserve topology. Affine rest shape uses a closed oriented triangle boundary with valid volume and mass. The supported model set covers the indicated fields. Rest-shape derivatives include edge-length-dependent mass for line elements unless masses are prescribed. The Kirchhoff forward energy uses the adjacent rest lengths, not a rest turning angle. Rest-shape optimization of affine open shells and affine rods, direct density or thickness bindings, differentiation through topology changes, and higher-order autograd fall outside the scope of these bindings.
Plastic hinge gradients follow the elastic or yielded branch used in the recorded trajectory. A derivative at a yield switch, angle unwrap switch, or degenerate hinge is not covered. Compare perturbed trajectories on a consistent branch when validating these inputs.
Frame-specific controls
For an active joint input or affine position target, use <name>/frame/<t>
to override the base value at frame \(t\), starting at 1. Create the matching
diff/<name>/frame/<t> integer attribute to optimize that override. For
example, aim_angle/frame/2 with diff/aim_angle/frame/2 = 3 selects
P[3] at frame 2. An override without an index is constant. Frames without
an override use the base control and its binding. Reuse an index across
frames to optimize one shared control.
Conditions for a meaningful gradient
- Use the CUDA backend, a fixed positive time step and a fixed DoF layout.
Backward requires the BDF1 predictor. With BDF1,
is_dynamic = 0resets velocity carryover while retaining the incremental inertial term. BDF2 supports forward simulation. A BDF2 backward request raises an exception because the adjoint requires terms from two previous steps. Use standard IPC for differentiable contact. The backend rejects AL-IPC multiplier-history differentiation. - With contact enabled, specify finite nonnegative resistance. Hold the effective contact stiffness fixed within each trajectory. A new forward can optimize a resistance input between trajectories. For that input, the derivative through the clamp is active inside its open interval and zero outside or exactly at its endpoints. Select an explicit default contact model to differentiate the default row's resistance.
- Contact groups without an explicit pair use the current default coefficients. If vertices of one edge or triangle use different contact groups, the forward coefficient is the arithmetic mean over the vertex pairs. Its gradient is divided among those pairs with the same weights. Contributions bound to the same parameter index add together.
- A half-plane normal denotes a direction, not a distance scale. Supply a finite, nonzero vector. The contact and friction-history calculations use a unit normal.
- Record every step from frame zero and check that each frame converges. Backward validates the recomputed residual for each frame adjoint. Its iteration budget and numerical tolerance are independent of the forward Newton tolerance. See differentiable solver settings.
- A contact appearing, disappearing or changing closest features can change the local derivative. To check a direction \(v\), run the same simulation from frame zero at \(U+hv\) and \(U-hv\), then compare \([L(U+hv)-L(U-hv)]/(2h)\) with \(\nabla_U L\cdot v\). Try multiple step sizes at a feasible design where both rollouts converge and stay on the same contact branch. For a nonlinear physical map, perturb the same design variables whose PyTorch gradients you are checking.