-
Notifications
You must be signed in to change notification settings - Fork 862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[float32] CG/Newton solver terminates early due to improvement overshoots #2313
Comments
An abs is certainly not missing on that line. This is a signed quantity. If it is negative then there is no improvement. If you can provide a MRE that would be helpful. |
Ah but I think I see what you mean. On line 1833, a negative improvement would would lead to termination. I'll investigate. Thanks. |
I think the correct thing is not an mjtNum improvement = scale * mju_max(oldcost - ctx.cost, 0); Right? Right now any increase in cost leads to termination. Perhaps this is by design? @emotodorov WDYT? |
Ya I think a negative improvement is not possible since in this case we will have already terminated here: mujoco/src/engine/engine_solver.c Line 1779 in a8a9607
I'm closing this issue as you provided no way to reproduce, but I'm quite interested if you were to provide an example. |
@yuvaltassa sorry, I should have mentioned I'm using single precision. You can see negative improvement in something like the xml below. I also noticed that sometimes one-sided search can stuck at local minima and exhaust iterations with no improvement, while deriv[0] is above the tolerance. Would it make sense to check for delta in this loop as well? mujoco/src/engine/engine_solver.c Line 1292 in a8a9607
<mujoco>
<option timestep="0.015"/>
<option gravity="0 0 -9.81"/>
<size memory="100M"/>
<default>
<geom solimp=".9 .99 .005"/>
<default class="box">
<geom type="box" material="box" size="0.5 0.5 0.5"/>
</default>
</default>
<asset>
<texture name="texgeom" type="cube" builtin="flat" mark="cross" width="128" height="128"
rgb1="0.6 0.6 0.6" rgb2="0.6 0.6 0.6" markrgb="1 1 1"/>
<material name="box" texture="texgeom" texuniform="true" rgba=".4 .9 .9 1"/>
</asset>
<visual>
<quality shadowsize="4096" offsamples="8"/>
<map znear="0.1" force="0.05"/>
</visual>
<statistic extent="4"/>
<worldbody>
<light directional="true" diffuse=".8 .8 .8" pos="0 0 10" dir="0 0 -10"/>
<geom type="plane" size="10 10 .01"/>
<body euler="0 0 0" pos="3 0 10">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 10">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 13">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 15">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 17">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 19">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 21">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 23">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 25">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 27">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 29">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 31">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 33">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 35">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 37">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 39">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 41">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 43">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 45">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 47">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 49">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 51">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 53">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 55">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 57">
<freejoint/>
<geom class="box"/>
</body>
</worldbody>
</mujoco> |
We are solving a convex optimization problem and have computed a direction
which mathematically should be a descent direction. If it is not, that
means we are so close to the minimum that floating-point errors are causing
an increase in cost; in which case we should indeed terminate.
…On Mon, Dec 30, 2024 at 3:40 PM Yuval Tassa ***@***.***> wrote:
I think the correct thing is not an abs but rather max(0, ):
mjtNum improvement = scale * mju_max(oldcost - ctx.cost, 0);
Right?
Right now any increase in cost leads to termination. Perhaps this is by
design? @emotodorov <https://github.com/emotodorov> WDYT?
—
Reply to this email directly, view it on GitHub
<#2313 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB2V4L7RP7JH7UDIMJLEXF32IHKWJAVCNFSM6AAAAABUINWXSKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRWGAYTANJYGM>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Ah, like I said, floating-point errors. This is an interesting idea though,
when using single-precision. If you do this, set an internal flag to tell
you that you are now operating in a different regime where the math and
convergence criteria etc. no longer apply. Maybe allow a couple of
iterations in that regime and terminate? Not obvious; will have to be
fine-tuned or real-world examples.
…-- Emo
On Mon, Dec 30, 2024 at 7:16 PM Maxim Vorobey ***@***.***> wrote:
@yuvaltassa <https://github.com/yuvaltassa> sorry, I should have
mentioned I'm using single precision. You can see negative improvement in
something like the xml below.
I also noticed that sometimes one-sided search can stuck at local minima
and exhaust iterations with no improvement, while deriv[0] is above the
tolerance. Would it make sense to check for delta in this loop as well?
https://github.com/google-deepmind/mujoco/blob/a8a960771234c8d84b085516d9f76a53477af28c/src/engine/engine_solver.c#L1292
<mujoco>
<option timestep="0.015"/>
<option gravity="0 0 -9.81"/>
<size memory="100M"/>
<default>
<geom solimp=".9 .99 .005"/>
<default class="box">
<geom type="box" material="box" size="0.5 0.5 0.5"/>
</default>
</default>
<asset>
<texture name="texgeom" type="cube" builtin="flat" mark="cross" width="128" height="128"
rgb1="0.6 0.6 0.6" rgb2="0.6 0.6 0.6" markrgb="1 1 1"/>
<material name="box" texture="texgeom" texuniform="true" rgba=".4 .9 .9 1"/>
</asset>
<visual>
<quality shadowsize="4096" offsamples="8"/>
<map znear="0.1" force="0.05"/>
</visual>
<statistic extent="4"/>
<worldbody>
<light directional="true" diffuse=".8 .8 .8" pos="0 0 10" dir="0 0 -10"/>
<geom type="plane" size="10 10 .01"/>
<body euler="0 0 0" pos="3 0 10">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 10">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 13">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 15">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 17">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 19">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 21">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 23">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 25">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 27">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 29">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 31">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 33">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 35">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 37">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 39">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 41">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 43">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 45">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 47">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 49">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 51">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 53">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 55">
<freejoint/>
<geom class="box"/>
</body>
<body euler="0 0 0" pos="0 0 57">
<freejoint/>
<geom class="box"/>
</body>
</worldbody>
</mujoco>
—
Reply to this email directly, view it on GitHub
<#2313 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AB2V4L5V55THTN6Q7XM4JU32IIECJAVCNFSM6AAAAABUINWXSKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKNRWGA4TONZTGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Reopening since we now have an MRE, thanks @n3b ! If you have capacity:
Thanks again! |
@emotodorov thank you, that makes so much sense now. Unfortunately my math background is way below the necessary level to make such assumptions. I never thought of precision issues in that context because I've been seeing unscaled delta cost even below -1e5. @yuvaltassa thank you,
I do have some thoughts about improving Hessian updates besides what I already did, and about CG performance as well, but am not sure if it's the right place for it. Neither I'm confident it would make any sense from the math POV, so please let me know if you are up to discuss it. Oh, and another thing I just remembered. The R dimensions for contacts are being overridden by the first one (using translation diag only). Is that intentional? mujoco/src/engine/engine_core_constraint.c Line 1466 in 69c9ac0
mujoco/src/engine/engine_core_constraint.c Line 1528 in 69c9ac0
mujoco/src/engine/engine_core_constraint.c Line 1543 in 69c9ac0
|
Intro
My setup
What's happening? What did you expect?
I believe an abs() is missing here
mujoco/src/engine/engine_solver.c
Line 1824 in a8a9607
There are serious stability issues otherwise that can be seen in cases like throwing 10+ perfectly aligned cubes on top of each other.
Steps for reproduction
Minimal model for reproduction
No response
Code required for reproduction
No response
Confirmations
The text was updated successfully, but these errors were encountered: