-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
API: optimize.differential_evolution
: transition to Generator (SPEC 7)
#21774
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big yes for me. I have eggs in the basket so I will let the crowd decide. Approving if that counts in any ways.
The biggest effect of PRs of this type will be the default RNG will be a Previously if one supplied an This is going to change random number generation, and code that relied on a certain seed for reproducibility will be different across versions. |
Thanks @andyfaff for doing this!
The intent of the SPEC is that this only happens after warnings expire. In the meantime, arguments passed positionally or via the old keyword argument are processed as they always were, whatever that is. (Arguments passed using the new keyword are validated and standardarized by the decorator according to the new behavior, which is simply to call After the warnings have been emitted for two cycles (according to SciPy's policy), then we can remove the decorator and any old argument validation/standardization code except for |
Co-authored-by: Matt Haberland <mhaberla@calpoly.edu>
@mdhaber what the SPEC doesn't provide guidelines on is what should happen to the docstring of
|
Ok, I think I got a useful docstring now. |
It was actually an explicit decision to leave that up to projects due to differences in opinion over how (/whether) the outgoing behavior should be documented explicitly. One side is that only the new behavior needs to be documented, since old code will continue to work and new uses should follow the new pattern. The other is that we need to document all supported behaviors of the function - both as a matter of principle and to support those who are referring to the documentation while working with existing code that uses the old behavior. Regardless of the level of detail about the supported old behavior, I'd suggest leading with the new behavior to encourage its use. These things are true whether the argument is passed by position or by keyword: rng : `numpy.random.Generator`, optional
Pseudorandom number generator state. Then, if you prefer, I think it's OK to document all the details as long as it's clear that passing a
Thanks for pioneering this transition. I know it's messy! |
How about:
|
I think that's OK. Just some rendering issues, especially with the admonition: We never saw this rendered, so I think we need to do something about the single backticks around plain @stefanv Just thought I'd ping you so you can see how one of these SPEC 7 transitions to |
I've tried to improve by putting more backticks around e.g. |
I don't know why the versionchanged isn't displayed properly. |
It's rendering properly now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is ready. If you're happy with the final tweaks @andyfaff, I'll go ahead and merge. SciPy already endorsed SPEC 7.
[docs only]
optimize.differential_evolution
: transition to Generator (SPEC 7)
Fine to merge, but it wasn't decided in the endorsement thread that we were also happy to implement the SPEC everywhere in SciPy (they are two separate things). The relevant news from the forum is that Andrew's post for this API change received no pushback. |
@mdhaber, I'm happy with the changes you made. Once this gets merged I'm intending to start working on similar changes. First the other global optimisers, then I think it would be good to do all the stats distributions as well, but that may be a big task. |
Thanks @andyfaff! I think that sounds pretty good, although I wouldn't put time into the old distributions, personally. The new distributions will only support the |
rng=1, | ||
tol=0.5) | ||
# use of rng=RandomState should give rise to an error. | ||
differential_evolution(self.quadratic, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these need to be in separate context managers as the test will still pass if only one these raises an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup. Let's fix that in the next PR like this.
Transitions
optimize.differential_evolution
according to SPEC007.@mdhaber, @tupui.