libprima / prima

PRIMA is a package for solving general nonlinear optimization problems without using derivatives. It provides the reference implementation for Powell's derivative-free optimization methods, i.e., COBYLA, UOBYQA, NEWUOA, BOBYQA, and LINCOA. PRIMA means Reference Implementation for Powell's methods with Modernization and Amelioration, P for Powell.
http://libprima.net
BSD 3-Clause "New" or "Revised" License
304 stars 40 forks source link

Refactor prima_is_success to accept options.ctol #200

Closed nbelakovski closed 5 months ago

nbelakovski commented 5 months ago

This is in reference to https://github.com/libprima/prima/issues/195

I made it so that ctol is initialized to the default value that was being used. Another option is to check if options.ctol is NaN within prima_is_success, but I know we've discussed before that isnan can have issues with certain optimization levels.

I'll think about it some more, but I'm not sure what other options there are. With either option above we need to maintain a default value within prima.c which is not ideal since that implies two places where default values are stored (prima.c and consts.f90). Would it make sense to have a consts folder at the root of the repo, which then contains folders like fortran, c, python, each of which defines const values for each of the languages, so that there's one place where these values are maintained?

zaikunzhang commented 5 months ago

Hi @nbelakovski ,

I agree with what you said.

I think the solution you propose is fine given the current situation.

However, I am considering another possibility: let the Fortran backend return success (optional), so that other languages do not need to define success themselves.

This also motivates a single gateway prima.f90 to the Fortran backend, so that we do not need to define success for each solver. You proposed this before, and I disagreed, but I now think it is a good idea. Once prima.f90 is defined, we will provide prima_c.f90 to replace newuoa_c.f90 etc, disabling the access to individual solvers. It will make the Fortran API more consistent with the current C and Python ones. However, this is still some dispute about this perspective.

What do you think? We can merge the current solution first, but I hope to hear your opinions.

Thanks.

Zaikun

zaikunzhang commented 5 months ago

Hi @nbelakovski ,

Do we really need to expose prima_is_success in the public API? Could we add a success field to result, expecting users to get success by reading this field?

A similar question was asked about prima_get_rc_string.

Thanks.

nbelakovski commented 5 months ago

Do we really need to expose prima_is_success in the public API? Could we add a success field to result, expecting users to get success by reading this field?

A similar question was asked about prima_get_rc_string.

I don't think we need to expose either of these in the public API, and I've made the appropriate changes.

Once prima.f90 is defined, we will provide prima_c.f90 to replace newuoa_c.f90 etc, disabling the access to individual solvers.

Of course I think that defining prima_c.f90 would be much more straightforward than our current solution of almost identically copying the same file 5 times. I think the package overall is more useful if it automatically determines what algorithm to use given the constraints provided, but it would be nice to have an "advanced mode" where users could explicitly specify the solver.