Simulation Tuning#
Physics tuning is a process of reducing one failure mode at a time. Start with the smallest scene that reproduces the issue, verify the model scale and mass properties, then follow the order appropriate to the diagnosed symptom.
This page is intentionally operational: it is written as a checklist for humans and agents. Parameter names are Newton parameter names unless explicitly marked as external references.
Important
Rely on this guide for the durable reasoning — the constraint model, the “diagnose before tuning” workflow, and the principle that harder is not always more stable. For specifics — default values, enum and mode names, which knobs a solver exposes, APIs, and exact behavior — the code is the source of truth. These evolve with the codebase, so verify the ones you rely on against the cited source (and the solver’s own constructor or config) before acting.
Diagnose Before Tuning#
Before changing any parameter, classify the problem. Most “soft contact” symptoms are not contact problems:
Initialization / geometry: initial penetration, collision-vs-visual mesh mismatch, wrong joint state.
Control: a bad controller or IK target, step changes in drive targets.
Model: bad mass or effective inertia; a missing drive import; or missing friction, damping, and reflected actuator inertia where physically expected.
Capacity: too few contact or constraint rows for the scene.
Contact / solver: only after the above are ruled out.
Three principles guide every change:
Rule out non-contact issues before tuning contact. Do not hide a model or control problem by raising contact stiffness.
Tune physical parameters before solver options. Solver iterations, line-search iterations, and tolerances affect convergence; they are not a substitute for correct geometry, mass, drives, and contact parameters.
Harder is not always more stable. A harder contact (smaller penetration, closer to a hard constraint) can be less stable: excessive stiffness, high plateau impedance, or too large a timestep cause jitter, energy injection, or poor solver conditioning. Tune to task metrics, not to a single penetration number.
Tuning Order#
For contact-dominated rigid-body and articulation problems, use this order:
Simplify the scene. Test the robot, mechanism, gripper, or object in isolation before tuning the full environment.
Validate the model. Check SI units, shape dimensions, mass, inertia, joint axes, joint limits, and unintended self-collisions. Inspect collision geometry and contact normals with the viewer debugging tools rather than assuming collision geometry matches visual geometry.
Choose the contact representation. Prefer primitives for speed. Use SDF or hydroelastic contacts when contact patch quality, force distribution, or non-convex geometry matters.
Set the timestep. Reduce the simulation
dtor increase substeps before raising stiffness. A smallerdtis usually the most reliable stability improvement, but it is also expensive.Tune solver convergence. If the selected solver exposes iterations or tolerances, increase them in a bounded sweep (for example, double the iterations) and stop when an increase reduces the constraint residual by less than a small margin you set in advance (a few percent); further iterations then cost runtime without meaningful accuracy.
Tune contacts. Adjust stiffness, damping, friction, contact margins, gaps, contact count, and collision refresh cadence.
Tune joints and drives. Use realistic drive stiffness and damping. Add target rate limits in control code. Use supported model features such as effort limits, armature, or joint friction only where the selected solver supports them.
Optimize performance last. Reduce collision frequency, contact count, solver iterations, or substeps only after the behavior is acceptable. See Performance.
Do not hide model errors with extreme solver settings. Bad mass ratios, incorrect inertia tensors, overlapping collision geometry, and over-stiff drives usually remain unstable even with more iterations.
For symptoms that classify as Control or Model under “Diagnose Before Tuning” above, resolve that category before contacts: steps 6–7 list contacts before joints and drives only because that order suits contact-dominated symptoms. For drive- or controller-dominated symptoms (such as poor tracking or oscillation), tune joints and drives first and consult the Symptom Table.
Accept a parameter change only when the target task metric improves and no guardrail regresses past a bound set in advance — NaN/Inf count, maximum penetration or constraint residual, and runtime. Record those baselines before the first change. Change one knob at a time when attributing an effect; when the failure evidence points to an interaction, test the smallest justified combination in a scripted reproduction and keep it only if the target metric and guardrails improve.
Tunneling and Adaptive Collision Detection#
If fast objects pass through thin geometry, first reduce the solver timestep and refresh collisions every substep. Increasing solver iterations cannot recover a collision that was never detected. Once this baseline works, consider speculative contacts with conditional collision refreshes as a practical alternative to full continuous collision detection (CCD) for rigid contacts.
Newton can keep possible contacts between nearby objects before they touch.
The experimental CollisionSubstepScheduler reuses this information for
several solver steps, checking again as the objects move. This can reduce
collision-detection work for sufficiently stable motion while keeping the
solver timestep small. Falling and thrown objects under gravity can require
collision checks every substep because their velocities keep changing.
Tune these three controls together:
substeps: how many solver steps run per frame. Increase this to resolve faster motion and abrupt acceleration.CollisionPipeline(speculative_contact_gap_max=...): how far ahead to look, in meters. A larger positive distance can allow longer intervals between collision checks, but can also create more contacts.collision_dt_max: the longest allowed time between collision checks. Lower this cap if contacts need more frequent updates.
Velocity-adapted detection keeps possible contacts that current motion
could close before the next check, up to the configured distance limit. Supply
that time as pipeline.collide(..., dt=collision_dt). Scheduled checks preserve
this velocity-guided extension. After a collidable shape changes linear or
angular velocity, the scheduler refreshes contacts with a one-substep prediction
horizon. Rotating shapes also require one-substep horizons because their
witness approach directions change even at constant angular velocity.
Gravity and impacts can therefore require a check every substep.
Monitor interval_overflow for travel beyond the configured distance limit,
and use enough substeps for abrupt motion: forces and impulses within a substep
can invalidate the velocity forecast before the scheduler observes them.
See Speculative contacts (velocity-adapted gaps) for callback setup, CUDA graph requirements,
refresh rules, and supported geometry.
Choose a solver that uses these contacts:
XPBD checks retained contacts after predicting body positions; no extra speculative-response option is needed.
MuJoCo Warp requires
use_mujoco_contacts=Falseand the experimentaluse_speculative_contacts=Truewith Euler or implicitfast integration. See MuJoCo Solver for response and capacity requirements.Steel supports separated contacts by default.
contact_speculative_scalecontrols how much of the gap may close per step;contact_gap_gatecan discard farther contacts. SeeSolverSteel.Kamino LOX keeps separated contacts by default; other Kamino modes cull them by default. See Kamino and
config.dynamics.cull_speculative_contacts.
Measure total runtime as well as collision-check counts at the fastest expected
motion. Fast scenes may still check every substep and incur scheduling overhead;
larger distances can increase contact-buffer and solver costs. Read
schedule.interval_overflow.numpy()[0] occasionally after a frame, outside
CUDA graph capture; this synchronizes CUDA. If set, increase substeps or the
speculative distance limit. Keep penetration and contact/constraint capacity
within the task’s bounds.
This remains a tunneling mitigation, not full CCD. It does not compute a time of impact, and abrupt motion within one substep can still cross thin geometry. Choose the solver timestep accordingly; see Speculative contacts (velocity-adapted gaps) for the full limitations.
Solver and Backend Changes#
Treat a solver or backend change as a model port, not a gain-tuning exercise. Before retuning, audit the Joint Feature Support table and current implementation for the limits, drives, passive properties, contact representation, margin/gap semantics, and capacities the scene relies on.
Record the source run’s commands and replay them unchanged on the target. Compare task state, penetration, contact and constraint counts, and force or residual traces where their definitions are compatible. Include recorded failures and bounded worst-case commands; random rollouts may not reach the states that expose a missing feature or unstable interaction.
Symptom Table#
Symptom |
Try first |
Then try |
Main cost |
|---|---|---|---|
Persistent penetration |
Reduce |
Increase solver iterations if available; increase contact stiffness within stability limits; use SDF or hydroelastic contacts for complex meshes. |
Runtime |
Jitter or explosive motion |
Lower contact or drive stiffness; add damping; check for overlapping shapes, unintended self-collision, and conflicting or overconstrained constraints. |
Clamp or rate-limit commands in control code; use supported effort limits or armature when physically justified; reduce mass and inertia ratios. |
Fidelity |
Fast objects tunnel through geometry |
Reduce |
Use speculative contacts and conditional refreshes with a solver that acts on separated contacts; monitor travel overflow. |
Collision and solver runtime |
Weak grasp or object slip |
Check friction coefficients, contact locations, contact count, and gripper force limits. |
Use richer contact geometry; raise solver convergence work if supported; tune torsional and rolling friction where relevant. |
Runtime |
Slow or inaccurate drive tracking |
Tune |
Add feed-forward control; reduce |
Runtime or response speed |
Stack or mechanism drifts |
Verify mass properties and joint frames; reduce |
Increase solver-specific constraint work; reduce unsupported or over-constrained features; use a solver that supports the needed constraints. |
Runtime |
Simulation is too slow |
Profile the simulation and address execution overhead first (see Performance). |
Reduce substeps, iterations, or contact refresh rate; simplify collision geometry or contact models, and validate accuracy. |
Accuracy |
Going Deeper#
Solver overview — solver selection, capability matrices, and joint-feature support.
Solver Tuning Reference — supported knobs per solver and sanity-check math.
MuJoCo-Warp Contact Tuning — the MuJoCo-Warp constraint model,
ke/kdtosolref/solimpmapping, and task templates.Performance — CUDA graph capture, buffer sizing, and benchmarking.
VBD Tuning — the VBD mental model, parameter effects, failure modes and fixes, and known-good parameter combinations (in development).