Another approach to assembly solver (A2plus)

Discussion about the development of the Assembly workbench.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

project4 wrote: Mon Jul 16, 2018 5:16 pm Can someone send me large and complex Assembly2 files, but those that are using simple constraints that already exist in A2P?
I'll try to import those to A2P format, so we could have large assemblies to create pressure on the solver...
Hi project4,

you do not need to test now, as solver load will be much to high above some 15/20 parts, depending on constraint structure.
(Worst case: some long chains of constrained parts)

Interesting would be the import of old A2 files. Would be fine you could translate the constraint names from A2 to A2p.
But i am not sure that the imported system will be solvable as e.g. directions of constraints could be wrong.

@Turro75 is fighting to split up bigger assemblies to partial systems (me too), as this would speed system up, reduce load on solver and enhance accuracy.

I for my self do not have big A2 assemblies as A2 failed much to early for my needs.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

kbwbe wrote: Mon Jul 16, 2018 5:46 pm you do not need to test now, as solver load will be much to high above some 15/20 parts, depending on constraint structure.
(Worst case: some long chains of constrained parts)
Sounds like you don't want any help with that project :)

If I had some assembly2 files, I could at least try to load it...
I do want some big files that will create high pressure on the solver, so we could measure its performance.
20 parts is very low. Need something that will take 10-20-60 seconds to resolve as a start.

A general note from my experience, if you want developers help, add some tasks to the GitHub issues, so people would know what are your plans and might take some tasks. It could be something easy as updating a wiki or some future plans on 5 version ahead.
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

project4 wrote: Mon Jul 16, 2018 5:55 pm
kbwbe wrote: Mon Jul 16, 2018 5:46 pm you do not need to test now, as solver load will be much to high above some 15/20 parts, depending on constraint structure.
(Worst case: some long chains of constrained parts)
Sounds like you don't want any help with that project :)

If I had some assembly2 files, I could at least try to load it...
I do want some big files that will create high pressure on the solver, so we could measure its performance.
20 parts is very low. Need something that will take 10-20-60 seconds to resolve as a start.

A general note from my experience, if you want developers help, add some tasks to the GitHub issues, so people would know what are your plans and might take some tasks. It could be something easy as updating a wiki or some future plans on 5 version ahead.
Hi @project4,
@Turro75 as information...

help is appreciated, if you really want to program something for this project.

I need someone who is able to analyse the dependency graph of constraints via alogrithm.
Especially this case:

- a part is constrained to a fix/tempfixed part directly

- if there is a constraint-chain, which leads from this part via some intermediate constraints to any fixed part again, i will have to add all these intermediate parts to a partial system for solving.

- if there is more than one constraint chain with this criteria, this part chains belongs to partial system also.

- if there is no chain found, the first part can be solved stand alone and could be tempfixed. Otherwise the partial system has to be solved and the parts be tempfixed after that.

Solving system starts again with less parts involved.

This would be a good start for warming up. ;) As it is very important for speeding up the solver.
Turro already implemented good code to manage the partial systems. Code of Turro you can find some posts before (solversystem.py). But the algorithm above is not there ATM and my brain is smoking..

Feel free to ask.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

kbwbe wrote: Mon Jul 16, 2018 7:30 pm I need someone who is able to analyse the dependency graph of constraints via alogrithm.
Especially this case:

- a part is constrained to a fix/tempfixed part directly

- if there is a constraint-chain, which leads from this part via some intermediate constraints to any fixed part again, i will have to add all these intermediate parts to a partial system for solving.

- if there is more than one constraint chain with this criteria, this part chains belongs to partial system also.

- if there is no chain found, the first part can be solved stand alone and could be tempfixed. Otherwise the partial system has to be solved and the parts be tempfixed after that.

Solving system starts again with less parts involved.

