erwincoumans / tiny-differentiable-simulator

Tiny Differentiable Simulator is a header-only C++ and CUDA physics library for reinforcement learning and robotics with zero dependencies.
Apache License 2.0
1.2k stars 129 forks source link

ModuleNotFoundError for pytinydiffsim_ad and AttributeError for pytinydiffsim when running Python code #192

Closed mhr closed 2 years ago

mhr commented 2 years ago

I thought I'd just gotten Python working after finding https://github.com/google-research/tiny-differentiable-simulator/issues/63. But I was mistaken. I've found other errors as I've played with the example files for Python. Apologies if you would prefer if I had created multiple issues, one for each error.

It's especially odd to me that I can import pytinydiffsim_dual just fine, but not pytinydiffsim_ad.

$ python cppad_example.py
Traceback (most recent call last):
  File "cppad_example.py", line 1, in <module>
    import pytinydiffsim_ad as pd
ModuleNotFoundError: No module named 'pytinydiffsim_ad'
$ python b_urdf_structs_example.py
Traceback (most recent call last):
  File "b_urdf_structs_example.py", line 47, in <module>
    sphere_mb.set_base_position(pd.Vector3(0.,0.,25.))
AttributeError: 'pytinydiffsim.TinyMultiBody' object has no attribute 'set_base_position'

But other examples do work (each imports pytinydiffsim and/or pytinydiffsim_dual):

$ python e_load_urdf.py
robot_name= plane

$ python billiard_optimization.py
sphere2red_path= /mnt/c/users/mretc/OneDrive/Documents/Grad School/thesis/motion/tiny-differentiable-simulator/data/sphere2red.urdf

I don't know enough about automatic differentiation to know if I need pytinydiffsim_ad if I have pytinydiffsim_dual.

mhr commented 2 years ago

To solve ModuleNotFoundError for pytinydiffsim_ad, I did the following:

1) I had to amend the issue I linked to and add SET_TARGET_PROPERTIES(pytinydiffsim_ad PROPERTIES PREFIX "") to python/CMakeLists.txt. 2) I had to run make with the flag -D USE_CPPAD=ON.

Still not sure about the other issue. When I ran dir(sphere_mb), set_base_position was not an attribute, but set_position was. So I edited the code to run sphere_mb.set_position(pd.Vector3(0.,0.,25.)) instead, and there wasn't an error any longer. But I'm not sure if set_position does the same thing as set_base_position is supposed to.

erwincoumans commented 2 years ago

If you can import pytinydiffsim_dual , you should be fine. We haven't updated the setup.py code to include the pytinydiffsim_ad I think.

erwincoumans commented 2 years ago

adding the _ad version requires large dependencies that make the build complicated, so it likely won't happen. Closing for now.