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()