This would be a good start for warming up. ;) As it is very important for speeding up the solver.
Turro already implemented good code to manage the partial systems. Code of Turro you can find some posts before (solversystem.py). But the algorithm above is not there ATM and my brain is smoking..

Feel free to ask.
I started to sniff around the code already and will do some experiments to understand it better.
For now I have a file with 5 parts and few constraints and from the measurements I've added it already takes about 100mSec to resolve (900 steps), so I have something to work with.

Still need help with that question:
Is there an efficient method to reload the WB python scripts besides closing and reopening the whole FreeCAD?
Looks like switching to another WB and back to A2B didn't help :(

Restarting the whole application is pretty annoying...

Another question:
I see you didn't take the cache logic to your repository. Could you at least explain the logic behind it?
It sounds pretty logical to store some recalculated information and use it if parts of the assembly wasn't moved.

And another question:
Are all the calculations should be done sequentially? Can we parallelize them to utilize all the cores of the CPU?
From my experience that speeds up the things ALOT.
Without thinking about it too much, looks like different branches of the chain could be calculated separately from each other...
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

Forgot to ask:
Is Turro's code in the GitHub repo already?
I can't work with passing ZIP files...
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

project4 wrote: Mon Jul 16, 2018 7:51 pm
I started to sniff around the code already and will do some experiments to understand it better.
For now I have a file with 5 parts and few constraints and from the measurements I've added it already takes about 100mSec to resolve (900 steps), so I have something to work with.
I can supply some test assemblies, done with A2plus. So you would have more test material. What do you like PM ? Zip here ?

project4 wrote: Mon Jul 16, 2018 7:51 pm Still need help with that question:
Is there an efficient method to reload the WB python scripts besides closing and reopening the whole FreeCAD?
Looks like switching to another WB and back to A2B didn't help :(
Restarting the whole application is pretty annoying...
It should be possible to convert the solversystem.py to an executable script, which you can start from FreeCAD. This uses always the new script.
You would have to add a section "if _name__ == __main__:" and some things within there. I can help if necessary.


project4 wrote: Mon Jul 16, 2018 7:51 pm Another question:
I see you didn't take the cache logic to your repository. Could you at least explain the logic behind it?
It sounds pretty logical to store some recalculated information and use it if parts of the assembly wasn't moved.
I do not quite understand your question. I think, my solving algorithm does not need a cache. Everything what is calculated is stored
within data structures in solversystem.py. If after calculation it turns out that parts are not been moved, the original placement is not updated.
So what do you mean exactly with "cache" ?
project4 wrote: Mon Jul 16, 2018 7:51 pm And another question:
Are all the calculations should be done sequentially? Can we parallelize them to utilize all the cores of the CPU?
From my experience that speeds up the things ALOT.
Without thinking about it too much, looks like different branches of the chain could be calculated separately from each other...
Could be possible. As function "calcMoveData()" is executed on constant data within this point, it can be perhaps be parallized.
Same for function "moveRigids()". Data calculated before is applied to all rigids. Think code could be parallized.

Edit 1:
if you have 4 CPU's, code will speed up max factor 4, probably less. I think Turro's idea implementing critical code with c++ or some other low level language will speed it up factor 100. So it is perhaps the better way.
/Edit 1:

And for your question in your next post:
I updated the branch "solverlogic" with Turro's code. I only changed code style a little bit.
Master branch will solve all testcases, but slow.
Turro's branch "solverlogic" is much faster but failes e.g. for my movable platform example.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Turro75
Posts: 179
Joined: Mon Aug 15, 2016 10:23 pm

Re: Another approach to assembly solver (A2plus)

Post by Turro75 »

@Kbwbe

another experiment, this is std logic so all objs and constraints are evaluated at the same time, simply I set accuracy as a variable instead of const:

it does 4 steps, the 1st with accuracy 0.1 then it solves at 0.01 (which is the current standard) and then 0.001 and finally 0.0001.

