Skip to content
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

Copy only dynamic data #258

Open
majklost opened this issue Oct 1, 2024 · 3 comments
Open

Copy only dynamic data #258

majklost opened this issue Oct 1, 2024 · 3 comments

Comments

@majklost
Copy link

majklost commented Oct 1, 2024

I am using pymunk for my bachelor thesis, where I plan using RRT algorithm. Problem is, that I store many copies of space in a tree. I benchmarked my solution and found out that making a copy of space is the most expensive operation in whole process (70 % of time). Since all the simulations contain same bodies, constraints, shapes and collision handlers, I would just need to extract and apply only data that changes when stepping the simulation.

I tried to copy all physical aspects of bodies to bodies in second simulator (pos, velocity, angle,...), But simulation result still differs....
I looked how space.copy() is implemented, but it creates new space, so many things differs from my usecase.

Can you give a hint what all should I export and import from one simulation to another to achieve same behaviour when stepping both of them?
(I can then contribute this feature to pymunk if it works)
Thanks,
Michal

@viblo
Copy link
Owner

viblo commented Oct 2, 2024 via email

@majklost
Copy link
Author

majklost commented Oct 2, 2024

Hello, thank you for response,
In my simulation I have a cable: https://github.com/majklost/2Dsim/blob/v2/src/deform_plan/assets/PM/objects/cable.py (Whole project is open source, but at this point it is still under construction and purpose of repo is just saving previous versions of code)

Cable is a group of rectangles connected with springs and rotary springs. The problem with space.copy() is that it is used in every iteration of RRT algortihm (imagine about 5000 or 10000 copies). In this setup all small nuances have drastical impact on final performance (I did not benchmarked internal parts of space.copy() )....

Do you think that extracting and setting things that can change during simulation (e.g. on body - position, angle, velocity) from one simulation to another and copying internal arbiter cache might be sufficient to make these two simulation "synced"? (behave same in next iterations?). Or is there anything else to transfer (I do not know if springs have some internal attributes like stored energy, that would need to be transfered, or is there even a need for making copies of internal C structures?)....

@viblo
Copy link
Owner

viblo commented Oct 2, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants