Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Christopher Dembia » Fri Nov 11, 2016 10:54 am

It should be fine to use SWIG 3.0.8.

I'd still be interested in knowing if the bindings will work for you (aside from the test cases).
Also, I don't have the <opensim-4.0-install-dir>/lib/[x86_64-linux-gnu] directory.
Then set LD_LIBRARY_PATH to the path containing your libraries:

Code: Select all

<opensim-4.0-install-dir>/lib

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Christopher Dembia » Fri Nov 11, 2016 10:47 pm

I was able to get the MATLAB bindings (from OpenSim 4.0) to work on Ubuntu (14.04), but it was not as straightforward as it should be. The issue is a conflict with MATLAB's libstdc++.so and the one used when building OpenSim. As your ldd output shows, OpenSim depends on libstdc++.so:

Code: Select all

libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f402c923000)
Outside of MATLAB, ld will use the one located at the path above. However, MATLAB tries to prefer its own libstdc++.so (inside the MATLAB installation), and it is not compatible with the one used with OpenSim. Ideally, you could just set LD_LIBRARY_PATH handle this, but MATLAB puts its own library paths in front of whatever you set LD_LIBRARY_PATH to. So, you must use LD_PRELOAD:

Code: Select all

LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6" matlab
You can also just export that environment variable before starting MATLAB, or put it in ~/.bashrc:

Code: Select all

export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6"
This solution is also described here: https://www.mathworks.com/matlabcentral ... ead/255846

User avatar
Bart van Veen
Posts: 9
Joined: Tue Jun 23, 2015 5:40 am

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Bart van Veen » Mon Nov 14, 2016 8:11 am

This actually solved the problem.

Thank you very much for your help, Chris!

User avatar
Christopher Dembia
Posts: 506
Joined: Fri Oct 12, 2012 4:09 pm

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Christopher Dembia » Mon Nov 14, 2016 10:21 am

Thank you for being courageous and trying out the MATLAB bindings on Ubuntu.

User avatar
Luca Modenese
Posts: 43
Joined: Wed Jan 21, 2009 9:16 am

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Luca Modenese » Mon Jan 13, 2020 11:32 am

Hello,

I have compiled OpenSim 4.0 on Ubuntu 18.04 encountering some issues and since this thread was extremely useful I have decided to extend it describing another problem that I have encountered and how I solved it.

In my case, after compiling the source code with the superbuild, I found that some of the MATLAB test failed.
opensim4.1_tests.png
opensim4.1_tests.png (47.19 KiB) Viewed 1228 times
After running the script for configuring OpenSim, preloading the libstdc++.so library from the system and checking that all the libraries were visible using ldd, my MATLAB API were still not working. Weirdly, I could manipulate/read/print models but not run simulations. For example, I could run OpenSimCreateTugOfWarModel.m smoothly but TugOfWar_CompleteRunVisualize.m was throwing a runtime error both in MATLAB and in my shell. The error in the shell was:
Intel MKL ERROR: Parameter 4 was incorrect on entry to DGETRF.
If I tried to run the RunHopper_answers.m script, MATLAB completely crashed.

I managed to solve the problem, and have all MATLAB test passed (and the OpenSim API working), only by preloading also the LAPACK library and avoiding to use the MATLAB one:

Code: Select all

export LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libstdc++.so.6:/usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1"
I hope this workaround helps and saves time to someone else!

Luca

User avatar
Giovanni Borrè
Posts: 1
Joined: Thu Mar 05, 2020 11:23 am

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Giovanni Borrè » Sat Mar 07, 2020 4:31 am

Hello,
I'm also trying to get Open Sim working with Matlab on Ubuntu 18.04 but I'm stuck. I've tried all the possibilities in this thread but still doesn't work. Performing the tests I get error on Java I can't really understand:
Screenshot from 2020-03-07 12-08-22.png
Screenshot from 2020-03-07 12-08-22.png (24.4 KiB) Viewed 1171 times
.
When I try some simple example on Matalb I get only java exceptions like this one:

Code: Select all

