OpenSim 4.4 and 4.5 MATLAB API on Apple Silicon M2 (arm64)

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Oliver Demuth
Posts: 6
Joined: Mon Nov 27, 2023 8:10 am

OpenSim 4.4 and 4.5 MATLAB API on Apple Silicon M2 (arm64)

Post by Oliver Demuth » Fri Feb 02, 2024 9:14 am

Hi everyone,

I am trying to configure and set up the OpenSim API in MATLAB on my new MacBook which has an Apple Silicon M2 Pro chip. I am running Matlab R2023b Update 3 (64-bit maca64) and have both OpenSim 4.4 and 4.5 (2024-01-10-3b63585) versions installed. When I run the configureOpenSim.m for either version it susscessfully completes and updates the paths for the OpenSim API with the following message:
OpenSim successfully added

Paths have been successfully updated for the OpenSim API installed at /Applications/OpenSIM 4.5-2024-01-10-3b63585/OpenSim 4.5-2024-01-10-3b63585.app/Contents/Resources/OpenSim. To complete setup, restart MATLAB. To test your set u, type: `model = rg.opensim.modelling.Model();`
However, when I restart Matlab and try the above line or try to check the version with org.opensim.modeling.opensimCommon.GetVersion() I get the following Matlab error:
Error: Failed to load OpenSim libraries

Failed to load one or more dynamic libraries for OpenSim.
java.lang.UnsatisfiedLinkError: /Applications/OpenSim 4.5-2024-01-10-3b63585/OpenSim 4.5-2024-01-10-3b63585.app/Contents/Resources/opensim/sdk/lib/libosimJavaJNI.dylib: dlopen(/Applications/OpenSim 4.5-2024-01-10-3b63585/OpenSim 4.5-2024-01-10-3b63585.app/Contents/Resources/opensim/sdk/lib/libosimJavaJNI.dylib, 0x0001): tried: '/Applications/OpenSim 4.5-2024-01-10-3b63585/OpenSim 4.5-2024-01-10-3b63585.app/Contents/Resources/opensim/sdk/lib/libosimJavaJNI.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/OpenSim 4.5-2024-01-10-3b63585/OpenSim 4.5-2024-01-10-3b63585.app/Contents/Resources/opensim/sdk/lib/libosimJavaJNI.dylib' (no such file), '/Applications/OpenSim 4.5-2024-01-10-3b63585/OpenSim 4.5-2024-01-10-3b63585.app/Contents/Resources/opensim/sdk/lib/libosimJavaJNI.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
and then:
Java exception occurred:
java.lang.UnsatisfiedLinkError: org.opensim.modeling.opensimCommonJNI.swig_module_init()V
at org.opensim.modeling.opensimCommonJNI.swig_module_init(Native Method)
at org.opensim.modeling.opensimCommonJNI.<clinit>(opensimCommonJNI.java:3242)
at org.opensim.modeling.opensimCommon.GetVersion(opensimCommon.java:25)
I assume the java library architecture mismatch might be causing my issue. x86_64 is the architecture used by OpenSim and arm64 is the architecture on the Apple Silicon chips that my MATLAB runs on, if I am not mistaken. So, MATLAB is looking for the library in the arm64 architecture but can only find the libosimJavaJNI.dylib with a x86_64 architecture, correct?

Is there a way to circumvent these architecture mismatches, as there is with Conda and Python (e.g., https://simtk-confluence.stanford.edu:8 ... da+Package)? Or will OpenSim support arm64 with a future release?

Many thanks,
Oliver

Tags:

User avatar
Oliver Demuth
Posts: 6
Joined: Mon Nov 27, 2023 8:10 am

Re: OpenSim 4.4 and 4.5 MATLAB API on Apple Silicon M2 (arm64)

Post by Oliver Demuth » Mon Feb 05, 2024 3:06 am

Update:

I installed MATLAB R2023b Update 6 (maci64), which I can run with Rosetta 2. This allowed me to successfully link it with OpenSim through the MATLAB API. It was definitley an issue with the initial MATLAB version being arm64 causing the architecture mismatch.

Are there plans to include Apple Silicon (arm64) for future OpenSim releases?

Many thanks,
Oliver

User avatar
Carmichael Ong
Posts: 375
Joined: Fri Feb 24, 2012 11:50 am

Re: OpenSim 4.4 and 4.5 MATLAB API on Apple Silicon M2 (arm64)

Post by Carmichael Ong » Mon Feb 05, 2024 11:44 am

Thanks for providing that update. This is correct, because currently we only have builds for x64 architectures, you must install that version of MATLAB to use the API right now. The GUI works using x64 as well.

Apple Silicon arm builds are on the future roadmap, but there is no current timeline set for these builds.

POST REPLY