Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when running toyCar in octave #42

Open
samlaf opened this issue Aug 29, 2020 · 3 comments
Open

Error when running toyCar in octave #42

samlaf opened this issue Aug 29, 2020 · 3 comments
Labels

Comments

@samlaf
Copy link

samlaf commented Aug 29, 2020

Hi, I am running toyCar's MAIN.m file, and get this error

error: pivot is zero
error: called from
    gjp at line 42 column 5
    cpiv_bard at line 76 column 4
    __lm_feasible__ at line 302 column 31
    fmincon at line 417 column 24
    directCollocation at line 95 column 33
    trapezoid at line 74 column 10
    optimTraj at line 180 column 24

I am wondering if this is due to me using octave, or if there is a fundamental bug happening.
Another "fix" I've had to do is to add

'GradObj', 'off',...
'GradConstr', 'off'

options in optimset in GetDefaultOptions.m. Otherwise directCollocation.m's line 26
flagGradObj = strcmp(Opt.nlpOpt.GradObj,'on');
was raising an error.

Not sure if this is also an issue due to octave or if it's actually an issue with the code.

@MatthewPeterKelly
Copy link
Owner

OptimTraj is not designed to run in Octave. At the time of writing, it didn't even run at all (no implementation for fmincon). That being said, it looks like someone implemented it, because the code gets farther than it used to!

Do you get a similar error on all of the other example problems?

My guess is that the Octave implementation of fmincon doesn't match all of the internal interface details (like how options are handled) and that is where your problem is coming from. Most of the examples in OptimTraj will default to using finite difference gradients, so you might have more luck with those ones.

@samlaf
Copy link
Author

samlaf commented Aug 31, 2020

Hi Matthew,
thank you for this very nice library, and for answering my message.

There is indeed an optim library in Octave now, which contains fmincon (though it needs to be loaded with pkg load optim).
I think the main difference is fmincon's default solver, which doesn't accept initial guesses that don't respect the constraints (which mostly all of your examples do!). So I changed the default solver to octave-sqp. It worked for this example, but still raises issues for other examples (I only tried the minwork example, and got discouraged.)

How/Where do I set finite difference gradients?

@MatthewPeterKelly
Copy link
Owner

The minimumWork example is a particularly tricky one to solve. I suggest starting with one of the following: cartPole, quadRotor2d, or simplePendulum`.

Octave SQP sounds like a reasonable choice - good luck!

By default, OptimTraj will solve using finite difference gradients. They are not computed directly by OptimTraj though -- they are done automatically inside of FMINCON. You can provide an analytic gradient, which is better to do if you can.

If the Octave solver requires that you provide a gradient, then I suggest that you try to go through the analytic gradient route. Look at the example code in fiveLinkBiped. The gradients for the optimization are a bit tricky -- there is a lot of "vectorization" going on to make things run fast enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants