{"action":"created","issue":{"url":"https://api.github.com/repos/scipy/scipy/issues/4384","labels_url":"https://api.github.com/repos/scipy/scipy/issues/4384/labels{/name}","comments_url":"https://api.github.com/repos/scipy/scipy/issues/4384/comments","events_url":"https://api.github.com/repos/scipy/scipy/issues/4384/events","html_url":"https://github.com/scipy/scipy/pull/4384","id":53741817,"number":4384,"title":"ENH: optimize, returning True from callback function halts minimization","user":{"login":"andyfaff","id":702934,"avatar_url":"https://avatars.githubusercontent.com/u/702934?v=3","gravatar_id":"","url":"https://api.github.com/users/andyfaff","html_url":"https://github.com/andyfaff","followers_url":"https://api.github.com/users/andyfaff/followers","following_url":"https://api.github.com/users/andyfaff/following{/other_user}","gists_url":"https://api.github.com/users/andyfaff/gists{/gist_id}","starred_url":"https://api.github.com/users/andyfaff/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andyfaff/subscriptions","organizations_url":"https://api.github.com/users/andyfaff/orgs","repos_url":"https://api.github.com/users/andyfaff/repos","events_url":"https://api.github.com/users/andyfaff/events{/privacy}","received_events_url":"https://api.github.com/users/andyfaff/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/scipy/scipy/labels/enhancement","name":"enhancement","color":"bfe5bf"},{"url":"https://api.github.com/repos/scipy/scipy/labels/scipy.optimize","name":"scipy.optimize","color":"207de5"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-01-08T11:41:57Z","updated_at":"2015-01-11T12:55:09Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/scipy/scipy/pulls/4384","html_url":"https://github.com/scipy/scipy/pull/4384","diff_url":"https://github.com/scipy/scipy/pull/4384.diff","patch_url":"https://github.com/scipy/scipy/pull/4384.patch"},"body":"If the `callback` functions in scipy.optimize return `True`, then the minimization halts.\r\nI have not modified `optimize.TNC` because the `callback` function is called in the Fortran somewhere."},"comment":{"url":"https://api.github.com/repos/scipy/scipy/issues/comments/69493526","html_url":"https://github.com/scipy/scipy/pull/4384#issuecomment-69493526","issue_url":"https://api.github.com/repos/scipy/scipy/issues/4384","id":69493526,"user":{"login":"dlax","id":1046124,"avatar_url":"https://avatars.githubusercontent.com/u/1046124?v=3","gravatar_id":"","url":"https://api.github.com/users/dlax","html_url":"https://github.com/dlax","followers_url":"https://api.github.com/users/dlax/followers","following_url":"https://api.github.com/users/dlax/following{/other_user}","gists_url":"https://api.github.com/users/dlax/gists{/gist_id}","starred_url":"https://api.github.com/users/dlax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dlax/subscriptions","organizations_url":"https://api.github.com/users/dlax/orgs","repos_url":"https://api.github.com/users/dlax/repos","events_url":"https://api.github.com/users/dlax/events{/privacy}","received_events_url":"https://api.github.com/users/dlax/received_events","type":"User","site_admin":false},"created_at":"2015-01-11T12:55:09Z","updated_at":"2015-01-11T12:55:09Z","body":"Andrew Nelson wrote:\n> So there are two places a user could raise an |Exception|, in the\n> objective function or the callback.\n>\n> One could catch either of those, does it make sense to catch one or both?\n\nWorking at the callback level is probably easier and makes more sense, \nin my opinion.\n\n> My use case is tracking what a minimizer is doing. I am using\n> differential_evolution and a minimization can go on for a few minutes. I\n> am doing this in a GUI program. I want to track (and display) what's\n> happening to chi2, how many iterations have been done, how close to\n> convergence I am, etc. If I notice a problem I would like to halt, but\n> keep the best solution so far. As I see it there are two places for\n> improvement:\n>\n>  1. Being able to halt the minimization. This is what this PR is for.\n>     Raising an Exception is a good way to do it. The status message in\n>     OptimizeResult would then have some variation.\n\nIn addition, we could simply bind the exception object to the \nOptimizeResult, hence everything the user would have put in would be \npreserved.\n\n>  2. At the moment the information provided to the |callback| function is\n>     limited, limited to the best solution so far, |xk|. I would like to\n>     see richer information being provided (function value, best solution\n>     vector so far, number of iterations, etc). But I don't know how to\n>     go about this without breaking backward compatibility.\n\nSo, in essence, you'd like to pass a state object similar to the final \nOptimizeResult to the callback? Somthing like `callback(xk, \nstate=current_state)`.\nI'd say we could handle backwards incompatibility through deprecation."}}