java.lang.RuntimeException: std::exception
	at org.opensim.modeling.opensimSimulationJNI.Model_initSystem(Native Method)
	at org.opensim.modeling.Model.initSystem(Model.java:848)
I have really no idea how to solve this, if someone have some idea to help me it would be great!
Thanks in advance

User avatar
Landais Erwann
Posts: 3
Joined: Wed Nov 04, 2020 6:49 am

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Landais Erwann » Fri Nov 27, 2020 10:10 am

Hi,

I'm also blocked at the same point, especially about the Java_TestTables. I'm using Ubuntu 18.04.5, Matlab R2020b.
What is really strange is that the problem seems to be related to an error in recovering data from .trc files. The recovered TImeStamps would not be of the double type, but of the int type; therefore, successive values of the .trc file would become identical, which would cause an error in the TimeSeriesTable class.
Here is the error message obtained for the file walk_free_01.trc (Timestamp : 3.067000 3.083000 3.100000 3.117000), for the Java_TestTables:

Code: Select all

Exception in thread "main" java.lang.RuntimeException: Timestamp at row 0 with value 3,000000 is greater-than/equal to timestamp at row 1 with value 3,000000
	Thrown at TimeSeriesTable.h:493 in validateRow().
	at org.opensim.modeling.opensimCommonJNI.new_TimeSeriesTableVec3__SWIG_5(Native Method)
	at org.opensim.modeling.TimeSeriesTableVec3.<init>(TimeSeriesTableVec3.java:61)
	at TestTables.test_FlattenWithIK(TestTables.java:710)
	at TestTables.main(TestTables.java:776)
... And if I change walk_free_01.trc a little bit (Timestamp : 3.067000 4.083000 3.100000 3.117000) :

Code: Select all

Exception in thread "main" java.lang.RuntimeException: Timestamp at row 1 with value 4,000000 is greater-than/equal to timestamp at row 2 with value 3,000000
	Thrown at TimeSeriesTable.h:493 in validateRow().
	at org.opensim.modeling.opensimCommonJNI.new_TimeSeriesTableVec3__SWIG_5(Native Method)
	at org.opensim.modeling.TimeSeriesTableVec3.<init>(TimeSeriesTableVec3.java:61)
	at TestTables.test_FlattenWithIK(TestTables.java:710)
	at TestTables.main(TestTables.java:776)
I'm pretty sure that the error on the other tests must be related to this kind of problem. Does anyone have any idea what caused this problem, and how it could be solved?

Regards,

Erwann

User avatar
Ayman Habib
Posts: 2248
Joined: Fri Apr 01, 2005 12:24 pm

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Ayman Habib » Fri Nov 27, 2020 10:31 am

Hello,

This appears to be a "locale" issue since the error message reports 3.0 as 3,000000. Likely the issue is that our code assumes US locale (decimal point is ".") while your environment suggests looking for "," as decimal point?
You may change the files in a text editor to test the hypothesis and if true investigate/try running our code in US locale environment.

Let us know what you find out,
-Ayman

User avatar
Landais Erwann
Posts: 3
Joined: Wed Nov 04, 2020 6:49 am

Re: Matlab API of OpenSim 4.0 on Linux (Ubuntu)

Post by Landais Erwann » Mon Nov 30, 2020 6:22 am

Hi,

Indeed, this was my issue; my locale variable was set as "fr_FR.UTF-8 UTF-8". Many thanks!

The way to solve this problem is rather well known, but I'll put it here for simplicity (from https://askubuntu.com/questions/162391/ ... 373#790373):

* Check the local variables via the "locale" command. If these variables do not match "en_US.UTF-8", do the following commands:

Code: Select all

 sudo locale-gen "en_US.UTF-8"
sudo dpkg-reconfigure locales 
* Restart the session.

With this last change, all the tests are functionnal with Ubuntu 18.04.5, Python 3.6.9 and Matlab R2020b. However, I also have another problem with the installation of Opensim-gui (problem with the visualization window). I'll detail it in a new topic (viewtopicPhpbb.php?f=91&t=12790&p=0&sta ... 8bdd1923ba).

Regards,

Erwann

POST REPLY