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

Callback #69

Closed jschueller closed 11 months ago

jschueller commented 1 year ago

Called after each iteration (Cobyla only for now). Reports the current best x & f values. Allows to request termination via a boolean argument.

comments welcome

github-actions[bot] commented 1 year ago

@check-spelling-bot Report

:red_circle: Please review

See the :open_file_folder: files view, the :scroll:action log or :angel: SARIF report for details.

Unrecognized words (5)

calcb callbck CCALLBACK evalcallback fcb

To accept :heavy_check_mark: these unrecognized words as correct, run the following commands ... in a clone of the [git@github.com:jschueller/prima.git](https://github.com/jschueller/prima.git) repository on the `callback` branch ([:information_source: how do I use this?]( https://github.com/check-spelling/check-spelling/wiki/Accepting-Suggestions)): ``` sh curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/main/apply.pl' | perl - 'https://github.com/libprima/prima/actions/runs/6202671785/attempts/1' ```
If the flagged items are :exploding_head: false positives If items relate to a ... * binary file (or some other file you wouldn't want to check at all). Please add a file path to the `excludes.txt` file matching the containing file. File paths are Perl 5 Regular Expressions - you can [test]( https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your files. `^` refers to the file's path from the root of the repository, so `^README\.md$` would exclude [README.md]( ../tree/HEAD/README.md) (on whichever branch you're using). * well-formed pattern. If you can write a [pattern](https://github.com/check-spelling/check-spelling/wiki/Configuration-Examples:-patterns) that would match it, try adding it to the `patterns.txt` file. Patterns are Perl 5 Regular Expressions - you can [test]( https://www.regexplanet.com/advanced/perl/) yours before committing to verify it will match your lines. Note that patterns can't match multiline strings.
zaikunzhang commented 1 year ago

Thank you Julien @jschueller . This is very nice.

The first question that we have to discuss is as follows. In callback(x, f, terminate, [, other inputs]), what do we want x and f to be? There are two possibilities.

Another possibility is to change the signature of the callback function to callback(xnew, fnew, xbest, fbest, terminate, ...) to include both of them.

In addition,

Insights from SciPy maintainers are greatly needed.

Thanks.

jschueller commented 1 year ago

we want the best point only; we can already know the last point evaluated via the objective function

This is a useful observation. The objective function is also a callback. However, there is a small difference: the objective function does not give us terminate.

are you sure we need constr too ?

Yes. This is related to a previous discussion (see point 2 there). In the applications that PRIMA target, constr can be quite expensive to evaluate. Thus it is essential to provide this information to the user via the callback function (then the user will choose how to use it).

jschueller commented 1 year ago

@zaikunzhang I stumbled on a weird compiler bug: https://github.com/flang-compiler/flang/issues/1419 You can add it to your collection :]

zaikunzhang commented 1 year ago

@zaikunzhang I stumbled on a weird compiler bug: flang-compiler/flang#1419 You can add it to your collection :]

Done: https://github.com/zequipe/test_compiler/commit/1990a70f52712dc74db97a14ead54dc50c448fc2. Thank you.

jschueller commented 1 year ago

@zaikunzhang I added constraint values, what do you think ?

zaikunzhang commented 11 months ago

Hello @jschueller Julien,

Sorry for the delayed reply. The work and life on my side have been complicated recently, and they will continue to be so for a while.

Note the following.

  1. [x, f, cstrv, nlconstr] is not the latest best [decision variable, function value, constraint violation, nonlinear constraint value]. It is the latest evaluated one. The latest best one is [xbase + xpt(:, kopt), fval(kopt), cval(kopt), conmat(:, kopt)].

  2. cstrv and nlconstr should be optional in callback. It is rather strange and confusing to define cstrv and nlconstr in subroutines like newuob.f90.

  3. Since the callback changes the Fortran API, the MATLAB interface will be broken. I can take care of that, but do not have time for the moment.

Thanks.