[fixed] Sketcher Levenberg-Marquardt solver precision issues?

Have some feature requests, feedback, cool stuff to share, or want to know where FreeCAD is going? This is the place.
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

[fixed] Sketcher Levenberg-Marquardt solver precision issues?

Post by DeepSOIC »

Hi!
I recently played with selecting the solver when replying to OldDraftsman's post, and left it in LM mode. Now, I'm modeling a not-so-complex yet nontrivial part, and I am regularly running into strange BOP failures.

Like, the initial modeling goes OK. I print it, then I realize it needs an improvement, tweak some sketches, and it fails to recompute (or bad result, fails bopcheck, or looks good but last fillet fails). I try forced recompute - no improvement. I delete most fusions and try to redo them, and those that failed previously, fail yet again. Then I edit sketches that are involved - I just open them (one by one), drag some fully-constrained point (i.e. don't change sketch geometry), and close. And that actually helps.

I have noticed such a behavior before when I tried LM solver. It was too intermittent, I couldn't really reproduce it, so I didn't post a bug report. I just switched to DogLeg, and problems seemed to go away. Now I've run into it again, and decided it's time to post. Sorry, I still don't have a way to reproduce the problem.

So. Did anyone have similar intermittent problems? Maybe we could eventually find a reproducible example, which will allow us to debug and fix the solver. LM solver has this nice property of being somewhat more flip-resistant, and I'd like to use it as my solver of choice.

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.14495 (Git)
Build type: Release
Branch: master
Hash: c717d1121d888fe6cfbd8971b5f59311a34b37bc
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Russian/RussianFederation (ru_RU)
Last edited by DeepSOIC on Tue Mar 24, 2020 3:47 pm, edited 2 times in total.
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher Levenberg-Marquardt solver precision issues?

Post by abdullah »

DeepSOIC wrote: Sat Oct 27, 2018 7:28 pm Hi!
I recently played with selecting the solver when replying to OldDraftsman's post, and left it in LM mode. Now, I'm modeling a not-so-complex yet nontrivial part, and I am regularly running into strange BOP failures.

Like, the initial modeling goes OK. I print it, then I realize it needs an improvement, tweak some sketches, and it fails to recompute (or bad result, fails bopcheck, or looks good but last fillet fails). I try forced recompute - no improvement. I delete most fusions and try to redo them, and those that failed previously, fail yet again. Then I edit sketches that are involved - I just open them (one by one), drag some fully-constrained point (i.e. don't change sketch geometry), and close. And that actually helps.

I have noticed such a behavior before when I tried LM solver. It was too intermittent, I couldn't really reproduce it, so I didn't post a bug report. I just switched to DogLeg, and problems seemed to go away. Now I've run into it again, and decided it's time to post. Sorry, I still don't have a way to reproduce the problem.

So. Did anyone have similar intermittent problems? Maybe we could eventually find a reproducible example, which will allow us to debug and fix the solver. LM solver has this nice property of being somewhat more flip-resistant, and I'd like to use it as my solver of choice.

OS: Windows 10
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.14495 (Git)
Build type: Release
Branch: master
Hash: c717d1121d888fe6cfbd8971b5f59311a34b37bc
Python version: 2.7.14
Qt version: 4.8.7
Coin version: 4.0.0a
OCC version: 7.2.0
Locale: Russian/RussianFederation (ru_RU)
I am a LM regular.

What you describe relating to the solver is reality. I have never come into failed bopchecks due to this. In the cases I have had problems, it completely failed to pad (for example). You open it you try to drag, even with fully constrained. You closed and it is solved.

One of the causes is that outside of Sketch edit mode, the solver used is still dogleg, no matter what you have selected.

Fixing it is in my mind. It should be a new feature of v0.19, i.e. that if you selected LM, LM is also used outside the Sketcher edit mode.

I do not know if there is a ticket for this, if there is not, feel free to make one.
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Sketcher Levenberg-Marquardt solver precision issues?

Post by triplus »

abdullah wrote: Sun Oct 28, 2018 8:12 am One of the causes is that outside of Sketch edit mode, the solver used is still dogleg, no matter what you have selected.

Fixing it is in my mind.
Was waiting for you to write something like that since:

https://forum.freecadweb.org/viewtopic. ... =30#p92119

Exciting times ahead! :mrgreen:
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher Levenberg-Marquardt solver precision issues?

Post by DeepSOIC »

I think I have a reliable way to reproduce.
1. Open attached file
-> has two boxes having coplanar faces. Faces are one, thanks to refinement.
2. Open "Sketch001". Change solver to LM. Close the sketch.
(if already in LM mode, I still have to open and close Sketch001 for the problem to happen)

3. Open "Sketch". Drag the left side of rectangle a little bit.
4. close the sketch, project recomputes.
-> the refinement is broken, faces are split. Forced recompute doesn't fix the problem.

In console, I test solver accuracy:

Code: Select all

>>> App.ActiveDocument.Sketch001.calculateConstraintError(8)
4.8310712881574035e-06
So the constraint has an error much larger than Precision::Confusion, so the faces are not treated coplanar anymore, and so refinement doesn't work.
Actual problems probably begin when accuracy happens to be close to 1e-7, where OCC starts to struggle to decide if things intersect or not.


EDIT: changed steps to reproduce
Attachments
sketcher-basic-precision-test.FCStd
(10.79 KiB) Downloaded 111 times
sketcher-basic-precision-test.PNG
sketcher-basic-precision-test.PNG (157.81 KiB) Viewed 2332 times
abdullah
Veteran
Posts: 4935
Joined: Sun May 04, 2014 3:16 pm
Contact:

Re: Sketcher Levenberg-Marquardt solver precision issues?

Post by abdullah »

DeepSOIC wrote: Sun Oct 28, 2018 11:46 am I think I have a reliable way to reproduce.
I am puzzled by your example. It indeed fails with LM and succeeds with DL. However, it is not a case I would expect to fail because of the solver selected.
GeneFC
Veteran
Posts: 5373
Joined: Sat Mar 19, 2016 3:36 pm
Location: Punta Gorda, FL

Re: Sketcher Levenberg-Marquardt solver precision issues? [now with steps to reproduce!]

Post by GeneFC »

DeepSOIC wrote: Sun Oct 28, 2018 11:46 am -> the refinement is broken, faces are split. Forced recompute doesn't fix the problem.
Just for fun I changed the solver back to dog leg. The faces automatically rejoin without any user action. So it appears the model is not permanently tainted.

Gene
triplus
Veteran
Posts: 9471
Joined: Mon Dec 12, 2011 4:45 pm

Re: Sketcher Levenberg-Marquardt solver precision issues? [now with steps to reproduce!]

Post by triplus »

I can confirm this issue still exists. Interestingly going back to Sketch001 and dragging one of the lines a bit fixes the issue.

P.S. During the dragging operation i noticed DogLeg solver is being used. Could this be somehow changed to LM and could it be related to the fact LM isn't being used from outside of the Sketcher edit mode?

Reference.
https://forum.freecadweb.org/viewtopic.php?f=8&t=44312
User avatar
DeepSOIC
Veteran
Posts: 7896
Joined: Fri Aug 29, 2014 12:45 am
Location: used to be Saint-Petersburg, Russia

Re: Sketcher Levenberg-Marquardt solver precision issues? [now with steps to reproduce!]

Post by DeepSOIC »

I think the reason is:
DeepSOIC wrote: Wed Nov 27, 2019 5:32 pm LM solver ... termination condition is:
e1^2 + e2^2 + .. < eps, where default eps = 1e-10
In dogleg, it is:
max(abs(e1), abs(e2), ...) < tolf , where tolf default is again 1e-10
Since DL is comparing linearly and LM is comparing squared, there is a 5 order of magnitude difference in accuracy.
I'll make a PR this weekend, if I don't forget.
chrisb
Veteran
Posts: 54213
Joined: Tue Mar 17, 2015 9:14 am

Re: Sketcher Levenberg-Marquardt solver precision issues? [now with steps to reproduce!]

Post by chrisb »

triplus wrote: Fri Mar 20, 2020 1:44 pm Could this be somehow changed to LM and could it be related to the fact LM isn't being used from outside of the Sketcher edit mode?
Did you try changing it directly in the Parameters->BaseApp->Preferences->Mod->Sketcher->SolverAdvanced ?
A Sketcher Lecture with in-depth information is available in English, auf Deutsch, en français, en español.
Post Reply