Hi everyone,
I am working on a simulation using Moco Track to track walking data. I have been stuck with the following warnings and error. The warning seems to appear when I change my time and it is no longer from 0 to 1s.
The error "Invalid number in NLP function or derivative detected" appeared when I removed my initial guess.
I would appreciate guidance if anyone has encountered these errors/warnings before.
Thanks,
Kaitlyn
Invalid number detected/NaN detected error/warning
- Kaitlyn Downer
- Posts: 11
- Joined: Tue Jul 11, 2023 8:47 am
- Nicholas Bianco
- Posts: 1057
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Invalid number detected/NaN detected error/warning
Hi Kaitlyn,
This error usually happens if you try to solve a MocoProblem using a model with locked coordinates, although other issues can cause this too (e.g., using a poor initial guess).
Could you provide more details about the problem you're trying to solve and exactly which changes led to your error?
Best,
Nick
This error usually happens if you try to solve a MocoProblem using a model with locked coordinates, although other issues can cause this too (e.g., using a poor initial guess).
Could you provide more details about the problem you're trying to solve and exactly which changes led to your error?
Best,
Nick
- Kaitlyn Downer
- Posts: 11
- Joined: Tue Jul 11, 2023 8:47 am
Re: Invalid number detected/NaN detected error/warning
Hi Nick,
Thank you for your response. I had the subtalar and MTP locked; I thought I welded the joints, but looking back I did not. I welded those using ModOpReplaceJointsWithWelds.
I am still getting a (different) error. Previously, when I was still working from 0 to 1 s, I added an initial guess using the following lines:
Additionally, when I set the model and states initially, I also included this line of code: track.set_apply_tracked_states_to_guess(true)
Since I am now working on a different timepoint, I was just trying to get the simulation to run without any initial guess. However, when I remove the guess, I get "CasADi - 2023-10-30 09:49:46 WARNING("nlp:nlp_grad_f failed: NaN detected for output grad_f_x, at (row 0, col 0).")". I was attempting to take the approach of starting at a lower amount of mesh intervals to create a solution that I will use as an initial guess for the next iteration. But right now, it will not run if I remove the guess. Let me know if there is any other information you need.
Kaitlyn
Thank you for your response. I had the subtalar and MTP locked; I thought I welded the joints, but looking back I did not. I welded those using ModOpReplaceJointsWithWelds.
I am still getting a (different) error. Previously, when I was still working from 0 to 1 s, I added an initial guess using the following lines:
Code: Select all
% Insert previous solution from a less complex model
guess = solver.createGuess();
prevSolution = MocoTrajectory('JASC05_Trial02_MocoTrack_0to1_tx_mod_torque16.sto');
prevStatesTable = prevSolution.exportToStatesTable();
prevControlsTable = prevSolution.exportToControlsTable();
guess.insertStatesTrajectory(prevStatesTable, true);
guess.insertControlsTrajectory(prevControlsTable, true);
solver.setGuess(guess);
Since I am now working on a different timepoint, I was just trying to get the simulation to run without any initial guess. However, when I remove the guess, I get "CasADi - 2023-10-30 09:49:46 WARNING("nlp:nlp_grad_f failed: NaN detected for output grad_f_x, at (row 0, col 0).")". I was attempting to take the approach of starting at a lower amount of mesh intervals to create a solution that I will use as an initial guess for the next iteration. But right now, it will not run if I remove the guess. Let me know if there is any other information you need.
Kaitlyn
- Nicholas Bianco
- Posts: 1057
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Invalid number detected/NaN detected error/warning
Hi Kaitlyn,
I think what's happening is that MocoTrack is still applying the default initial guess via "track.set_apply_tracked_states_to_guess(true)", but it's no longer va good guess for your simulation. Try setting a fresh initial guess and see if that works:
-Nick
I think what's happening is that MocoTrack is still applying the default initial guess via "track.set_apply_tracked_states_to_guess(true)", but it's no longer va good guess for your simulation. Try setting a fresh initial guess and see if that works:
Code: Select all
guess = solver.createGuess();
solver.setGuess(guess);
study.solve();
- Kaitlyn Downer
- Posts: 11
- Joined: Tue Jul 11, 2023 8:47 am
Re: Invalid number detected/NaN detected error/warning
Thank you for your response. My code is now running, but I have two questions/concerns.
I am able to converge on a solution, but it does not resemble walking at all. I have included an image, but it essentially just does a little "hop" where it lifts the heels but neither foot leaves the ground. In my code, I am not tracking the pelvis_ty coordinate based on a previous forum post about the floor contact being sensitive to pelvis initial height. Could my issue result from not prescribing an initial guess (since I am just using a random guess right now). Is there a standard for setting an initial guess if so?
Second, my simulation runs, and in the command window it shows me that an optimal solution is found. However, no files are written and then it just begins running again. After this second run, it does write a solution file. Have you ever ran into this before?
Thanks,
Kaitlyn
I am able to converge on a solution, but it does not resemble walking at all. I have included an image, but it essentially just does a little "hop" where it lifts the heels but neither foot leaves the ground. In my code, I am not tracking the pelvis_ty coordinate based on a previous forum post about the floor contact being sensitive to pelvis initial height. Could my issue result from not prescribing an initial guess (since I am just using a random guess right now). Is there a standard for setting an initial guess if so?
Second, my simulation runs, and in the command window it shows me that an optimal solution is found. However, no files are written and then it just begins running again. After this second run, it does write a solution file. Have you ever ran into this before?
Thanks,
Kaitlyn
- Attachments
-
- Results.png (151.57 KiB) Viewed 1005 times
- Nicholas Bianco
- Posts: 1057
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Invalid number detected/NaN detected error/warning
Yes, a better initial guess would likely give you better results. Creating a good initial guess is usually an iterative process for more complex simulations (e.g., muscle-driven w/ grf tracking). I like to solve intermediate problems where I apply strong residual and reserve actuators to the model until I can track my data well, and then use that solution as the initial guess for my final simulation where I remove or at least weaken the residuals/reserves.Could my issue result from not prescribing an initial guess (since I am just using a random guess right now). Is there a standard for setting an initial guess if so?
I'm not sure what you mean here. Are you working with one of the scripting examples (e.g., exampleMocoTrack)?Second, my simulation runs, and in the command window it shows me that an optimal solution is found. However, no files are written and then it just begins running again. After this second run, it does write a solution file.
Best,
Nick
- Kaitlyn Downer
- Posts: 11
- Joined: Tue Jul 11, 2023 8:47 am
Re: Invalid number detected/NaN detected error/warning
Nick,
I am working with my own code, which I started based off of the example. Usually, it will run once (going through the multiple iterations), and then says EXIT: Optimal solution found. Previously, it would then write the .sto file and say ans = org.opensim..... Now, the code in MATLAB doesn't end, and it just begins the simulation again (going through the same number iterations as the first time). After this second time, it will write the results. I have attached a picture to try to help explain - the red line is where it ends, but instead of writing the results, it just starts a new simulation.
I am unsure what would cause this that it just repeats itself before writing the solution files. It is frustrating because now the simulations take double the amount of time. Please let me know if you/anyone has ever encountered this before.
Thanks,
Kaitlyn
I am working with my own code, which I started based off of the example. Usually, it will run once (going through the multiple iterations), and then says EXIT: Optimal solution found. Previously, it would then write the .sto file and say ans = org.opensim..... Now, the code in MATLAB doesn't end, and it just begins the simulation again (going through the same number iterations as the first time). After this second time, it will write the results. I have attached a picture to try to help explain - the red line is where it ends, but instead of writing the results, it just starts a new simulation.
I am unsure what would cause this that it just repeats itself before writing the solution files. It is frustrating because now the simulations take double the amount of time. Please let me know if you/anyone has ever encountered this before.
Thanks,
Kaitlyn
- Nicholas Bianco
- Posts: 1057
- Joined: Thu Oct 04, 2012 8:09 pm
Re: Invalid number detected/NaN detected error/warning
Hi Kaitlyn,
Is it possible you're calling "study.solve()" twice by accident? I'm not sure how that would happen otherwise.
-Nick
Is it possible you're calling "study.solve()" twice by accident? I'm not sure how that would happen otherwise.
-Nick