Error when using Moco in Python: MocoCasADiSolver is not available

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
User avatar
Carlo von Diecken
Posts: 6
Joined: Mon Dec 05, 2022 7:24 am

Error when using Moco in Python: MocoCasADiSolver is not available

Post by Carlo von Diecken » Wed May 08, 2024 1:56 am

Hi,

I am trying to get started with OpenSim Moco in Python but receive an error when running the line 'solution = study.solve()' in the example script exampleSlidingMass.py. I have tried uninstalling and reinstalling the OpenSim package but still the same error appears.

Does anybody have an idea what's going on here?

Best
Carlo

Code: Select all

>>> solution = study.solve()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/anaconda3/envs/opensim-moco/lib/python3.10/site-packages/opensim/moco.py", line 8603, in solve
    return _moco.MocoStudy_solve(self)
RuntimeError: std::exception in 'OpenSim::MocoSolution OpenSim::MocoStudy::solve() const': MocoCasADiSolver is not available.
        Thrown at MocoCasADiSolver.cpp:455 in solveImpl().

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

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Nicholas Bianco » Fri May 10, 2024 11:23 am

Hi Carlo,

The "opensim" conda package does not currrently include Moco. If you are on Windows, you can use the opensim-moco conda package. We are currently working on Mac and Linux support for Moco integrated into the main "opensim" conda package.

Best,
-Nick

User avatar
Carlo von Diecken
Posts: 6
Joined: Mon Dec 05, 2022 7:24 am

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Carlo von Diecken » Sun May 12, 2024 11:18 pm

Hi Nick,

thank you for your response! I should have mentioned my operating system, I am indeed on Mac (ARM64). Is there currently any other way of working with Moco on Mac? Unfortunately, I do not have access to a MATLAB license at the moment, so I can't use the MATLAB API.

Best,
Carlo

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

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Nicholas Bianco » Mon May 13, 2024 8:35 pm

Hi Carlo,

You can always manually install OpenSim into a Python environment to use Moco.

You can download OpenSim 4.5 here. Then, create your Python environment (e.g., using conda or another environment manager) and navigate to the directory "<install_dir>/sdk/Python", where <install_dir> is the directory you installed OpenSim 4.5 in. The directory should the file "setup.py. Finally, run the following command to install OpenSim into your environment:

Code: Select all

python -m pip install .
Then you should be able to open a Python interpreter and import OpenSim via

Code: Select all

import opensim as osim
-Nick

User avatar
Carlo von Diecken
Posts: 6
Joined: Mon Dec 05, 2022 7:24 am

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Carlo von Diecken » Tue May 14, 2024 3:55 am

Hi Nick,

thank you again for your help! I have done what you recommended and successfully installed OpenSim manually. However, when I try to run the line 'import opensim as osim', I receive an error stating that the '_simbody.so' file is incompatible with my operating system arm64 and requires x86_64.

Code: Select all

>>> import opensim as osim
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Applications/OpenSim 4.5/OpenSim 4.5.app/Contents/Resources/opensim/sdk/Python/opensim/__init__.py", line 18, in <module>
    from .simbody import *
  File "/Applications/OpenSim 4.5/OpenSim 4.5.app/Contents/Resources/opensim/sdk/Python/opensim/simbody.py", line 10, in <module>
    from . import _simbody
ImportError: dlopen(/Applications/OpenSim 4.5/OpenSim 4.5.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so, 0x0002): tried: '/Applications/OpenSim 4.5/OpenSim 4.5.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Applications/OpenSim 4.5/OpenSim 4.5.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so' (no such file), '/Applications/OpenSim 4.5/OpenSim 4.5.app/Contents/Resources/opensim/sdk/Python/opensim/_simbody.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e' or 'arm64'))
Is there any way of installing the files with the required architecture or is this way of installing OpenSim simply not compatible with newer MacOS architecture?

Best,
Carlo

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

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Nicholas Bianco » Tue May 14, 2024 10:23 am

Hi Carlo,

If you have an Arm64 Mac, then you'll need to set up a x64 Python environment since we currently only have x64 builds of OpenSim.

If using conda, you can follow the instructions on this Stack Overflow post to set up a conda environment using x64. You can then follow my previous instructions to install OpenSim into this environment and everything should (hopefully) work.

Best,
Nick

User avatar
Carlo von Diecken
Posts: 6
Joined: Mon Dec 05, 2022 7:24 am

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Carlo von Diecken » Thu May 16, 2024 12:48 am

