Single precision: EPA face normals tilt on exactly aligned face pairs since mjMINDIST2/3 were lowered to 1e-17
メンテナーはふだん 6 日以内に返信
評価
調査の方向性
Start with the single precision distance tolerances and EPA face normal calculations in engine_collision_gjk.c, then compare behavior with the reproduction model and program in the issue. The reported candidate fix should preserve shallow penetration handling while restoring aligned contact normals and depths; verify single precision behavior and unchanged double precision results. Pull request #3915 is already open against this issue.
索引モデルが issue の本文から書いたものです。
説明
Intro
I contribute to MuJoCo Warp, which runs MuJoCo's GJK/EPA in float32 with the constants of the mjUSESINGLE build, so I compare against MuJoCo C built with mjUSESINGLE.
My setup
MuJoCo C at main (aa9a0eaef), built with CMake and -DmjUSESINGLE in CMAKE_C_FLAGS and CMAKE_CXX_FLAGS. Linux x86_64, GCC. Double precision builds of the same commit for comparison.
What's happening? What did you expect?
Since 3bbf510d4 ("Improve NativeCCD numerical precision"), a stack of thin box-shaped mesh plates resting exactly aligned on a mesh slab no longer settles in the single precision build. The four corner contacts of a face pair, which should have the same depth and the normal (0, 0, 1), get normals tilted by 3e-4 to 5e-4 rad and depths that differ by up to about 100 µm (for example -172, -209, -286, -249 µm on the top pair at step 999). The plates rock, and CG needs 10 to 20 times more iterations.
Mean CG iterations over the second half of 2000 steps, and max z drift of any plate over that half:
| plates (8 mm thick) | double, main | single, 3bbf510d4^ | single, main |
|---|---|---|---|
| 3 | 1.3, 0.000 mm | 1.3, 0.000 mm | 16.8, 0.018 mm |
| 4 | 1.8, 0.001 mm | 1.8, 0.001 mm | 26.4, 0.074 mm |
| 5 | 2.0, 0.001 mm | 2.0, 0.001 mm | 19.9, 0.156 mm |
Within 3bbf510d4, the change comes from the single precision mjMINDIST2 and mjMINDIST3, lowered from 1e-10f to 1e-17f: setting them back to 1e-10f restores equal depths, the (0, 0, 1) normal and 1 to 2 iterations. Reverting them is not a fix, though, because the lower values are what made shallow penetration work in single precision: with 1e-10f, mj_geomDistance returns 0 for aligned boxes or mesh boxes overlapping by 2 to 12 µm.
I have a candidate fix in engine_collision_gjk.c that keeps both and leaves double precision results unchanged, and can send it as a PR.
Steps for reproduction
- Build MuJoCo with
-DmjUSESINGLE. - Compile the program below against it (with
-DmjUSESINGLE) and run it on the model. - Compare with a double precision build, or with single precision at 3bbf510d4^.
Minimal model for reproduction
<mujoco>
<option timestep="0.002" solver="CG" cone="elliptic" impratio="10" integrator="implicitfast"
iterations="100" ls_iterations="15" tolerance="1e-6"/>
<asset>
<mesh name="plate" vertex="-0.105 -0.148 -0.004 -0.105 -0.148 0.004 -0.105 0.148 -0.004 -0.105 0.148 0.004
0.105 -0.148 -0.004 0.105 -0.148 0.004 0.105 0.148 -0.004 0.105 0.148 0.004"/>
<mesh name="slab" vertex="-0.3 -0.3 -0.02 -0.3 -0.3 0.02 -0.3 0.3 -0.02 -0.3 0.3 0.02
0.3 -0.3 -0.02 0.3 -0.3 0.02 0.3 0.3 -0.02 0.3 0.3 0.02"/>
</asset>
<worldbody>
<body pos="0 0 0.02"><geom type="mesh" mesh="slab"/></body>
<body pos="0 0 0.044"><freejoint/><geom type="mesh" mesh="plate" mass="0.05"/></body>
<body pos="0 0 0.052"><freejoint/><geom type="mesh" mesh="plate" mass="0.05"/></body>
<body pos="0 0 0.060"><freejoint/><geom type="mesh" mesh="plate" mass="0.05"/></body>
</worldbody>
</mujoco>
Code required for reproduction
#include <math.h>
#include <stdio.h>
#include <mujoco/mujoco.h>
int main(int argc, char** argv) {
char err[1000];
mjModel* m = mj_loadXML(argv[1], NULL, err, sizeof(err));
mjData* d = mj_makeData(m);
double iters = 0, drift = 0, z0[3];
for (int step = 0; step < 2000; step++) {
mj_step(m, d);
if (step == 999) {
for (int c = 0; c < d->ncon; c++) {
printf("geoms %d-%d dist %+.1f um normal (%.4f %.4f %.4f)\n", d->contact[c].geom[0], d->contact[c].geom[1],
1e6 * d->contact[c].dist, d->contact[c].frame[0], d->contact[c].frame[1], d->contact[c].frame[2]);
}
}
if (step >= 1000) {
iters += d->solver_niter[0];
for (int p = 0; p < 3; p++) {
double z = d->qpos[7 * p + 2];
if (step == 1000) z0[p] = z;
drift = fmax(drift, fabs(z - z0[p]));
}
}
}
printf("mean CG iterations %.1f, max z drift %.3f mm\n", iters / 1000, 1e3 * drift);
return 0;
}
Confirmations
- I searched the latest documentation thoroughly before posting.
- I searched previous Issues and Discussions, I am certain this has not been raised before.
- 主要言語
- C++
- スター
- 18.3k
- フォーク
- 2.2k
- 平均マージ
- 9日 11時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
google-deepmind/mujoco のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google-deepmind/mujoco#3932 ·
メンテナーはふだん 6 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
google-deepmind/mujoco#3929 ·
メンテナーはふだん 6 日以内に返信
-
`import mujoco.mjx` fails with TypeError when warp-lang is too old対応中かも @moah0911 が 22 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
google-deepmind/mujoco#3738 ·
メンテナーはふだん 6 日以内に返信
-
Unity 6.6 support再び着手できるかも @Balint-H が 53 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンenhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
google-deepmind/mujoco#3615 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 6 日以内に返信
-
Filament: `filament.ao.bilateral_threshold` and six other model options are ignored since 4.0.1, which changed the default ambient occlusion対応中かも @jeongseok-meta が今日担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 56/100
google-deepmind/mujoco#3933 ·
メンテナーはふだん 6 日以内に返信
google-deepmind/mujoco の issue をすべて見る
似ている issue
-
難易度 1/5 1時間未満 初心者へのやさしさ 91/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
maplibre/maplibre-native#5072 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
tenstorrent/tt-umd#4017 ·
メンテナーはふだん 3 日以内に返信
-
difficulty:easy func:gui prio:low type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
NatronGitHub/Natron#1538 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
hyprwm/hyprsunset#103 · コメント 1 件 ·