Python Bindings in Custom OpenSim Build

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Aaron Fox
Posts: 294
Joined: Sun Aug 06, 2017 10:54 pm

Python Bindings in Custom OpenSim Build

Post by Aaron Fox » Wed Dec 11, 2024 6:15 pm

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

User avatar
Francesco Piqué
Posts: 2
Joined: Sat Oct 21, 2017 12:41 am

Re: Python Bindings in Custom OpenSim Build

Post by Francesco Piqué » Thu Jan 16, 2025 8:35 am

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

User avatar
Nicholas Bianco
Posts: 1073
Joined: Thu Oct 04, 2012 8:09 pm

Re: Python Bindings in Custom OpenSim Build

Post by Nicholas Bianco » Mon Jan 20, 2025 10:29 am

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

User avatar
Aaron Fox
Posts: 294
Joined: Sun Aug 06, 2017 10:54 pm

Re: Python Bindings in Custom OpenSim Build

Post by Aaron Fox » Tue Jan 21, 2025 3:24 pm

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

User avatar
Nicholas Bianco
Posts: 1073
Joined: Thu Oct 04, 2012 8:09 pm

Re: Python Bindings in Custom OpenSim Build

Post by Nicholas Bianco » Wed Jan 22, 2025 1:17 pm

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

User avatar
Francesco Piqué
Posts: 2
Joined: Sat Oct 21, 2017 12:41 am

Re: Python Bindings in Custom OpenSim Build

Post by Francesco Piqué » Thu Jan 23, 2025 3:00 am

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

POST REPLY