Trouble running MocoTrack in implicit mode?

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
Daniel Gordon
Posts: 34
Joined: Fri May 06, 2016 7:57 am

Trouble running MocoTrack in implicit mode?

Post by Daniel Gordon » Thu Sep 09, 2021 7:42 am

Hello,

I'm trying to run the MocoTrack tool for a problem in implicit mode using Matlab, but am running in to this error:
java.lang.RuntimeException: casVector should be 1-dimensional, but has size 0 x 0.
Thrown at MocoCasOCProblem.h:108 in convertToSimTKVector().
The same code when run in explicit mode seems to work fine and produces a solution in 70-100 iterations or so.

To enter implicit mode, I've been using the following:

Code: Select all

solver = MocoCasADiSolver.safeDownCast(study.updSolver());
solver.set_multibody_dynamics_mode('implicit');
Has anyone else run in to this problem, or is anyone a bit more familiar with the error message to point me in the right direction?

Cheers

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

Re: Trouble running MocoTrack in implicit mode?

Post by Nicholas Bianco » Thu Sep 09, 2021 11:09 am

Hi Daniel,

How are you creating the initial guess? This type of error usually has something with the guess being incompatible, which can happen when switching between implicit and explicit mode due to missing acceleration variables. (This is technically a bug though, we should account for this during the compatibility checks we do).

You could try creating a fresh initial guess after changing the dynamics mode, that way you can ensure the guess is compatible with the problem.

-Nick

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

Re: Trouble running MocoTrack in implicit mode?

Post by Pasha van Bijlert » Thu Nov 21, 2024 5:07 pm

Hi Nick,

Sorry to resurrect this thread, but I just wanted to mention I ran into the same issue, and how I avoided it.

I ran a MocoTrack study in explicit mode, which worked fine. I then set the following code:

Code: Select all

solver.set_multibody_dynamics_mode('implicit');
    solver.set_minimize_implicit_multibody_accelerations(true);
    solver.set_implicit_multibody_accelerations_weight(myweight);
This resulted in the casVector error in the OP. The problem was how I set the the guess - I'd done the following:

Code: Select all

guess = solver.createGuess();

[several lines of code that modified the default guess
I had subsequently forgotten to call: solver.setGuess(guess).
So I wasn't setting the guess that I'd modified. Is this a bug, or is this user error?

The steps to reproduce are:
MocoTrack
Set implicit multibody dynamics
Create Guess
Don't set the guess after modifying it.

Cheers,
Pasha

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

Re: Trouble running MocoTrack in implicit mode?

Post by Nicholas Bianco » Mon Nov 25, 2024 11:16 am

Hi Pasha,

I'd say this is more of a design limitation of MocoTrack, rather than a bug. By default, MocoTrack sets the initial guess based on explicit dynamics mode. If you switch to implicit dynamics mode, the default guess set by MocoTrack will be incompatible with the problem, which is why you need to update the guess.

It is a bug that we don't catch the incompatible problem before encountering the casVector error. I'll track this issue on GitHub and look into a fix.

Best,
Nick

POST REPLY