[fixed] Sketcher Levenberg-Marquardt solver precision issues?
Forum rules
Be nice to others! Read the FreeCAD code of conduct!
Be nice to others! Read the FreeCAD code of conduct!
- 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?
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 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.
Re: Sketcher Levenberg-Marquardt solver precision issues?
I am a LM regular.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)
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.
Re: Sketcher Levenberg-Marquardt solver precision issues?
Was waiting for you to write something like that since:
https://forum.freecadweb.org/viewtopic. ... =30#p92119
Exciting times ahead!
- 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?
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:
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
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
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 (157.81 KiB) Viewed 2332 times
Re: Sketcher Levenberg-Marquardt solver precision issues? [now with steps to reproduce!]
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
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
- 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!]
I think the reason is:
I'll make a PR this weekend, if I don't forget.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.
Re: Sketcher Levenberg-Marquardt solver precision issues? [now with steps to reproduce!]
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.