Simulations never converge

OpenSim Moco is a software toolkit to solve optimal control problems with musculoskeletal models defined in OpenSim using the direct collocation method.
User avatar
Simon Jeng
Posts: 87
Joined: Fri Sep 07, 2018 8:26 pm

Re: Simulations never converge

Post by Simon Jeng » Wed Nov 10, 2021 6:41 pm

Got it, Thanks Nick and Pasha.

User avatar
Carlos Gonçalves
Posts: 127
Joined: Wed Jun 08, 2016 4:56 am

Re: Simulations never converge

Post by Carlos Gonçalves » Thu Nov 11, 2021 6:30 am

Hello everyone,

Getting back to the issue of generating a guess file. I came across this procedure cited in the work from Antoine Falisse, Maarten Afschrift, Friedl De Groote https://www.biorxiv.org/content/10.1101 ... 292v1.full

The first initial guess was a "hot-start" based on 172 experimental walking data, whereas the second initial guess was a "cold-start" that consisted of a 173 static, bilaterally symmetrical standing posture that translated forward over the simulation duration. 174 Muscle states and controls were set to constant values for both initial guesses

I think it was exactly what Pasha shared before. The IPOPT and CaSADi can deal with guesses that are within the bounds and path constraints, which doesn't mean that they need to be respecting physics. Is that right? To just leave everything standing and constant was indeed shocking, but definitely is worth trying.

If it is, then creating guess files is tedious but not that hard.

What do you think?

Best regards.

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

Re: Simulations never converge

Post by Aaron Fox » Thu Nov 11, 2021 3:27 pm

Hi Carlos,

Yes I don't think the initial guess needs to be anything too 'realistic.' I believe if you do nothing to set the initial guess it simply sets all values to the middle of the bounds on the states across the entire problem - which wouldn't really be respecting physics at all.

Aaron

User avatar
Pasha van Bijlert
Posts: 219
Joined: Sun May 10, 2020 3:15 am

Re: Simulations never converge

Post by Pasha van Bijlert » Fri Nov 12, 2021 4:13 am

Hi Carlos,

Yeah they can get away with "bad" initial guesses, although to be honest I'm not able to reproduce their computational performance. They're describing model complexity way beyond what I'm using, while their 3D simulations seem to converge in under an hour. I'm not sure what explains this difference (I initially thought it might be related to tendon dynamics but I think they're including non-rigid tendons in their simulations).

I'm pretty sure they're using implicit formulations for all the dynamics as well, and using the same contact model, etc. Could the difference lie in the polynomial approximation of the MTC lengths?

Cheers,
Pasha

User avatar
John Davis
Posts: 56
Joined: Mon Aug 26, 2019 7:42 am

Re: Simulations never converge

Post by John Davis » Fri Nov 12, 2021 11:14 am

I suspect the significant computational speedups are due to automatic differentiation, which is reported to be 1.8-17.8x faster than finite differences for these kinds of problems. My understanding is that Moco currently gets its derivatives from finite differences. The Moco preprint mentions that overhauling OpenSim (and presumably Simbody) to support autodiff would be a pretty substantial undertaking.

User avatar
Carlos Gonçalves
Posts: 127
Joined: Wed Jun 08, 2016 4:56 am

Re: Simulations never converge

Post by Carlos Gonçalves » Fri Nov 12, 2021 11:30 am

Hello Aaron, Pasha and John. Thanks for the feedback.

@Aaron, that is so true, but yet that is so disruptive for me :lol: ... If it works, and will, will be a game changer for my simulations.

@Pasha, I have been following Falisse work for a while, and they use CaSADi directly, and also with "algorithm differentiation" as @John mentioned.

The code for this research is at https://github.com/antoinefalisse/predictsim_mtp.

I "met" some of the researchers from LEUVEN HUMAN MOVEMENT BIOMECHANICS RESEARCH GROUP at ISB 2021 and they use it a lot. I intend to get to learn someway in the next months (fingers crossed).

Hope it helps. Best regards.

Carlos

User avatar
Ross Miller
Posts: 372
Joined: Tue Sep 22, 2009 2:02 pm

Re: Simulations never converge

Post by Ross Miller » Fri Nov 12, 2021 3:46 pm

Algorithmic differentiation can indeed make a tremendous difference in speed for these sorts of simulations. AD is not the same thing as providing symbolic expressions for the gradient but it's conceptually similar in that the time required to determine where to step from iteration to iteration is greatly reduced. I never did much in 3-D pre-Moco but I could do 2-D simulations of a full stride of walking with a fairly complicated model (12 DoF, 26 muscles) with a 101-node grid that often converged within 20 minutes, running Matlab in serial on a normal laptop. That was with symbolic gradients. The drawback to this approach is any time you want to change anything topographic about the model, you have to form the gradient again, which is pretty tedious. There are probably better ways to automate it for someone who is actually a skilled programmer but for me it involved a lot of error-prone copy/paste, find/replace, and grep operations since software for symbolic dynamics like Autolev or PyDy generally doesn't output equations in a format that can be immediately inserted into something like Matlab.

Symbolic is not feasible with OpenSim at least as OpenSim currently exists (it never forms the symbolic state equations) and as John mentioned AD is also not feasible without modifying the "guts" of OpenSim like I think Antoine did in his PhD work. I'm actually impressed that Moco is as fast as it is with finite difference gradients, I was not expecting to be doing 3-D simulations of a full stride with a complex model on my laptop in a single-digit number of hours but that's indeed the performance, most of the time.

The larger headache for me with direct collocation is the number of iterations to convergence is not predictable. Sometimes it is 300, sometimes 3000. Symbolic gradients still suffered from this.

Ton told me once about an approach he was using that worked with random initial guesses but I can't remember the details.

Ross

User avatar
Carlos Gonçalves
Posts: 127
Joined: Wed Jun 08, 2016 4:56 am

Re: Simulations never converge

Post by Carlos Gonçalves » Sat Nov 13, 2021 3:37 am

Thanks for the complementation Ross.

This is one great forum topic. Hope I can contribute on it later.

It is a long journey ahead is mastering these kinds of simulations.

If anyone is also working on creating guess files, I discovered yesterday that the .sto should have the same columns' positions from what is generated by the solver.

In my case it was:

Coordinates' values
Coordinates' speed
Muscles' activation
Muscles' normalized tendon force
Muscles' excitation (/forceset/soleus_r for example)
Muscles' implicitderiv_normalized_tendon_force


Best regards.

POST REPLY