coin-or / Ipopt

COIN-OR Interior Point Optimizer IPOPT
https://coin-or.github.io/Ipopt
Other
1.43k stars 284 forks source link

C++ exceptions and MATLAB #252

Closed svigerske closed 5 years ago

svigerske commented 5 years ago

Issue created by migration from Trac.

Original creator: drosos.kourounis

Original creation time: 2014-12-11 06:20:46

Assignee: ipopt-team

Version: 3.11

Dear developers,

according to the following thread,

http://in.mathworks.com/matlabcentral/newsreader/view_thread/16818

C++ exceptions are not portable in MATLAB. As a result, every time IPOPT throws an exception MATLAB crashes. Is there any possible way to deactivate them during configuring or compilation? I searched the corresponding source files but I did not see any #define statements to remove exceptions in a preprocessing step. Compiling with -fno-exceptions doesn't work either.

Thanks in advance! DK.

svigerske commented 5 years ago

Comment by @tkelman created at 2014-12-15 13:32:44

It might be worth trying to use the C interface to Ipopt, I haven't looked at the code in a while but I'm pretty sure the mex wrapper is based on the C++ API. The C API is supposed to catch exceptions internally and not propagate them back to the calling function, which may or may not help with the Matlab crashes. I don't think completely removing exceptions from Ipopt would be possible, but I could be wrong. If using Ipopt from any environment other than Matlab is remotely feasible for you, I would recommend doing that.

svigerske commented 5 years ago

Comment by FabiF1 created at 2014-12-17 19:26:26

Hi DK,

If you're using Matlab, I would expect you to have written a mex-file. If that is true, wouldn't it be possible to implement a "Try-Catch" that would surround the call to ipopt, and if any error "known" or "unknown" is caught, then exit properly the mex-file with a:

try{
}
catch(...){
mexprintf('Oupsss... Ipopt mexfile exits!')
}

You can also improve it by catching specific error and react differently.

Nonetheless this should enable you not to take down Matlab when a C++ exception is thrown.

Cheers, Fab

svigerske commented 5 years ago

Comment by @tkelman created at 2014-12-17 21:34:40

There is a pre-existing mex file in Ipopt/contrib/MatlabInterface, that's what DK is using. I haven't looked through the code in some time, it may already be doing some try/catch internally. But it could probably be made more robust.

svigerske commented 5 years ago

The MatlabInterface is no longer distributed with Ipopt (>= 3.13).

Consider trying out mexIPOPT instead.