MocoInverse with compliant tendons

Provide easy-to-use, extensible software for modeling, simulating, controlling, and analyzing the neuromusculoskeletal system.
POST REPLY
User avatar
Mohammadreza Rezaie
Posts: 377
Joined: Fri Nov 24, 2017 12:48 am

MocoInverse with compliant tendons

Post by Mohammadreza Rezaie » Mon Apr 03, 2023 2:13 am

Hi,

In MocoInverse example, I commented this line modelProcessor.append(osim.ModOpIgnoreTendonCompliance()) to include tendon elasticity but this error appears:

Code: Select all

CasADi - 2023-04-03 12:27:44 WARNING("nlp:nlp_jac_g failed: NaN detected for output jac_g_x, at nonzero index 99 (row 179, col 0).") [C:\Miniconda3\envs\test\conda-bld\opensim-moco_1655259458192\work\dependencies\casadi\casadi\core\oracle_function.cpp:265]                                                                
Error evaluating Jacobian of equality constraints at user provided starting point.                                                                              
  No scaling factors for equality constraints computed!                                                                                                         
CasADi - 2023-04-03 12:29:10 WARNING("nlp:nlp_jac_g failed: NaN detected for output jac_g_x, at nonzero index 99 (row 179, col 0).") [C:\Miniconda3\envs\test\conda-bld\opensim-moco_1655259458192\work\dependencies\casadi\casadi\core\oracle_function.cpp:265]                                                                
                                                                                                                                                                
Number of Iterations....: 0                                                                                                                                     
                                                                                                                                                                
Number of objective function evaluations             = 0                                                                                                        
Number of objective gradient evaluations             = 0                                                                                                        
Number of equality constraint evaluations            = 0                                                                                                        
Number of inequality constraint evaluations          = 0                                                                                                        
Number of equality constraint Jacobian evaluations   = 1                                                                                                        
Number of inequality constraint Jacobian evaluations = 0                                                                                                        
Number of Lagrangian Hessian evaluations             = 0                                                                                                        
Total CPU secs in IPOPT (w/o function evaluations)   =     91.518                                                                                               
Total CPU secs in NLP function evaluations           =     86.632                                                                                               
                                                                                                                                                                
EXIT: Invalid number in NLP function or derivative detected.                                                                                                    
         nlp  :   t_proc      (avg)   t_wall      (avg)    n_eval                                                                                               
  nlp_grad_f  |  29.00ms ( 29.00ms)  29.34ms ( 29.34ms)         1                                                                                               
   nlp_jac_g  | 178.09 s ( 89.05 s) 178.09 s ( 89.05 s)         2                                                                                               
       total  | 178.15 s (178.15 s) 178.15 s (178.15 s)         1                                                                                               
[info] Set log level to Info.                                                                                                                                   
[info] ------------------------------------------------------------------------                                                                                 
[info] Elapsed real time: 219 second(s) (3 minute(s), 39 second(s)).                                                                                            
[info] Mon Apr  3 12:29:11 2023                                                                                                                                 
[warning] MocoCasADiSolver did NOT succeed:                                                                                                                     
[warning]   Invalid_Number_Detected                                                                                                                             
[info] ========================================================================
However, it works in case of rigid tendons. Any idea why MocoInverse doesn't work with compliant tendons? Any help is greatly appreciated.

Regards,
Mohammadreza

Tags:

User avatar
Aaron Fox
Posts: 273
Joined: Sun Aug 06, 2017 10:54 pm

Re: MocoInverse with compliant tendons

Post by Aaron Fox » Tue Apr 04, 2023 8:54 pm

Hi Mohammadreza,

I've found any time using compliant tendons that I actually convert the problem to a MocoStudy so that you can set an appropriate initial guess, and set the normalised tendon force to a reasonable value so that it doesn't stray off into a weird starting space (check Ross Miller's UMocoD code for an example of this). The other thing it allows you to do is access the solver and reset the problem, which I think I've found can resolve this NaN issue (i.e. solver.resetProblem).

Aaron

User avatar
Mohammadreza Rezaie
Posts: 377
Joined: Fri Nov 24, 2017 12:48 am

Re: MocoInverse with compliant tendons

Post by Mohammadreza Rezaie » Wed Apr 05, 2023 3:06 am

Hi Dr. Fox,

Thanks for your reply. In this case, the error is the same.

Code: Select all

study = inverse.initialize()
problem = study.updProblem()
solver = osim.MocoCasADiSolver.safeDownCast(study.updSolver())
solver.resetProblem(problem)
initGuess = solver.createGuess()
n = initGuess.getNumTimes()
for i in model.getMuscles():
	muscle = i.getAbsolutePathString()
	# initGuess.setState(muscle +'/activation', 0.1*np.ones(n))
	initGuess.setState(muscle +'/normalized_tendon_force', 0.1*np.ones(n))
solver.setGuess(initGuess)
solution = study.solve()
Is this exactly what you mean?

Thank you,
Mohammadreza

User avatar
Mohammadreza Rezaie
Posts: 377
Joined: Fri Nov 24, 2017 12:48 am

Re: MocoInverse with compliant tendons

Post by Mohammadreza Rezaie » Thu Apr 06, 2023 1:41 pm

Hi, appending ModOpUseImplicitTendonComplianceDynamicsDGF to the model processor fixed the issue.

POST REPLY