Further information and documentation about modifying and adding deformables?
DanielTakeshi opened this issue · 6 comments
I am able to run the code with python examples/random_env.py --env_name <ENV_NAME>
commands successfully, and am trying to tune and adjust some of the properties of deformables and have a few questions from my exploration here.
(1) Understanding the Hyperparameters
Is there any documentation I can see for understanding how to tune hyperparameters?
For example, with cloth environments, I see that this method in the ClothEnv
softgym/softgym/envs/cloth_env.py
Lines 90 to 108 in 3841d5c
and with liquid environments we have:
softgym/softgym/envs/pour_water.py
Lines 63 to 85 in 3841d5c
Some of the hyperparameters are self-explanatory, such as the ClothPos
, but others are less clear and it might be nice to understand what they mean in more detail. Is there a reference for this somewhere? More generally I'm wondering how you tuned these parameters in general.
(2) Adding and Mixing Items to Environment/Scene
I am interested in trying to add a variety of items together, for example, a rope and a cloth together in one environment. From reading the code it looks like this must be done through some PyFleX code (located at https://github.com/YunzhuLi/PyFleX) because you are using the API that's at the bottom of this script (https://github.com/YunzhuLi/PyFleX/blob/1391799c77b0bd8f5ab5a2a01f1f2ee64fb5a929/bindings/pyflex.cpp#L3447-L3490). However I'm not sure I fully understand how this interface works.
For example, let's look at the ClothFold environment, where I run:
python examples/random_env.py --env_name ClothFold
The environment reset code will call FlexEnv.reset():
softgym/softgym/envs/flex_env.py
Lines 153 to 175 in 3841d5c
which then calls ClothEnv.set_scene():
softgym/softgym/envs/cloth_env.py
Lines 144 to 166 in 3841d5c
This will call the PyFleX method to set the scene, and I think this is where the cloth and camera are actually created (please correct me if I am wrong). When I print the scene_params
that gets passed as input, I get:
[ -1.6 2. -0.8 74. 73. 0.8 1. 0.9 2. -0. 0.82 0.82 0.
-0.78539816 0. 720. 720. 0.5 1. ]
This comes from a bunch of cloth, camera, and other parameters. However, what I'm not sure about is how to extend this to other items I'd like to add, because it seems like PyFlex will expect to see just a bunch of numbers that must be in the right order. I was looking for some kind of interface that might make object addition like this:
pyflex.add_object(name='xingyu_awesome_cloth', object_type=Cloth, object_config=cloth_params)
pyflex.add_object(name='yufei_fun_camera', object_type=Camera, object_config=camera_params)
However it seems like PyFlex must be provided this information beforehand somehow, then you manually have to pass in the parameters by putting numbers in an array, which presumably has to be in the right order. Is there more information about how this works?
Thanks for your help so far! :)
For (1):
For the fluid env, most of the parameters are about the physical properties of the fluid, e.g., viscosity
will change how viscous the fluid is, with larger value, the fluid behaves more like mil instead of water. We tune those parameters mostly following what the Nvidia Flex demo scene files use, with some tweaks and visual checking.
For (2):
Your trace of how the scene is actually built is correct. So every scene eventually calls pyflex.set_scene(sence_id, params)
, and this will pass a list of parameters to the .h scene files, e.g., the cloth scene is here: https://github.com/Xingyu-Lin/softgym/blob/master/PyFlex/bindings/softgym_scenes/softgym_cloth.h, which accepts the parameters and create the corresponding cloth & cameras.
So if you want to build a new scene that includes both a cloth and a rope, you will need to do the following things:
- Write a new softgym_cloth_and_rope.h, e.g., by combining softgym_cloth.h and softgym_rope.h
- Add the new scene to scene.h: https://github.com/Xingyu-Lin/softgym/blob/master/PyFlex/bindings/scenes.h#L30, and register the new scene in pyflex.cpp: https://github.com/Xingyu-Lin/softgym/blob/master/PyFlex/bindings/pyflex.cpp#L25
- recompile pyflex
- write a new python env wrapper for your new scene.
As per your question on the awesome object adding function pyflex.add_object
, we have not figured out a way to dynamicall add new particle-based objects to a Flex scene after the scene is built. This is becasue the Flex buffer & solver is initialized once when the scene is created, and adding more particles will need to rebuilt the buffer & solver. We had some preliminary exploration on this dynamic adding thing but it didn't work out very well back then. We will spend more time on this in the future as it will indeed bring lots of convenience.
Still, I believe it woule be possible to write a scene file that accepts a parameter to control how many ropes & cloth you want to built when you initialzie the scene.
Hope this helps, and let us know if you have further questions. We will also add this to a more detailed instruction file later.
Thanks @yufeiwang63 !!
Yes, indeed dynamically adding new particle-based objects after the scene is built would be an incredibly useful feature.
After the RSS/IROS deadline in a few days, I will come back to this to investigate ways to customize scenes.
For the fluid env, most of the parameters are about the physical properties of the fluid, e.g., viscosity will change how viscous the fluid is, with larger value, the fluid behaves more like mil instead of water. We tune those parameters mostly following what the Nvidia Flex demo scene files use, with some tweaks and visual checking.
I have a question very similar to topic 1 in this issue about the customized configuration.
What if I want to add a new configuration in pyflex.set_scene? For example, if I want to change the color of the rope, how can I do it?
And furthermore, how can I add a new shape like a figure 8 knot? How to modify the pkl file? (What's the meaning of the data in the pkl - why data['s']
has shape 2*42?)
I am trying to recreate something like Ha's fling bot env and perform some domain randomization. For simplicity Im going to refer to the black cloth as base cloth and the yellow one as main cloth
Yufei's previous comment was very helpful, but I still have some questions.
-
Select different colors for main and base clothes.
softgym/PyFlex/bindings/main.cpp
Line 181 in 27c6cbc
CreateSpringGrid()
the same as far as I know. -
When using
pos = pyflex.get_positions()
I am 99% sure I get positions for both clothes. Is it possible to access each cloth independently. I suspect this is going to require me to changepyflex_get_positions()
in pyflex.cpp -
Also for the sake of domain randomization, is it possible to change illumination? I see some references in https://github.com/Xingyu-Lin/softgym/blob/master/PyFlex/external/nvapi/include/nvapi.h but nothing I can acces from PyFlex.
Thanks!
@FranBesq I think Huy Ha did a lot of the domain randomization in Blender, where it's probably easier to randomize images. However indeed it would be great to do this in SoftGym directly.
Closing this issue.