Page 1 of 1

Python Bindings in Custom OpenSim Build

Posted: Wed Dec 11, 2024 6:15 pm
by aafox
Hi OpenSim Team,

I have created some new classes in a custom build of OpenSim 4.5 which seem to be behaving nicely and working in C++ on my local build. I would like to try and include these new classes in the Python bindings as I'm keen to run some more detailed pipelines and analyses with these classes - and I'd be more comfortable doing this in Python vs. C++. I made a relatively lazy attempt to include the new classes in the Python bindings by adding them to the Bindings\OpenSimHeaders_simulation.h file and creating a basic test case - yet this failed when running the continuous-integration workflow on GitHub actions in trying to build this custom version of OpenSim (whereas it succeeded before I made these changes). I can see there are other files in the Bindings folder where classes are mentioned (e.g. simulation.i), so I am wondering whether there is a recommended approach for adding classes to these bindings or if it might not actually be feasible?

Aaron

Re: Python Bindings in Custom OpenSim Build

Posted: Thu Jan 16, 2025 8:35 am
by fpique94
Hello,

I write here since my question is probably similar to the above.

I have slightly modified an existing class of Simbody in C++. So I would like to rebuild the whole opensim and include it in the Python bindings so that I can import this custom version into a Python script.
As Aaron said, I am about to make some "lazy attempts" at this, but, since I have relatively low experience on these matters, any guide/tutorial/hint/suggestion on how to achieve this would be of great help!

Francesco

Re: Python Bindings in Custom OpenSim Build

Posted: Mon Jan 20, 2025 10:29 am
by nbianco
Hi Aaron and Francesco,

You will need to update both "Bindings\OpenSimHeaders_simulation.h" and "Bindings\simulation.i" with a header include for your new class. If all else is correct, then that should be sufficient to rebuild the bindings with your custom class.

If you run into issues, feel free to post them to this thread and I can help debug.

Best,
Nick

Re: Python Bindings in Custom OpenSim Build

Posted: Tue Jan 21, 2025 3:24 pm
by aafox
Thanks Nick.

Follow-up question, if I successfully get these bindings to work I would then need to build this custom version of OpenSim (e.g. via the continuous-integration workflow on GitHub actions) and that would generate the set-up files for configuring a Python environment to use this version of OpenSim? Alternatively I assume this custom build could be used in a CMake project like the C++ examples provided with the OpenSim release?

Aaron

Re: Python Bindings in Custom OpenSim Build

Posted: Wed Jan 22, 2025 1:17 pm
by nbianco
Hi Aaron,

If you build the "Install" target in your custom build, it will create a folder (similar to those from the CI builds downloaded from GitHub) that includes the "setup.py" script needed for a manual install of the Python bindings. So no need to go through GitHub for that.

Let me know if I can clarify anything.

-Nick

Re: Python Bindings in Custom OpenSim Build

Posted: Thu Jan 23, 2025 3:00 am
by fpique94
Thank you Nick,

I was able to rebuild opensim and manually install the corresponding python package using pip. In my case I didn't have to touch the bindings since I did not create new classes, I guess.

Best,
Francesco