Page 1 of 1

Saving and restoring full state?

Posted: Wed Jan 03, 2018 10:23 am
by eof
I'm using PyBullet to basically reimplement some of the models provided by Roboschool. The reason for doing this is that I would need to be able to simulate the exact results of actions in order to have a gold standard model for planning. In other words, I need to be able to play an action and then undo it. Basically, this means being able to snapshot the current state of the simulation, then run it and restore it back.

Is there some way of accomplishing this? I didn't notice any direct API for this in PyBullet. Is this supported at the C++ layer and if so, can someone point me to the right hooks, so I can expose the functionality by patching PyBullet?

Re: Saving and restoring full state?

Posted: Wed Jan 03, 2018 4:08 pm
by Erwin Coumans
That is good timing, I just implemented a first start of saveState and restoreState.

You can save the state to memory using saveState, or save the state to disk using saveBullet('filename')
THen you can restore the state using restoreState(stateId) or restoreState('filename')

Use the latest pybullet 1.7.7 or later (pip install pybullet or from github) and see this example:

https://github.com/bulletphysics/bullet ... reState.py

Make sure the number of objects/constraints etc in the world during restoreState is the same as during saveState.

Re: Saving and restoring full state?

Posted: Wed Sep 26, 2018 6:38 pm
by ratponto
I have used saveState to restore the environment to a previously saved state and it works well.
I was wondering if the environment's envStepCounter attribute is supposed to be resetted to match the saved state's counter?
Now if I reset it multiple times, the counter is not set back and the environment terminates, which is not what I need currently.
Should I save the counter value and re-assign it when restoring, or this would be an incorrect approach?

Thanks in advance!

Re: Saving and restoring full state?

Posted: Fri Oct 05, 2018 1:31 am
by Erwin Coumans
Where is 'envStepCounter'? If it is in Python, just reset it there.