Hi Nick,

thank you so much! This approach worked and Moco is now running smoothly on my machine.

Best,
Carlo

User avatar
Camille Guillaume
Posts: 3
Joined: Thu Apr 25, 2024 7:42 am

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Camille Guillaume » Fri May 31, 2024 12:09 pm

Hi,

I have the same problem as Carlo. I have an Arm64 Mac, and I am trying to run a script on python using Moco.

First I created a conda environment with python 3.8, and installed the opensim package using the command line:

Code: Select all

conda install -c opensim-org opensim
I managed to import opensim in the script however the following intruction

Code: Select all

study = tracking_problem.initialize() 
gives me this error:

Code: Select all

Traceback (most recent call last):
  File "/Users/camilleguillaume/Documents/MasterThesis/assistive-arm/scripts/assistiveForce_camille.py", line 113, in <module>
    main()
  File "/Users/camilleguillaume/Documents/MasterThesis/assistive-arm/scripts/assistiveForce_camille.py", line 96, in main
    study = tracking_problem.initialize()
  File "/Users/camilleguillaume/opt/anaconda3/envs/assistive_arm/lib/python3.8/site-packages/opensim/moco.py", line 9355, in initialize
    return _moco.MocoTrack_initialize(self)
RuntimeError: std::exception in 'OpenSim::MocoStudy OpenSim::MocoTrack::initialize()': MocoCasADiSolver is not available.
        Thrown at MocoCasADiSolver.cpp:91 in createGuess().
Then, I saw this post and created a new conda x64 Python environment using the Stack Overflow post mentioned.
I downloaded Opensim 4.5 and tried to install opensim via the <install_dir>/sdk/Python directory using the command line mentioned:
python -m pip install .
But I get this error:

Code: Select all

Processing /Applications/OpenSim 4.5/OpenSim 4.5.app/Contents/Resources/opensim/sdk/Python
  Preparing metadata (setup.py) ... done
Building wheels for collected packages: opensim
  Building wheel for opensim (setup.py) ... error
  error: subprocess-exited-with-error
  
  x python setup.py bdist_wheel did not run successfully.
    I exit code: 1
    --> [5 lines of output]
      running bdist_wheel
      running build
      running build_py
      running egg_info
      error: Cannot update time stamp of directory 'opensim.egg-info'
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
  ERROR: Failed building wheel for opensim
  Running setup.py clean for opensim
Failed to build opensim
ERROR: Could not build wheels for opensim, which is required to install pyproject.toml-based projects
Does anybody have an idea how can I fix this? Or another way to install opensim/opensim-moco on a python environment?

Best
Camille

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

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Nicholas Bianco » Sat Jun 01, 2024 12:14 pm

Hi Camille,

It might be a problem with permissions on your machine. Try the following:

Code: Select all

sudo python pip -m install .
-Nick

User avatar
Camille Guillaume
Posts: 3
Joined: Thu Apr 25, 2024 7:42 am

Re: Error when using Moco in Python: MocoCasADiSolver is not available

Post by Camille Guillaume » Mon Jun 03, 2024 11:56 am

Hi Nick,

Thank you for your reply.

I managed to install opensim in my x64 Python environment.

However, now when I run the script, I get another error when importing opensim.

Code: Select all

Traceback (most recent call last):
  File "/Users/camilleguillaume/Documents/MasterThesis/assistive-arm/scripts/assistiveForce_camille.py", line 3, in <module>
    import opensim as osim
  File "/Users/camilleguillaume/opt/anaconda3/envs/opensim_forum/lib/python3.8/site-packages/opensim/__init__.py", line 18, in <module>
    from .simbody import *
  File "/Users/camilleguillaume/opt/anaconda3/envs/opensim_forum/lib/python3.8/site-packages/opensim/simbody.py", line 10, in <module>
    from . import _simbody
ImportError: dlopen(/Users/camilleguillaume/opt/anaconda3/envs/opensim_forum/lib/python3.8/site-packages/opensim/_simbody.so, 2): Library not loaded: @rpath/libosimExampleComponents.dylib
  Referenced from: /Users/camilleguillaume/opt/anaconda3/envs/opensim_forum/lib/python3.8/site-packages/opensim/_simbody.so
  Reason: image not found
Fyi, the python version I am using is 3.8, the numpy version is 1.21 (I tried with numpy 1.20 and got the same error).

Would you know how to solve this?

Thank you.
Camille

POST REPLY