I made a small set of test but it seems it has an edge against the single step at 0.01 in terms of num steps as it seems more easier for the solver getting a rough position will less accurancy and then inprove it, as the object are mostly in place the whole load would be less.

I increased a little bit the size of spinstep, I wonder if it can be set to a value according to the current accuracy
Attachments
solversystem.py
(33.58 KiB) Downloaded 41 times
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

Turro75 wrote: Mon Jul 16, 2018 10:13 pm @Kbwbe

another experiment, this is std logic so all objs and constraints are evaluated at the same time, simply I set accuracy as a variable instead of const:

it does 4 steps, the 1st with accuracy 0.1 then it solves at 0.01 (which is the current standard) and then 0.001 and finally 0.0001.

I made a small set of test but it seems it has an edge against the single step at 0.01 in terms of num steps as it seems more easier for the solver getting a rough position will less accurancy and then inprove it, as the object are mostly in place the whole load would be less.

I increased a little bit the size of spinstep, I wonder if it can be set to a value according to the current accuracy
Hi Turro,
you are always good for great ideas :D . I will test instantly, but not this night!
The size of spinStep and also the size of linMoves sure have to be optimized. I just only have been setting them to somehow working values. ;)
But i think we will still need some logic as you already suggested. Chaining parts with a lot of constraints destabilizes computation and decreases accuracy. There will remain a lot of work. But this is the important part of this project: A reliable solver. Other features can be added, later, everytime..
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
project4
Posts: 237
Joined: Fri Jul 12, 2013 12:53 pm

Re: Another approach to assembly solver (A2plus)

Post by project4 »

kbwbe wrote: It should be possible to convert the solversystem.py to an executable script, which you can start from FreeCAD. This uses always the new script.
You would have to add a section "if _name__ == __main__:" and some things within there. I can help if necessary.
Please elaborate that. An example will definitely help.
How do you and Turro are developing?
kbwbe wrote: I can supply some test assemblies, done with A2plus. So you would have more test material. What do you like PM ? Zip here ?
ZIP here could be great. Might be useful to others as well.
kbwbe wrote: So what do you mean exactly with "cache" ?
I think there are some data that might be cached.
For example, with my test assembly that has only 5 parts and few constraints the loadSystem function takes 2ms, if there are no parts added/removed from the assembly, it might not be needed to rebuild the whole structure again.

I've asked about A2 caching. You wrote somewhere that you didn't take its caching logic since you thought it might have problems.
kbwbe
Veteran
Posts: 1052
Joined: Tue Apr 10, 2018 3:12 pm
Location: Germany, near Köln (Cologne)

Re: Another approach to assembly solver (A2plus)

Post by kbwbe »

Turro75 wrote: Mon Jul 16, 2018 10:13 pm @Kbwbe

another experiment, this is std logic so all objs and constraints are evaluated at the same time, simply I set accuracy as a variable instead of const:

it does 4 steps, the 1st with accuracy 0.1 then it solves at 0.01 (which is the current standard) and then 0.001 and finally 0.0001.

I made a small set of test but it seems it has an edge against the single step at 0.01 in terms of num steps as it seems more easier for the solver getting a rough position will less accurancy and then inprove it, as the object are mostly in place the whole load would be less.

I increased a little bit the size of spinstep, I wonder if it can be set to a value according to the current accuracy
Hi @Turro75,
i does not look so bad. I reduced your "accuray_level" to 4, as 5 was to much for some tests. In total, accuracy improved now factor 10. With no drastically effect to computation time. Your version has been moved to master now.

But i still detect huge computation times on long chains of objects. (e.g. Manuel's crankshaft) So some new logic will still be needed.
KBWBE

https://github.com/kbwbe/A2plus
latest release: v0.4.56, installable via FreeCAD's addon manager
Tutorial: gripper assembly https://www.youtube.com/watch?v=QMxcQ5tssWk
Documentation: https://www.freecadweb.org/wiki/A2plus_Workbench
Post Reply