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

DOC: indicate possibility that line_search returns some values that are None #4312

Merged
merged 3 commits into from Feb 23, 2015

Conversation

argriffing
Copy link
Contributor

Partially addresses #4257.

@dlax
Copy link
Member

dlax commented Dec 28, 2014

How about raising an exception instead?

@argriffing
Copy link
Contributor Author

How about raising an exception instead?

Yes that would make more sense. This PR is just intended to document the current behavior.

@dlax
Copy link
Member

dlax commented Dec 29, 2014

argriffing a écrit :

How about raising an exception instead?

Yes that would make more sense. This PR is just intended to document the
current behavior.

The thing is that changing the current behavior to raise an exception
might be considered backwards incompatible. Though, it seems most usages
of line search functions within scipy actually check for None and then
raise a specific exception (_LineSearchError(RuntimeError)). So making
this "official" would make sense IMO. Alternatively a warning could be used.
Other opinions?

@rgommers rgommers added scipy.optimize Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org labels Dec 29, 2014
@rgommers
Copy link
Member

I can easily imagine users that ran into None before having writting code to work around it (maybe trying another starting point), so a clear warning may be preferable to an exception.

@dlax
Copy link
Member

dlax commented Jan 2, 2015

I guess I'd also prefer a (documented) warning to be raised after all. Also "something has gone wrong" is not very informative, just saying that the line search algorithm did not converge might be better.

@dlax dlax added the needs-work Items that are pending response from the author label Jan 2, 2015
@argriffing
Copy link
Contributor Author

I have a bias against adding warnings because of the drawbacks of design by committee. But in this case it might make sense. The meaning of the warning would be "Your optimization has failed, but for backwards compatibility this is a warning instead of an exception, and some of the return values of the line search function will be None." but the warning text should be translated into something more bland.

@argriffing
Copy link
Contributor Author

Added the warning and improved the explanation for None return values.

@dlax
Copy link
Member

dlax commented Jan 2, 2015

Thanks @argriffing. Sorry for nitpicking again but, wouldn't a plain RuntimeWarning be more appropriate and sufficient? There is already a few of those in scipy for "similar" issues.

@argriffing
Copy link
Contributor Author

@dlax I used RuntimeWarning originally, but it is transformed into an error on my system, possibly because I'm using a development version of numpy. I tried changing to OptimizeWarning as a base class, but there was some kind of import problem, maybe a cyclic import. Then I switched to a base class of UserWarning because that is the base class of OptimizeWarning.

@dlax
Copy link
Member

dlax commented Jan 2, 2015

argriffing a écrit :

@dlax https://github.com/dlax I used |RuntimeWarning| originally, but
it is transformed into an error on my system, possibly because I'm using
a development version of numpy. I tried changing to |OptimizeWarning| as
a base class, but there was some kind of import problem, maybe a cyclic
import. Then I switched to a base class of |UserWarning| because that is
the base class of |OptimizeWarning|.

I'd say that UserWarning (base class for warnings generated by user
code) is not semantically appropriate in this case. RuntimeWarning (Base
class for warnings about dubious runtime behavior) is probably more.

@argriffing
Copy link
Contributor Author

@dlax Currently I think the scipy tests never raise uncaught RuntimeWarnings. One reason is that these warnings (along with DeprecationWarning) are promoted to Exceptions in certain environments (e.g. possibly numpy development versions). Changing the base class from UserWarning to RuntimeWarning would introduce some uncaught exceptions that may not be completely straightforward to deal with in terms of modification of the scipy unit tests. Also, your argument favoring RuntimeWarning over UserWarning as a base class would apply not only to the LineSearchWarning but also to OptimizeWarning, right?

@argriffing
Copy link
Contributor Author

OptimizeWarning was introduced in #217 with the UserWarning base class.

@dlax
Copy link
Member

dlax commented Jan 2, 2015

IIRC, OptimizeWarning concerns user code, so it's appropriate for it to be a UserWarning.

@argriffing
Copy link
Contributor Author

@dlax At least the first of the following couple of uses does not particularly seem to concern user code, except in the loose sense that all optimization concerns user code at some level.
https://github.com/scipy/scipy/blob/maintenance/0.15.x/scipy/optimize/minpack.py#L602
https://github.com/scipy/scipy/blob/maintenance/0.15.x/scipy/optimize/optimize.py#L127

@dlax
Copy link
Member

dlax commented Jan 4, 2015

argriffing wrote:

@dlax https://github.com/dlax At least the first of the following
couple of uses does not particularly seem to concern user code, except
in the loose sense that all optimization concerns user code at some level.
https://github.com/scipy/scipy/blob/maintenance/0.15.x/scipy/optimize/minpack.py#L602
https://github.com/scipy/scipy/blob/maintenance/0.15.x/scipy/optimize/optimize.py#L127

So there's an inconsistency.

Anyways, I still fail to see the real problem with using a RuntimeWarning.

@argriffing
Copy link
Contributor Author

Anyways, I still fail to see the real problem with using a RuntimeWarning.

I agree that there is not a real problem with using a RuntimeWarning. My intention with this low-effort PR was to quickly update the line_search docs. If others would like to improve the line_search function itself rather than just documenting its current possibly sub-optimal behavior then that would be awesome and we could close this PR!

@rgommers
Copy link
Member

Since the non-convergence is usually due to the user specifying something incorrectly, a subclass of UserWarning doesn't seem completely inappropriate. I'm fine with either merging this as is or changing to RuntimeWarning.

@argriffing
Copy link
Contributor Author

Changed from UserWarning to RuntimeWarning. It seems to pass TravisCI so I guess it's OK.

@dlax dlax removed the needs-work Items that are pending response from the author label Feb 23, 2015
dlax added a commit that referenced this pull request Feb 23, 2015
DOC: indicate possibility that line_search returns some values that are None
@dlax dlax merged commit 07a28a4 into scipy:master Feb 23, 2015
@dlax
Copy link
Member

dlax commented Feb 23, 2015

Merged, thanks @argriffing !

@argriffing
Copy link
Contributor Author

FWIW this PR causes test errors on unreleased numpy. I think this is because they set some kind of global flags to escalate warnings to errors for more stringent testing during development than in released versions.

@rgommers
Copy link
Member

This indicates that there are now warnings raised by tests added here which should be filtered out. The common pattern for that is:

 with warnings.catch_warnings():
    warnings.simplefilter('ignore', UserWarning)
    function_call_that_gives_expected_warning()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation Issues related to the SciPy documentation. Also check https://github.com/scipy/scipy.org scipy.optimize
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants