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.
POST REPLY
User avatar
Molly Shepherd
Posts: 17
Joined: Thu Nov 14, 2019 9:36 am

MocoCasADiSolver is not available

Post by Molly Shepherd » Thu Dec 21, 2023 9:22 am

Hi all,

I have recently been trying to switch my MocoInverse code from Matlab to Python. I have been following the example 'exampleMocoInverse.py' to ensure that I am using the correct syntax. Everything appears to be working up until the line: solution = inverse.solve() where I get the error: RuntimeError: std::exception in 'OpenSim::MocoInverseSolution OpenSim::MocoInverse::solve() const': MocoCasADiSolver is not available.
Thrown at MocoCasADiSolver.cpp:448 in solveImpl().

This code runs error free in Matlab, so I am unsure of what might be causing this issue. I am currently using Jupyter Notebook to execute my code, and I have attached it below.

Any insight would be appreciated.
Thanks!
Molly

Code: Select all

import opensim as osim
import os
import numpy as np
from mat4py import loadmat
import scipy.io
import pandas as pd
print(osim.__version__)

# Construct the MocoInverse tool.
inverse = osim.MocoInverse()

# Construct a ModelProcessor and set it on the tool. The default
# muscles in the model are replaced with optimization-friendly
# DeGrooteFregly2016Muscles, and adjustments are made to the default muscle
# parameters.
modelProcessor = osim.ModelProcessor('DDH01_SS_Final.osim')
modelProcessor.append(osim.ModOpAddExternalLoads('External_Loads_grf.xml'))
modelProcessor.append(osim.ModOpReplaceMusclesWithDeGrooteFregly2016())
# Only valid for DeGrooteFregly2016Muscles.DDH01
modelProcessor.append(osim.ModOpIgnorePassiveFiberForcesDGF())
# modelProcessor.append(opensim.ModOpIgnoreTendonCompliance())
modelProcessor.append(osim.ModOpUseImplicitTendonComplianceDynamicsDGF())
# modelProcessor.append(opensim.ModOpTendonComplianceDynamicsModeDGF('opimplicit'))
# Only valid for DeGrooteFregly2016Muscles.
modelProcessor.append(osim.ModOpScaleActiveFiberForceCurveWidthDGF(1.5))
modelProcessor.append(osim.ModOpAddReserves(10, float('inf'), True))

jointNames = osim.StdVectorString()
jointNames.append('mtp_l')
jointNames.append('mtp_r')
modelProcessor.append(osim.ModOpReplaceJointsWithWelds(jointNames))
inverse.setModel(modelProcessor)

# Construct a TableProcessor of the coordinate data and pass it to the
# inverse tool. TableProcessors can be used in the same way as
# ModelProcessors by appending TableOperators to modify the base table.
# A TableProcessor with no operators, as we have here, simply returns the
# base table.
inverse.setKinematics(osim.TableProcessor('RRA_states.sto'))
# initial time, final time, and mesh interval.
inverse.set_initial_time(1.136)
inverse.set_final_time(1.910)
inverse.set_mesh_interval(0.02)
# By default, Moco gives an error if the kinematics contains extra columns.
# Here, we tell Moco to allow (and ignore) those extra columns.
inverse.set_kinematics_allow_extra_columns(True)
inverse.set_minimize_sum_squared_activations(True)
# constrains muscle residuals/error
inverse.set_constraint_tolerance(1e-05)
# when change from an iteration is smaller than tolerance, iterations terminated
inverse.set_convergence_tolerance(1e-04)

# Solve the problem and write the solution to a Storage file.
solution = inverse.solve()

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

Re: MocoCasADiSolver is not available

Post by Nicholas Bianco » Fri Dec 22, 2023 9:05 pm

Hi Molly,

Did you install OpenSim using one of our conda packages? You might have installed a version that does not include the Moco libraries.

You can find the list of available packages here and some instructions on how to install specific packages here. The list includes the latest OpenSim beta release (4.5), which I believe has Moco included.

Best,
Nick

User avatar
Molly Shepherd
Posts: 17
Joined: Thu Nov 14, 2019 9:36 am

Re: MocoCasADiSolver is not available

Post by Molly Shepherd » Fri Dec 22, 2023 9:27 pm

Nick,

Thanks for the quick reply. I did not realize that there were 2 different conda packages. I had only installed the base opensim package; installing opensim-moco fixed my issue.

Thank you!
Molly

POST REPLY